diff options
-rw-r--r-- | src/Hakyll/Core/Util/File.hs | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/Hakyll/Core/Util/File.hs b/src/Hakyll/Core/Util/File.hs index 45f3760..71de322 100644 --- a/src/Hakyll/Core/Util/File.hs +++ b/src/Hakyll/Core/Util/File.hs @@ -4,15 +4,21 @@ module Hakyll.Core.Util.File ( makeDirectories , getRecursiveContents , isFileObsolete + , isFileInternal ) where -import System.FilePath (normalise, takeDirectory, (</>)) import System.Time (ClockTime) import Control.Monad (forM, filterM) +import Data.List (isPrefixOf) import System.Directory ( createDirectoryIfMissing, doesDirectoryExist , doesFileExist, getModificationTime , getDirectoryContents ) +import System.FilePath ( normalise, takeDirectory, splitPath + , dropTrailingPathSeparator, (</>) + ) + +import Hakyll.Core.Configuration -- | Given a path to a file, try to make the path writable by making -- all directories on the path. @@ -65,3 +71,17 @@ isFileObsolete file depends = do then return True else do timeStamp <- getModificationTime file isObsolete timeStamp depends + +-- | Check if a file is meant for Hakyll internal use, i.e. if it is located in +-- the destination or store directory +-- +isFileInternal :: HakyllConfiguration -- ^ Configuration + -> FilePath -- ^ File to check + -> Bool -- ^ If the given file is internal +isFileInternal configuration file = + any (`isPrefixOf` split file) dirs + where + split = map dropTrailingPathSeparator . splitPath + dirs = map (split . ($ configuration)) [ destinationDirectory + , storeDirectory + ] |