summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core/Configuration.hs
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2013-04-03 12:02:06 +0200
committerJasper Van der Jeugt <m@jaspervdj.be>2013-04-03 12:02:06 +0200
commit5e4adaecb232231d87a6bb4dd0b041daf86a4cdb (patch)
treedab51fae19d9c062fdc9697c1ac410a93e8f4517 /src/Hakyll/Core/Configuration.hs
parent792fcdf4c6c5a86a6dcaf969f807ae86a58090b1 (diff)
downloadhakyll-5e4adaecb232231d87a6bb4dd0b041daf86a4cdb.tar.gz
Account for absolute paths in `shouldIgnoreFile`
Diffstat (limited to 'src/Hakyll/Core/Configuration.hs')
-rw-r--r--src/Hakyll/Core/Configuration.hs38
1 files changed, 26 insertions, 12 deletions
diff --git a/src/Hakyll/Core/Configuration.hs b/src/Hakyll/Core/Configuration.hs
index 480c6c4..70a7a1c 100644
--- a/src/Hakyll/Core/Configuration.hs
+++ b/src/Hakyll/Core/Configuration.hs
@@ -8,11 +8,13 @@ module Hakyll.Core.Configuration
--------------------------------------------------------------------------------
-import Control.Monad (void)
-import Data.Default (Default(..))
-import Data.List (isPrefixOf, isSuffixOf)
-import System.FilePath (normalise, takeFileName)
-import System.Process (system)
+import Control.Monad (void)
+import Data.Default (Default (..))
+import Data.List (isPrefixOf, isSuffixOf)
+import System.Directory (canonicalizePath)
+import System.FilePath (isAbsolute, normalise, takeFileName)
+import System.IO.Error (catchIOError)
+import System.Process (system)
--------------------------------------------------------------------------------
@@ -99,11 +101,23 @@ defaultConfiguration = Configuration
--------------------------------------------------------------------------------
-- | Check if a file should be ignored
-shouldIgnoreFile :: Configuration -> FilePath -> Bool
-shouldIgnoreFile conf path =
- destinationDirectory conf `isPrefixOf` path' ||
- storeDirectory conf `isPrefixOf` path' ||
- tmpDirectory conf `isPrefixOf` path' ||
- ignoreFile conf path'
+shouldIgnoreFile :: Configuration -> FilePath -> IO Bool
+shouldIgnoreFile conf path = orM
+ [ inDir (destinationDirectory conf)
+ , inDir (storeDirectory conf)
+ , inDir (tmpDirectory conf)
+ , return (ignoreFile conf path')
+ ]
where
- path' = normalise path
+ path' = normalise path
+ absolute = isAbsolute path
+
+ inDir dir
+ | absolute = do
+ dir' <- catchIOError (canonicalizePath dir) (const $ return dir)
+ return $ dir' `isPrefixOf` path'
+ | otherwise = return $ dir `isPrefixOf` path'
+
+ orM :: [IO Bool] -> IO Bool
+ orM [] = return False
+ orM (x : xs) = x >>= \b -> if b then return True else orM xs