module Utility.Directory.TestDirectory where
import Utility.Directory
import Utility.Directory.Stream
import Utility.Exception
isDirectoryEmpty :: FilePath -> IO Bool
isDirectoryEmpty d = testDirectory d dirCruft
isUnpopulated :: FilePath -> IO Bool
isUnpopulated d = catchDefaultIO True $ testDirectory d fsCruft
fsCruft :: FilePath -> Bool
fsCruft "lost+found" = True
fsCruft d = dirCruft d
testDirectory :: FilePath -> (FilePath -> Bool) -> IO Bool
testDirectory d test = bracket (openDirectory d) closeDirectory check
where
check h = do
v <- readDirectory h
case v of
Nothing -> return True
Just f
| not (test f) -> return False
| otherwise -> check h