diff options
-rw-r--r-- | Annex/Journal.hs | 16 | ||||
-rw-r--r-- | Utility/Directory.hs | 15 |
2 files changed, 19 insertions, 12 deletions
diff --git a/Annex/Journal.hs b/Annex/Journal.hs index 198388aa8..4d9c6ab66 100644 --- a/Annex/Journal.hs +++ b/Annex/Journal.hs @@ -87,17 +87,11 @@ withJournalHandle a = do {- Checks if there are changes in the journal. -} journalDirty :: Annex Bool -journalDirty = withJournalHandle go - where - go h = do - v <- readDirectory h - case v of - (Just f) - | not (dirCruft f) -> do - closeDirectory h - return True - | otherwise -> go h - Nothing -> return False +journalDirty = do + d <- fromRepo gitAnnexJournalDir + liftIO $ + (not <$> isDirectoryEmpty d) + `catchIO` (const $ doesDirectoryExist d) {- Produces a filename to use in the journal for a file on the branch. - 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 |