From 48da85b3418e7805d27cd2703f83570027d66a2a Mon Sep 17 00:00:00 2001 From: Jasper Van der Jeugt Date: Thu, 10 Feb 2011 16:42:26 +0100 Subject: Add isFileInternal --- src/Hakyll/Core/Util/File.hs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/Hakyll') 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 + ] -- cgit v1.2.3