File: Utils.hs

package info (click to toggle)
ghc-mod 5.6.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 1,216 kB
  • ctags: 240
  • sloc: haskell: 8,323; lisp: 1,557; makefile: 40; sh: 34
file content (26 lines) | stat: -rw-r--r-- 681 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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