Assistant: Remove stale MERGE_HEAD files in lockfile cleanup.

See http://git-annex.branchable.com/forum/How_to_resolve_a_interrupted_merge_in_direct_mode__63__/
This commit is contained in:
Joey Hess 2014-01-01 22:05:33 -04:00
parent 858eb26303
commit f83e5c75dc
2 changed files with 16 additions and 8 deletions

View file

@ -113,23 +113,30 @@ runRepair u mrmt destructiverepair = do
-
- However, this could be on a network filesystem. Which is not very safe
- anyway (the assistant relies on being able to check when files have
- no writers to know when to commit them). Just in case, when the lock
- file appears stale, we delay for one minute, and check its size. If
- the size changed, delay for another minute, and so on. This will at
- least work to detect is another machine is writing out a new index
- file, since git does so by writing the new content to index.lock.
- no writers to know when to commit them). Also, a few lock-file-ish
- things used by git are not kept open, particularly MERGE_HEAD.
-
- So, just in case, when the lock file appears stale, we delay for one
- minute, and check its size. If the size changed, delay for another
- minute, and so on. This will at work to detect when another machine
- is writing out a new index file, since git does so by writing the
- new content to index.lock.
-
- Returns true if locks were cleaned up.
-}
repairStaleGitLocks :: Git.Repo -> Assistant Bool
repairStaleGitLocks r = do
lockfiles <- filter (not . isInfixOf "gc.pid")
. filter (".lock" `isSuffixOf`)
<$> liftIO (findgitfiles r)
lockfiles <- liftIO $ filter islock <$> findgitfiles r
repairStaleLocks lockfiles
return $ not $ null lockfiles
where
findgitfiles = dirContentsRecursiveSkipping (== dropTrailingPathSeparator annexDir) True . Git.localGitDir
islock f
| "gc.pid" `isInfixOf` f = False
| ".lock" `isSuffixOf` f = True
| takeFileName f == "MERGE_HEAD" = True
| otherwise = False
repairStaleLocks :: [FilePath] -> Assistant ()
repairStaleLocks lockfiles = go =<< getsizes
where

1
debian/changelog vendored
View file

@ -8,6 +8,7 @@ git-annex (5.20131231) UNRELEASED; urgency=medium
since this is used for password prompting.
* Avoid looping if long-running git cat-file or git hash-object crashes
and keeps crashing when restarted.
* Assistant: Remove stale MERGE_HEAD files in lockfile cleanup.
-- Joey Hess <joeyh@debian.org> Tue, 31 Dec 2013 13:41:18 -0400