diff options
| author | Joey Hess <joeyh@joeyh.name> | 2017-10-25 11:48:50 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2017-10-25 11:48:50 -0400 |
| commit | 628f239e0dab82cee2c1b9a1f2818695990df122 (patch) | |
| tree | b9260f539dcf6eb126a6e0476528364eb81ab600 /src/Utility | |
| parent | c693c11b69cfa18d30fbadefbea257bf62c314a6 (diff) | |
| parent | b437fa963d7e44945d24c1c5a6453cebcaf7a682 (diff) | |
Merge remote-tracking branch 'nicolas/ignore-lost-n-found'
Diffstat (limited to 'src/Utility')
| -rw-r--r-- | src/Utility/Directory.hs | 19 |
1 files changed, 17 insertions, 2 deletions
diff --git a/src/Utility/Directory.hs b/src/Utility/Directory.hs index 693e7713..86904d63 100644 --- a/src/Utility/Directory.hs +++ b/src/Utility/Directory.hs @@ -42,6 +42,10 @@ dirCruft "." = True dirCruft ".." = True dirCruft _ = False +fsCruft :: FilePath -> Bool +fsCruft "lost+found" = True +fsCruft d = dirCruft d + {- Lists the contents of a directory. - Unlike getDirectoryContents, paths are not relative to the directory. -} dirContents :: FilePath -> IO [FilePath] @@ -236,12 +240,23 @@ readDirectory hdl@(DirectoryHandle _ h fdat mv) = do -- 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 +isDirectoryEmpty d = testDirectory d dirCruft + +-- | True if the directory does not exists or contains nothing, ignoring +-- "lost+found" which can exists in an empty filesystem. +isUnpopulated :: FilePath -> IO Bool +isUnpopulated d = catchDefaultIO True $ testDirectory d fsCruft + +-- | Run test on entries found in directory, return False as soon as the +-- test returns False, else return True. Throws exception if directory does +-- not exist. +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 (dirCruft f) -> return False + | not (test f) -> return False | otherwise -> check h |
