aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorSean Whitton <spwhitton@spwhitton.name>2015-04-05 09:47:54 +0900
committerSean Whitton <spwhitton@spwhitton.name>2015-04-05 09:47:54 +0900
commit80479b62e51ff13cd24baf4a1a22999303144d48 (patch)
treea0feaad7c36a1c445cb84e084cdf3bfc3c1fa7b9
parent104abc8c64efecf1075c668d69acef0313d9b4a3 (diff)
downloadsrem-80479b62e51ff13cd24baf4a1a22999303144d48.tar.gz
fix purging the old caches
-rw-r--r--src/Main.hs1
-rw-r--r--src/Utility/EventCache.hs12
2 files changed, 7 insertions, 6 deletions
diff --git a/src/Main.hs b/src/Main.hs
index 8bc4a7e..21388f6 100644
--- a/src/Main.hs
+++ b/src/Main.hs
@@ -36,6 +36,7 @@ import Utility.Notify
doCron :: IO ()
doCron = do
+ purgeOldEventCaches
rems <- (++) <$> readEmacsEventCache <*> readManualEventCache
(h, m, _) <- localHMD
let nowRemsFilter r = getReminderHour r == h
diff --git a/src/Utility/EventCache.hs b/src/Utility/EventCache.hs
index aecaeaf..a5835db 100644
--- a/src/Utility/EventCache.hs
+++ b/src/Utility/EventCache.hs
@@ -48,12 +48,12 @@ import Utility.Emacs
purgeOldEventCaches :: IO ()
purgeOldEventCaches = do
- files <- (SremConfig.getCacheDirectory
- >>= getDirectoryContents)
+ dir <- SremConfig.getCacheDirectory
+ files <- getDirectoryContents dir
`catch` ((\_ -> return []) :: IOException -> IO [FilePath])
today <- localDay . zonedTimeToLocalTime <$> getZonedTime
forM_ files $ \file ->
- when (fileIsOldCache today file) $ removeFile file
+ when (fileIsOldCache today file) $ removeFile (dir </> file)
appendManualEventCache :: Reminder -> Day -> IO ()
appendManualEventCache r d = do
@@ -125,9 +125,9 @@ todaysCacheFileDateString = showGregorian . localDay . zonedTimeToLocalTime
fileIsOldCache :: Day -> FilePath -> Bool
fileIsOldCache today file = length splitFile == 3
- && splitFile !! 1 `elem` ["manual", "emacs"]
- && (maybe False (< today) $ readDay $ splitFile !! 2)
- && splitFile !! 3 == "csv"
+ && splitFile !! 0 `elem` ["manual", "emacs"]
+ && (maybe False (< today) $ readDay $ splitFile !! 1)
+ && splitFile !! 2 == "csv"
where
splitFile = splitOneOf "_." file