on master help sign in
Account for absolute paths in `shouldIgnoreFile`
commit5e4adaecb232231d87a6bb4dd0b041daf86a4cdb authorJasper Van der Jeugt <m@jaspervdj.be> dateWed 3 Apr 2013, 12:02 (14 years ago) parent792fcdf
7 files changed+47−30
src/Hakyll/Check.hs+2−2 src/Hakyll/Core/Configuration.hs+26−12 src/Hakyll/Core/Provider.hs+4−4 src/Hakyll/Core/Provider/Internal.hs+4−4 src/Hakyll/Core/Util/File.hs+9−6 src/Hakyll/Init.hs+1−1 tests/TestSuite/Util.hs+1−1
src/Hakyll/Check.hs+2−2
@@ -109,8 +109,8 @@ runChecker checker config verbosity check' = do
109109checkDestination :: Checker ()
110110checkDestination = do
111111 config <- checkerConfig <$> ask
112− files <- liftIO $
113− getRecursiveContents (const False) (destinationDirectory config)
112+ files <- liftIO $ getRecursiveContents
113+ (const $ return False) (destinationDirectory config)
114114
115115 let htmls =
116116 [ destinationDirectory config </> file
src/Hakyll/Core/Configuration.hs+26−12
@@ -8,11 +8,13 @@ module Hakyll.Core.Configuration
88
99
1010--------------------------------------------------------------------------------
11−import Control.Monad (void)
12−import Data.Default (Default(..))
13−import Data.List (isPrefixOf, isSuffixOf)
14−import System.FilePath (normalise, takeFileName)
15−import System.Process (system)
11+import Control.Monad (void)
12+import Data.Default (Default (..))
13+import Data.List (isPrefixOf, isSuffixOf)
14+import System.Directory (canonicalizePath)
15+import System.FilePath (isAbsolute, normalise, takeFileName)
16+import System.IO.Error (catchIOError)
17+import System.Process (system)
1618
1719
1820--------------------------------------------------------------------------------
@@ -99,11 +101,23 @@ defaultConfiguration = Configuration
99101
100102--------------------------------------------------------------------------------
101103-- | Check if a file should be ignored
102−shouldIgnoreFile :: Configuration -> FilePath -> Bool
103−shouldIgnoreFile conf path =
104− destinationDirectory conf `isPrefixOf` path' ||
105− storeDirectory conf `isPrefixOf` path' ||
106− tmpDirectory conf `isPrefixOf` path' ||
107− ignoreFile conf path'
104+shouldIgnoreFile :: Configuration -> FilePath -> IO Bool
105+shouldIgnoreFile conf path = orM
106+ [ inDir (destinationDirectory conf)
107+ , inDir (storeDirectory conf)
108+ , inDir (tmpDirectory conf)
109+ , return (ignoreFile conf path')
110+ ]
108111 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)
3131
3232--------------------------------------------------------------------------------
3333-- | Create a resource provider
34−newProvider :: Store -- ^ Store to use
35− -> (FilePath -> Bool) -- ^ Should we ignore this file?
36− -> FilePath -- ^ Search directory
37− -> IO Internal.Provider -- ^ Resulting provider
34+newProvider :: Store -- ^ Store to use
35+ -> (FilePath -> IO Bool) -- ^ Should we ignore this file?
36+ -> FilePath -- ^ Search directory
37+ -> IO Internal.Provider -- ^ Resulting provider
3838newProvider store ignore directory = do
3939 -- Delete metadata cache where necessary
4040 p <- Internal.newProvider store ignore directory
src/Hakyll/Core/Provider/Internal.hs+4−4
@@ -103,10 +103,10 @@ data Provider = Provider
103103
104104--------------------------------------------------------------------------------
105105-- | Create a resource provider
106−newProvider :: Store -- ^ Store to use
107− -> (FilePath -> Bool) -- ^ Should we ignore this file?
108− -> FilePath -- ^ Search directory
109− -> IO Provider -- ^ Resulting provider
106+newProvider :: Store -- ^ Store to use
107+ -> (FilePath -> IO Bool) -- ^ Should we ignore this file?
108+ -> FilePath -- ^ Search directory
109+ -> IO Provider -- ^ Resulting provider
110110newProvider store ignore directory = do
111111 list <- map fromFilePath <$> getRecursiveContents ignore directory
112112 let universe = S.fromList list
src/Hakyll/Core/Util/File.hs+9−6
@@ -9,7 +9,7 @@ module Hakyll.Core.Util.File
99
1010--------------------------------------------------------------------------------
1111import Control.Applicative ((<$>))
12−import Control.Monad (forM, when)
12+import Control.Monad (filterM, forM, when)
1313import System.Directory (createDirectoryIfMissing,
1414 doesDirectoryExist, getDirectoryContents,
1515 removeDirectoryRecursive)
@@ -25,18 +25,21 @@ makeDirectories = createDirectoryIfMissing True . takeDirectory
2525
2626--------------------------------------------------------------------------------
2727-- | Get all contents of a directory.
28−getRecursiveContents :: (FilePath -> Bool) -- ^ Ignore this file/directory
29− -> FilePath -- ^ Directory to search
30− -> IO [FilePath] -- ^ List of files found
28+getRecursiveContents :: (FilePath -> IO Bool) -- ^ Ignore this file/directory
29+ -> FilePath -- ^ Directory to search
30+ -> IO [FilePath] -- ^ List of files found
3131getRecursiveContents ignore top = go ""
3232 where
33− isProper x = notElem x [".", ".."] && not (ignore x)
33+ isProper x
34+ | x `elem` [".", ".."] = return False
35+ | otherwise = not <$> ignore x
36+
3437 go dir = do
3538 dirExists <- doesDirectoryExist (top </> dir)
3639 if not dirExists
3740 then return []
3841 else do
39− names <- filter isProper <$> getDirectoryContents (top </> dir)
42+ names <- filterM isProper =<< getDirectoryContents (top </> dir)
4043 paths <- forM names $ \name -> do
4144 let rel = dir </> name
4245 isDirectory <- doesDirectoryExist (top </> rel)
src/Hakyll/Init.hs+1−1
@@ -23,7 +23,7 @@ main = do
2323 progName <- getProgName
2424 args <- getArgs
2525 srcDir <- getDataFileName "example"
26− files <- getRecursiveContents (const False) srcDir
26+ files <- getRecursiveContents (const $ return False) srcDir
2727
2828 case args of
2929 [dstDir] -> forM_ files $ \file -> do
tests/TestSuite/Util.hs+1−1
@@ -46,7 +46,7 @@ newTestStore = Store.new True $ storeDirectory testConfiguration
4646
4747--------------------------------------------------------------------------------
4848newTestProvider :: Store -> IO Provider
49−newTestProvider store = newProvider store (const False) $
49+newTestProvider store = newProvider store (const $ return False) $
5050 providerDirectory testConfiguration
5151
5252