ghc-mod/Utils.hs

27 lines
681 B
Haskell
Raw Normal View History

{-# LANGUAGE CPP #-}
module Utils where
import Control.Applicative
import Data.Traversable
import System.Directory
import System.Directory.ModTime
2015-08-03 01:09:56 +00:00
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