Reorganize shared modules

This commit is contained in:
Daniel Gröber
2017-05-18 02:40:21 +02:00
parent 3572b720d1
commit dc0a161925
5 changed files with 4 additions and 3 deletions

26
shared/Utils.hs Normal file
View File

@@ -0,0 +1,26 @@
{-# LANGUAGE CPP #-}
module Utils where
import Control.Applicative
import Data.Traversable
import System.Directory
import System.Directory.ModTime
import Prelude
data TimedFile = TimedFile { tfPath :: FilePath, tfTime :: ModTime }
deriving (Eq)
instance Ord TimedFile where
compare (TimedFile _ a) (TimedFile _ b) = compare a b
timeFile :: FilePath -> IO TimedFile
timeFile f = TimedFile <$> pure f <*> getModTime f
mightExist :: FilePath -> IO (Maybe FilePath)
mightExist f = do
exists <- doesFileExist f
return $ if exists then (Just f) else (Nothing)
timeMaybe :: FilePath -> IO (Maybe TimedFile)
timeMaybe f = traverse timeFile =<< mightExist f