summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-11-02 15:09:19 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-11-02 15:09:19 -0400
commit5f3dd3d246c757ee92aa8e68654071519364c0e9 (patch)
treeac31938cdbbee8f702fba4a70e228a2d6d0f2352
parentc33313c50b1a9424dd20e6e9995c46d60a48e540 (diff)
ensure directory exists when locking journal
Fixes git annex init in a bare repository that already has a git-annex branch.
-rw-r--r--Annex/Branch.hs11
1 files changed, 8 insertions, 3 deletions
diff --git a/Annex/Branch.hs b/Annex/Branch.hs
index 645a2de76..4c3192f53 100644
--- a/Annex/Branch.hs
+++ b/Annex/Branch.hs
@@ -250,10 +250,9 @@ files = withIndexUpdate $ do
setJournalFile :: FilePath -> String -> Annex ()
setJournalFile file content = do
g <- gitRepo
- liftIO $ catch (write g) $ const $ do
+ liftIO $ doRedo (write g) $ do
createDirectoryIfMissing True $ gitAnnexJournalDir g
createDirectoryIfMissing True $ gitAnnexTmpDir g
- write g
where
-- journal file is written atomically
write g = do
@@ -342,7 +341,13 @@ lockJournal a = do
bracketIO (lock file) unlock a
where
lock file = do
- l <- createFile file stdFileMode
+ l <- doRedo (createFile file stdFileMode) $
+ createDirectoryIfMissing True $ takeDirectory file
waitToSetLock l (WriteLock, AbsoluteSeek, 0, 0)
return l
unlock = closeFd
+
+{- Runs an action, catching failure and running something to fix it up, and
+ - retrying if necessary. -}
+doRedo :: IO a -> IO b -> IO a
+doRedo a b = catch a $ const $ b >> a