diff options
author | Yuchen Pei <hi@ypei.me> | 2022-05-30 17:20:01 +1000 |
---|---|---|
committer | Yuchen Pei <hi@ypei.me> | 2022-05-30 17:20:01 +1000 |
commit | f008ab0a3211c0d5912fe0b99b936d8770fada17 (patch) | |
tree | b6ff264ce30d7b02c63a98d0f686e96189f86551 /src/F2Md | |
parent | c96f8f6c820d43a55388f0307f3a6de9471ebb10 (diff) |
fixed a few things
- redundant imports and deps
- check file existence
Diffstat (limited to 'src/F2Md')
-rw-r--r-- | src/F2Md/Config.hs | 22 | ||||
-rw-r--r-- | src/F2Md/Import.hs | 2 |
2 files changed, 10 insertions, 14 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) diff --git a/src/F2Md/Import.hs b/src/F2Md/Import.hs index 80dfa54..eb6d014 100644 --- a/src/F2Md/Import.hs +++ b/src/F2Md/Import.hs @@ -27,8 +27,6 @@ import Data.Text.Encoding import Control.Monad import Data.Time import System.Process -import Data.UUID -import Data.UUID.V4 import Data.Char import Data.Text (Text) import Text.Feed.Types |