on master help sign in
Add isFileInternal
48da85bJasper Van der Jeugt
src/Hakyll/Core/Util/File.hs+21−1
@@ -4,15 +4,21 @@ module Hakyll.Core.Util.File
4 ( makeDirectories
4 ( makeDirectories
5 , getRecursiveContents
5 , getRecursiveContents
6 , isFileObsolete
6 , isFileObsolete
7+ , isFileInternal
7 ) where
8 ) where
8
9
9−import System.FilePath (normalise, takeDirectory, (</>))
10import System.Time (ClockTime)
10import System.Time (ClockTime)
11import Control.Monad (forM, filterM)
11import Control.Monad (forM, filterM)
12+import Data.List (isPrefixOf)
12import System.Directory ( createDirectoryIfMissing, doesDirectoryExist
13import System.Directory ( createDirectoryIfMissing, doesDirectoryExist
13 , doesFileExist, getModificationTime
14 , doesFileExist, getModificationTime
14 , getDirectoryContents
15 , getDirectoryContents
15 )
16 )
17+import System.FilePath ( normalise, takeDirectory, splitPath
18+ , dropTrailingPathSeparator, (</>)
19+ )
20+
21+import Hakyll.Core.Configuration
16
22
17-- | Given a path to a file, try to make the path writable by making
23-- | Given a path to a file, try to make the path writable by making
18-- all directories on the path.
24-- all directories on the path.
@@ -65,3 +71,17 @@ isFileObsolete file depends = do
65 then return True
71 then return True
66 else do timeStamp <- getModificationTime file
72 else do timeStamp <- getModificationTime file
67 isObsolete timeStamp depends
73 isObsolete timeStamp depends
74+
75+-- | Check if a file is meant for Hakyll internal use, i.e. if it is located in
76+-- the destination or store directory
77+--
78+isFileInternal :: HakyllConfiguration -- ^ Configuration
79+ -> FilePath -- ^ File to check
80+ -> Bool -- ^ If the given file is internal
81+isFileInternal configuration file =
82+ any (`isPrefixOf` split file) dirs
83+ where
84+ split = map dropTrailingPathSeparator . splitPath
85+ dirs = map (split . ($ configuration)) [ destinationDirectory
86+ , storeDirectory
87+ ]