aboutsummaryrefslogtreecommitdiff
path: root/src/F2Md/Config.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/F2Md/Config.hs')
-rw-r--r--src/F2Md/Config.hs22
1 files changed, 10 insertions, 12 deletions
diff --git a/src/F2Md/Config.hs b/src/F2Md/Config.hs
index c952d09..c17a55f 100644
--- a/src/F2Md/Config.hs
+++ b/src/F2Md/Config.hs
@@ -24,7 +24,6 @@ module F2Md.Config
( getUserdata
, FeedUserdata(..)
, updateLastUpdated
- , updateLastUpdated'
) where
import Control.Monad
@@ -37,6 +36,7 @@ import Data.Time
import GHC.Generics
import qualified Data.HashMap.Strict as HM
import Data.Aeson
+import System.Posix.Files
data Config = Config
{ dbPath :: String
@@ -52,7 +52,7 @@ data FeedUserdata = FeedUserdata
getUserdata :: FilePath -> IO ([FeedUserdata], Maybe FilePath, Maybe FilePath)
getUserdata file = do
- config <- decodeFileStrict file
+ config <- decodeFileStrict =<< expandPath file
case config of
Nothing -> return ([], Nothing, Nothing)
Just config' -> do
@@ -67,11 +67,14 @@ getUserdata' (Config dbPath _ feeds) = do
return $ map (\url -> FeedUserdata url $ HM.lookup url decoded) feeds
getLastUpdatedMap :: FilePath -> IO (HM.HashMap Text ZonedTime)
-getLastUpdatedMap dbPath =
- fromMaybe (HM.fromList []) <$> (decodeFileStrict =<< expandPath dbPath)
-
-updateLastUpdated' :: FilePath -> FeedUserdata -> [Message] -> IO ()
-updateLastUpdated' path feed msgs =
+getLastUpdatedMap dbPath = do
+ exists <- fileExist =<< expandPath dbPath
+ if exists then
+ fromMaybe (HM.fromList []) <$> (decodeFileStrict =<< expandPath dbPath)
+ else return $ HM.fromList []
+
+updateLastUpdated :: FilePath -> FeedUserdata -> [Message] -> IO ()
+updateLastUpdated path feed msgs =
unless (null msgs) $ do
decoded <- getLastUpdatedMap path
encodeFile path $
@@ -80,8 +83,3 @@ updateLastUpdated' path feed msgs =
(utcToZonedTime (zonedTimeZone $ mDate $ head msgs) . maximum $
zonedTimeToUTC . mDate <$> msgs)
decoded
-
-updateLastUpdated :: FilePath -> [FeedUserdata] -> [[Message]] -> IO ()
-updateLastUpdated path feeds feedMsgs = do
- mapM_ (uncurry (updateLastUpdated' path))
- (zip feeds feedMsgs)