2015-03-03 20:12:43 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
module Utils where
|
|
|
|
|
|
|
|
import Control.Applicative
|
|
|
|
import Data.Traversable
|
|
|
|
import System.Directory
|
2015-11-26 13:48:26 +00:00
|
|
|
import System.Directory.ModTime
|
2015-03-03 20:12:43 +00:00
|
|
|
|
2015-08-03 01:09:56 +00:00
|
|
|
import Prelude
|
|
|
|
|
2015-03-28 01:30:51 +00:00
|
|
|
data TimedFile = TimedFile { tfPath :: FilePath, tfTime :: ModTime }
|
2015-11-26 13:48:26 +00:00
|
|
|
deriving (Eq)
|
2015-03-03 20:12:43 +00:00
|
|
|
|
|
|
|
instance Ord TimedFile where
|
|
|
|
compare (TimedFile _ a) (TimedFile _ b) = compare a b
|
|
|
|
|
|
|
|
timeFile :: FilePath -> IO TimedFile
|
2015-11-26 13:48:26 +00:00
|
|
|
timeFile f = TimedFile <$> pure f <*> getModTime f
|
2015-03-03 20:12:43 +00:00
|
|
|
|
|
|
|
mightExist :: FilePath -> IO (Maybe FilePath)
|
|
|
|
mightExist f = do
|
|
|
|
exists <- doesFileExist f
|
|
|
|
return $ if exists then (Just f) else (Nothing)
|
|
|
|
|
|
|
|
timeMaybe :: FilePath -> IO (Maybe TimedFile)
|
2015-03-28 01:30:51 +00:00
|
|
|
timeMaybe f = traverse timeFile =<< mightExist f
|