summaryrefslogtreecommitdiff
path: root/src/Hakyll/Core/Util
diff options
context:
space:
mode:
authorJasper Van der Jeugt <m@jaspervdj.be>2012-11-19 14:59:55 +0100
committerJasper Van der Jeugt <m@jaspervdj.be>2012-11-19 14:59:55 +0100
commit88ffd3c5bea6b5e5cb1004173130b5691a7591f6 (patch)
tree8205d11882dc3a78f6ea03fe0adef390bc023670 /src/Hakyll/Core/Util
parent6b5c299ec945cdfea2dbf2df0922f8753588b729 (diff)
downloadhakyll-88ffd3c5bea6b5e5cb1004173130b5691a7591f6.tar.gz
Add tests again
Diffstat (limited to 'src/Hakyll/Core/Util')
-rw-r--r--src/Hakyll/Core/Util/File.hs64
1 files changed, 36 insertions, 28 deletions
diff --git a/src/Hakyll/Core/Util/File.hs b/src/Hakyll/Core/Util/File.hs
index 5889664..85fbd76 100644
--- a/src/Hakyll/Core/Util/File.hs
+++ b/src/Hakyll/Core/Util/File.hs
@@ -1,52 +1,60 @@
+--------------------------------------------------------------------------------
-- | A module containing various file utility functions
---
module Hakyll.Core.Util.File
( makeDirectories
, getRecursiveContents
, isFileInternal
) where
-import Control.Applicative ((<$>))
-import Control.Monad (forM)
-import Data.List (isPrefixOf)
-import System.Directory ( createDirectoryIfMissing, doesDirectoryExist
- , getDirectoryContents
- )
-import System.FilePath ( normalise, takeDirectory, splitPath
- , dropTrailingPathSeparator, (</>)
- )
-import Hakyll.Core.Configuration
+--------------------------------------------------------------------------------
+import Control.Applicative ((<$>))
+import Control.Monad (forM)
+import Data.List (isPrefixOf)
+import System.Directory (createDirectoryIfMissing,
+ doesDirectoryExist,
+ getDirectoryContents)
+import System.FilePath (dropTrailingPathSeparator,
+ splitPath, takeDirectory, (</>))
+
+--------------------------------------------------------------------------------
+import Hakyll.Core.Configuration
+
+
+--------------------------------------------------------------------------------
-- | Given a path to a file, try to make the path writable by making
-- all directories on the path.
---
makeDirectories :: FilePath -> IO ()
makeDirectories = createDirectoryIfMissing True . takeDirectory
+
+--------------------------------------------------------------------------------
-- | Get all contents of a directory.
-getRecursiveContents :: Bool -- ^ Include directories?
- -> FilePath -- ^ Directory to search
+getRecursiveContents :: FilePath -- ^ Directory to search
-> IO [FilePath] -- ^ List of files found
-getRecursiveContents includeDirs topdir = do
- topdirExists <- doesDirectoryExist topdir
- 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
+getRecursiveContents top = go ""
where
isProper = (`notElem` [".", ".."])
+ go dir = do
+ dirExists <- doesDirectoryExist (top </> dir)
+ if not dirExists
+ then return []
+ else do
+ names <- filter isProper <$> getDirectoryContents (top </> dir)
+ paths <- forM names $ \name -> do
+ let rel = dir </> name
+ isDirectory <- doesDirectoryExist (top </> rel)
+ if isDirectory
+ then go rel
+ else return [rel]
+
+ return $ concat paths
+
+--------------------------------------------------------------------------------
-- | Check if a file is meant for Hakyll internal use, i.e. if it is located in
-- the destination or store directory
---
isFileInternal :: Configuration -- ^ Configuration
-> FilePath -- ^ File to check
-> Bool -- ^ If the given file is internal