From 4dec38533281d2783ea7caac01cfbc13ef002ed3 Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 13 Jun 2016 01:38:44 +0200 Subject: [PATCH] Improve createDirRecursive --- src/HPath/IO.hs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/HPath/IO.hs b/src/HPath/IO.hs index a2dc46a..6526be3 100644 --- a/src/HPath/IO.hs +++ b/src/HPath/IO.hs @@ -89,6 +89,10 @@ import Control.Monad , void , when ) +import Control.Monad.IfElse + ( + unlessM + ) import Data.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. --- -- All parent directories are created with the same filemode. This -- basically behaves like: -- -- @ --- mkdir -p \/destination\/somedir +-- mkdir -p \/some\/dir -- @ -- -- Safety/reliability concerns: @@ -709,9 +712,8 @@ createDirRecursive :: FileMode -> Path Abs -> IO () createDirRecursive fm dest = catchIOError (createDirectory (fromAbs dest) fm) $ \e -> do errno <- getErrno - isd <- doesDirectoryExist dest case errno of - en | en == eEXIST && isd -> return () + en | en == eEXIST -> unlessM (doesDirectoryExist dest) (ioError e) | en == eNOENT -> createDirRecursive fm (dirname dest) >> createDirectory (fromAbs dest) fm | otherwise -> ioError e