LIB: add mkdirP

This commit is contained in:
Julian Ospald 2016-04-26 01:45:24 +02:00
parent 746daf9ba6
commit 8bcdb84efd
No known key found for this signature in database
GPG Key ID: 511B62C09D50CD28
1 changed files with 15 additions and 2 deletions

View File

@ -37,10 +37,15 @@ import Control.Exception
)
import Control.Monad
(
unless
forM_
, unless
, void
, when
)
import Control.Monad.Loops
(
dropWhileM
)
import Data.ByteString
(
ByteString
@ -551,10 +556,18 @@ createDir :: File FileInfo -> Path Fn -> IO ()
createDir (DirOrSym td) fn = do
let fullp = path td P.</> fn
throwDirDoesExist fullp
createDirectory (P.fromAbs fullp) newFilePerms
createDirectory (P.fromAbs fullp) newDirPerms
createDir _ _ = throw $ InvalidOperation "wrong input type"
-- |Create a directory at the given path, creating all parents if
-- necessary.
mkdirP :: Path Abs -> IO ()
mkdirP p = do
mkps <- dropWhileM canOpenDirectory (reverse $ p : P.getAllParents p)
forM_ mkps $ \mkp -> createDirectory (P.fromAbs mkp) newDirPerms
----------------------------