From 80479b62e51ff13cd24baf4a1a22999303144d48 Mon Sep 17 00:00:00 2001 From: Sean Whitton Date: Sun, 5 Apr 2015 09:47:54 +0900 Subject: fix purging the old caches --- src/Main.hs | 1 + src/Utility/EventCache.hs | 12 ++++++------ 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 -- cgit v1.2.3