summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core/Util
diff options
context:
space:
mode:
authorJasper Van der Jeugt <jaspervdj@gmail.com>2011-02-10 18:59:16 +0100
committerJasper Van der Jeugt <jaspervdj@gmail.com>2011-02-10 18:59:16 +0100
commit77f37c1443293b791841538bf860e346536e306d (patch)
tree587746f29c1e1f89cbc7d1ac470fdcc6e28886ae /src/Hakyll/Core/Util
parent48da85b3418e7805d27cd2703f83570027d66a2a (diff)
downloadhakyll-77f37c1443293b791841538bf860e346536e306d.tar.gz
getRecursiveContents can return directories
Diffstat (limited to 'src/Hakyll/Core/Util')
-rw-r--r--src/Hakyll/Core/Util/File.hs31
1 files changed, 17 insertions, 14 deletions
diff --git a/src/Hakyll/Core/Util/File.hs b/src/Hakyll/Core/Util/File.hs
index 71de322..9babc8b 100644
--- a/src/Hakyll/Core/Util/File.hs
+++ b/src/Hakyll/Core/Util/File.hs
@@ -7,6 +7,7 @@ module Hakyll.Core.Util.File
, isFileInternal
) where
+import Control.Applicative ((<$>))
import System.Time (ClockTime)
import Control.Monad (forM, filterM)
import Data.List (isPrefixOf)
@@ -27,22 +28,24 @@ makeDirectories :: FilePath -> IO ()
makeDirectories = createDirectoryIfMissing True . takeDirectory
-- | Get all contents of a directory. Note that files starting with a dot (.)
--- will be ignored.
+-- will be ignored.
--
-getRecursiveContents :: FilePath -> IO [FilePath]
-getRecursiveContents topdir = do
+getRecursiveContents :: Bool -- ^ Include directories?
+ -> FilePath -- ^ Directory to search
+ -> IO [FilePath] -- ^ List of files found
+getRecursiveContents includeDirs topdir = do
topdirExists <- doesDirectoryExist topdir
- if topdirExists
- then do names <- getDirectoryContents topdir
- let properNames = filter isProper names
- paths <- forM properNames $ \name -> do
- let path = topdir </> name
- isDirectory <- doesDirectoryExist path
- if isDirectory
- then getRecursiveContents path
- else return [normalise path]
- return (concat paths)
- else return []
+ if not topdirExists
+ then return []
+ else do
+ names <- filter isProper <$> getDirectoryContents topdir
+ paths <- forM names $ \name -> do
+ let path = normalise $ topdir </> name
+ isDirectory <- doesDirectoryExist path
+ if isDirectory then getRecursiveContents includeDirs path
+ else return [path]
+ return $ if includeDirs then topdir : concat paths
+ else concat paths
where
isProper = not . (== ".") . take 1