module Snap.Loader.Dynamic.TreeWatcher
( TreeStatus
, getTreeStatus
, checkTreeStatus
) where
#ifndef MIN_VERSION_directory
#define MIN_VERSION_directory(x,y,z) 1
#endif
import Control.Applicative
import System.Directory
import System.Directory.Tree
#if MIN_VERSION_directory(1,2,0)
import Data.Time.Clock
#else
import System.Time
#endif
#if MIN_VERSION_directory(1,2,0)
data TreeStatus = TS [FilePath] [AnchoredDirTree UTCTime]
#else
data TreeStatus = TS [FilePath] [AnchoredDirTree ClockTime]
#endif
getTreeStatus :: [FilePath] -> IO TreeStatus
getTreeStatus = liftA2 (<$>) TS readModificationTimes
checkTreeStatus :: TreeStatus -> IO Bool
checkTreeStatus (TS paths entries) = check <$> readModificationTimes paths
where
check = and . zipWith (==) entries
#if MIN_VERSION_directory(1,2,0)
readModificationTimes :: [FilePath] -> IO [AnchoredDirTree UTCTime]
#else
readModificationTimes :: [FilePath] -> IO [AnchoredDirTree ClockTime]
#endif
readModificationTimes = mapM $ readDirectoryWith getModificationTime