on master help sign in
Account for absolute paths in `shouldIgnoreFile`
5e4adaeJasper Van der Jeugt
src/Hakyll/Check.hs+2−2
@@ -109,8 +109,8 @@ runChecker checker config verbosity check' = do
109checkDestination :: Checker ()
109checkDestination :: Checker ()
110checkDestination = do
110checkDestination = do
111 config <- checkerConfig <$> ask
111 config <- checkerConfig <$> ask
112− files <- liftIO $
112+ files <- liftIO $ getRecursiveContents
113− getRecursiveContents (const False) (destinationDirectory config)
113+ (const $ return False) (destinationDirectory config)
114
114
115 let htmls =
115 let htmls =
116 [ destinationDirectory config </> file
116 [ destinationDirectory config </> file
src/Hakyll/Core/Configuration.hs+26−12
@@ -8,11 +8,13 @@ module Hakyll.Core.Configuration
8
8
9
9
10--------------------------------------------------------------------------------
10--------------------------------------------------------------------------------
11−import Control.Monad (void)
11+import Control.Monad (void)
12−import Data.Default (Default(..))
12+import Data.Default (Default (..))
13−import Data.List (isPrefixOf, isSuffixOf)
13+import Data.List (isPrefixOf, isSuffixOf)
14+import System.Directory (canonicalizePath)
14−import System.FilePath (normalise, takeFileName)
15+import System.FilePath (isAbsolute, normalise, takeFileName)
16+import System.IO.Error (catchIOError)
15−import System.Process (system)
17+import System.Process (system)
16
18
17
19
18--------------------------------------------------------------------------------
20--------------------------------------------------------------------------------
@@ -99,11 +101,23 @@ defaultConfiguration = Configuration
99
101
100--------------------------------------------------------------------------------
102--------------------------------------------------------------------------------
101-- | Check if a file should be ignored
103-- | Check if a file should be ignored
102−shouldIgnoreFile :: Configuration -> FilePath -> Bool
104+shouldIgnoreFile :: Configuration -> FilePath -> IO Bool
103−shouldIgnoreFile conf path =
105+shouldIgnoreFile conf path = orM
104− destinationDirectory conf `isPrefixOf` path' ||
106+ [ inDir (destinationDirectory conf)
105− storeDirectory conf `isPrefixOf` path' ||
107+ , inDir (storeDirectory conf)
106− tmpDirectory conf `isPrefixOf` path' ||
108+ , inDir (tmpDirectory conf)
107− ignoreFile conf path'
109+ , return (ignoreFile conf path')
110+ ]
108 where
111 where
109− path' = normalise path
112+ path' = normalise path
113+ absolute = isAbsolute path
114+
115+ inDir dir
116+ | absolute = do
117+ dir' <- catchIOError (canonicalizePath dir) (const $ return dir)
118+ return $ dir' `isPrefixOf` path'
119+ | otherwise = return $ dir `isPrefixOf` path'
120+
121+ orM :: [IO Bool] -> IO Bool
122+ orM [] = return False
123+ orM (x : xs) = x >>= \b -> if b then return True else orM xs
src/Hakyll/Core/Provider.hs+4−4
@@ -31,10 +31,10 @@ import Hakyll.Core.Store (Store)
31
31
32--------------------------------------------------------------------------------
32--------------------------------------------------------------------------------
33-- | Create a resource provider
33-- | Create a resource provider
34−newProvider :: Store -- ^ Store to use
34+newProvider :: Store -- ^ Store to use
35− -> (FilePath -> Bool) -- ^ Should we ignore this file?
35+ -> (FilePath -> IO Bool) -- ^ Should we ignore this file?
36− -> FilePath -- ^ Search directory
36+ -> FilePath -- ^ Search directory
37− -> IO Internal.Provider -- ^ Resulting provider
37+ -> IO Internal.Provider -- ^ Resulting provider
38newProvider store ignore directory = do
38newProvider store ignore directory = do
39 -- Delete metadata cache where necessary
39 -- Delete metadata cache where necessary
40 p <- Internal.newProvider store ignore directory
40 p <- Internal.newProvider store ignore directory
src/Hakyll/Core/Provider/Internal.hs+4−4
@@ -103,10 +103,10 @@ data Provider = Provider
103
103
104--------------------------------------------------------------------------------
104--------------------------------------------------------------------------------
105-- | Create a resource provider
105-- | Create a resource provider
106−newProvider :: Store -- ^ Store to use
106+newProvider :: Store -- ^ Store to use
107− -> (FilePath -> Bool) -- ^ Should we ignore this file?
107+ -> (FilePath -> IO Bool) -- ^ Should we ignore this file?
108− -> FilePath -- ^ Search directory
108+ -> FilePath -- ^ Search directory
109− -> IO Provider -- ^ Resulting provider
109+ -> IO Provider -- ^ Resulting provider
110newProvider store ignore directory = do
110newProvider store ignore directory = do
111 list <- map fromFilePath <$> getRecursiveContents ignore directory
111 list <- map fromFilePath <$> getRecursiveContents ignore directory
112 let universe = S.fromList list
112 let universe = S.fromList list
src/Hakyll/Core/Util/File.hs+9−6
@@ -9,7 +9,7 @@ module Hakyll.Core.Util.File
9
9
10--------------------------------------------------------------------------------
10--------------------------------------------------------------------------------
11import Control.Applicative ((<$>))
11import Control.Applicative ((<$>))
12−import Control.Monad (forM, when)
12+import Control.Monad (filterM, forM, when)
13import System.Directory (createDirectoryIfMissing,
13import System.Directory (createDirectoryIfMissing,
14 doesDirectoryExist, getDirectoryContents,
14 doesDirectoryExist, getDirectoryContents,
15 removeDirectoryRecursive)
15 removeDirectoryRecursive)
@@ -25,18 +25,21 @@ makeDirectories = createDirectoryIfMissing True . takeDirectory
25
25
26--------------------------------------------------------------------------------
26--------------------------------------------------------------------------------
27-- | Get all contents of a directory.
27-- | Get all contents of a directory.
28−getRecursiveContents :: (FilePath -> Bool) -- ^ Ignore this file/directory
28+getRecursiveContents :: (FilePath -> IO Bool) -- ^ Ignore this file/directory
29− -> FilePath -- ^ Directory to search
29+ -> FilePath -- ^ Directory to search
30− -> IO [FilePath] -- ^ List of files found
30+ -> IO [FilePath] -- ^ List of files found
31getRecursiveContents ignore top = go ""
31getRecursiveContents ignore top = go ""
32 where
32 where
33− isProper x = notElem x [".", ".."] && not (ignore x)
33+ isProper x
34+ | x `elem` [".", ".."] = return False
35+ | otherwise = not <$> ignore x
36+
34 go dir = do
37 go dir = do
35 dirExists <- doesDirectoryExist (top </> dir)
38 dirExists <- doesDirectoryExist (top </> dir)
36 if not dirExists
39 if not dirExists
37 then return []
40 then return []
38 else do
41 else do
39− names <- filter isProper <$> getDirectoryContents (top </> dir)
42+ names <- filterM isProper =<< getDirectoryContents (top </> dir)
40 paths <- forM names $ \name -> do
43 paths <- forM names $ \name -> do
41 let rel = dir </> name
44 let rel = dir </> name
42 isDirectory <- doesDirectoryExist (top </> rel)
45 isDirectory <- doesDirectoryExist (top </> rel)
src/Hakyll/Init.hs+1−1
@@ -23,7 +23,7 @@ main = do
23 progName <- getProgName
23 progName <- getProgName
24 args <- getArgs
24 args <- getArgs
25 srcDir <- getDataFileName "example"
25 srcDir <- getDataFileName "example"
26− files <- getRecursiveContents (const False) srcDir
26+ files <- getRecursiveContents (const $ return False) srcDir
27
27
28 case args of
28 case args of
29 [dstDir] -> forM_ files $ \file -> do
29 [dstDir] -> forM_ files $ \file -> do
tests/TestSuite/Util.hs+1−1
@@ -46,7 +46,7 @@ newTestStore = Store.new True $ storeDirectory testConfiguration
46
46
47--------------------------------------------------------------------------------
47--------------------------------------------------------------------------------
48newTestProvider :: Store -> IO Provider
48newTestProvider :: Store -> IO Provider
49−newTestProvider store = newProvider store (const False) $
49+newTestProvider store = newProvider store (const $ return False) $
50 providerDirectory testConfiguration
50 providerDirectory testConfiguration
51
51
52
52