Improve createDirRecursive
This commit is contained in:
parent
5b08e14b55
commit
4dec385332
@ -89,6 +89,10 @@ import Control.Monad
|
|||||||
, void
|
, void
|
||||||
, when
|
, when
|
||||||
)
|
)
|
||||||
|
import Control.Monad.IfElse
|
||||||
|
(
|
||||||
|
unlessM
|
||||||
|
)
|
||||||
import Data.ByteString
|
import Data.ByteString
|
||||||
(
|
(
|
||||||
ByteString
|
ByteString
|
||||||
@ -687,12 +691,11 @@ createDir fm dest = createDirectory (fromAbs dest) fm
|
|||||||
|
|
||||||
|
|
||||||
-- |Create an empty directory at the given directory with the given filename.
|
-- |Create an empty directory at the given directory with the given filename.
|
||||||
--
|
|
||||||
-- All parent directories are created with the same filemode. This
|
-- All parent directories are created with the same filemode. This
|
||||||
-- basically behaves like:
|
-- basically behaves like:
|
||||||
--
|
--
|
||||||
-- @
|
-- @
|
||||||
-- mkdir -p \/destination\/somedir
|
-- mkdir -p \/some\/dir
|
||||||
-- @
|
-- @
|
||||||
--
|
--
|
||||||
-- Safety/reliability concerns:
|
-- Safety/reliability concerns:
|
||||||
@ -709,9 +712,8 @@ createDirRecursive :: FileMode -> Path Abs -> IO ()
|
|||||||
createDirRecursive fm dest =
|
createDirRecursive fm dest =
|
||||||
catchIOError (createDirectory (fromAbs dest) fm) $ \e -> do
|
catchIOError (createDirectory (fromAbs dest) fm) $ \e -> do
|
||||||
errno <- getErrno
|
errno <- getErrno
|
||||||
isd <- doesDirectoryExist dest
|
|
||||||
case errno of
|
case errno of
|
||||||
en | en == eEXIST && isd -> return ()
|
en | en == eEXIST -> unlessM (doesDirectoryExist dest) (ioError e)
|
||||||
| en == eNOENT -> createDirRecursive fm (dirname dest)
|
| en == eNOENT -> createDirRecursive fm (dirname dest)
|
||||||
>> createDirectory (fromAbs dest) fm
|
>> createDirectory (fromAbs dest) fm
|
||||||
| otherwise -> ioError e
|
| otherwise -> ioError e
|
||||||
|
Loading…
Reference in New Issue
Block a user