summaryrefslogtreecommitdiff
path: root/Utility
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2014-07-10 00:16:53 -0400
committerGravatar Joey Hess <joey@kitenet.net>2014-07-10 00:16:53 -0400
commit200b8d462e46db7b6bb87ab832529199fff58247 (patch)
tree156302f2b35e085f9bf88a2ab1a9cbf70f9772ca /Utility
parente3c1ea0c526d74dd1636be4488437c9845fb4fad (diff)
refactor
Diffstat (limited to 'Utility')
-rw-r--r--Utility/Directory.hs15
1 files changed, 14 insertions, 1 deletions
diff --git a/Utility/Directory.hs b/Utility/Directory.hs
index d4e9b358f..ade5ef811 100644
--- a/Utility/Directory.hs
+++ b/Utility/Directory.hs
@@ -11,7 +11,7 @@ module Utility.Directory where
import System.IO.Error
import System.Directory
-import Control.Exception (throw)
+import Control.Exception (throw, bracket)
import Control.Monad
import Control.Monad.IfElse
import System.FilePath
@@ -215,3 +215,16 @@ readDirectory hdl@(DirectoryHandle _ h fdat mv) = do
filename <- Win32.getFindDataFileName fdat
return (Just filename)
#endif
+
+-- True only when directory exists and contains nothing.
+-- Throws exception if directory does not exist.
+isDirectoryEmpty :: FilePath -> IO Bool
+isDirectoryEmpty d = bracket (openDirectory d) closeDirectory check
+ where
+ check h = do
+ v <- readDirectory h
+ case v of
+ Nothing -> return True
+ Just f
+ | not (dirCruft f) -> return False
+ | otherwise -> check h