From f5c11a1acc4ded0ffcf0f9e6cf7c316750d61ee7 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 22 Sep 2015 12:59:56 -0400 Subject: Improve robustness of direct mode merge, avoiding a crash if the index file is missing. I couldn't find a good way to make an *empty* index file (zero byte file won't do), so I punted and just don't make index.lock when there's no index yet. This means some other git process could race and write an index file at the same time as the merge is ongoing, in theory. Only happens in new repos though. --- Annex/Direct.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'Annex') diff --git a/Annex/Direct.hs b/Annex/Direct.hs index d88dc43fb..35a5b5013 100644 --- a/Annex/Direct.hs +++ b/Annex/Direct.hs @@ -153,7 +153,7 @@ addDirect file cache = do - - A lock file is used to avoid races with any other caller of mergeDirect. - - - To avoid other git processes from making change to the index while our + - To avoid other git processes from making changes to the index while our - merge is in progress, the index lock file is used as the temp index - file. This is the same as what git does when updating the index - normally. @@ -162,7 +162,8 @@ mergeDirect :: Maybe Git.Ref -> Maybe Git.Ref -> Git.Branch -> Annex Bool -> Git mergeDirect startbranch oldref branch resolvemerge commitmode = exclusively $ do reali <- liftIO . absPath =<< fromRepo indexFile tmpi <- liftIO . absPath =<< fromRepo indexFileLock - liftIO $ copyFile reali tmpi + liftIO $ whenM (doesFileExist reali) $ + copyFile reali tmpi d <- fromRepo gitAnnexMergeDir liftIO $ do @@ -178,7 +179,8 @@ mergeDirect startbranch oldref branch resolvemerge commitmode = exclusively $ do mergeDirectCleanup d (fromMaybe Git.Sha.emptyTree oldref) mergeDirectCommit merged startbranch branch commitmode - liftIO $ rename tmpi reali + liftIO $ whenM (doesFileExist tmpi) $ + rename tmpi reali return r where -- cgit v1.2.3