1-- | A module containing various file utility functions
3module Hakyll.Core.Util.File
9import System.FilePath (normalise, takeDirectory, (</>))
10import System.Time (ClockTime)
11import Control.Monad (forM, filterM)
12import System.Directory ( createDirectoryIfMissing, doesDirectoryExist
13 , doesFileExist, getModificationTime
14 , getDirectoryContents
17-- | Given a path to a file, try to make the path writable by making
18-- all directories on the path.
20makeDirectories :: FilePath -> IO ()
21makeDirectories = createDirectoryIfMissing True . takeDirectory
23-- | Get all contents of a directory. Note that files starting with a dot (.)
26getRecursiveContents :: FilePath -> IO [FilePath]
27getRecursiveContents topdir = do
28 topdirExists <- doesDirectoryExist topdir
30 then do names <- getDirectoryContents topdir
31 let properNames = filter isProper names
32 paths <- forM properNames $ \name -> do
33 let path = topdir </> name
34 isDirectory <- doesDirectoryExist path
36 then getRecursiveContents path
37 else return [normalise path]
41 isProper = not . (== ".") . take 1
43-- | Check if a timestamp is obsolete compared to the timestamps of a number of
44-- files. When they are no files, it is never obsolete.
46isObsolete :: ClockTime -- ^ The time to check.
47 -> [FilePath] -- ^ Dependencies of the cached file.
49isObsolete _ [] = return False
50isObsolete timeStamp depends = do
51 depends' <- filterM doesFileExist depends
52 dependsModified <- mapM getModificationTime depends'
53 return (timeStamp < maximum dependsModified)
55-- | Check if a file is obsolete, given it's dependencies. When the file does
56-- not exist, it is always obsolete. Other wise, it is obsolete if any of it's
57-- dependencies has a more recent modification time than the file.
59isFileObsolete :: FilePath -- ^ The cached file
60 -> [FilePath] -- ^ Dependencies of the cached file
62isFileObsolete file depends = do
63 exists <- doesFileExist file
66 else do timeStamp <- getModificationTime file
67 isObsolete timeStamp depends
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list