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 - 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 - 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 - no writers to know when to commit them). Also, a few lock-file-ish
- file appears stale, we delay for one minute, and check its size. If - things used by git are not kept open, particularly MERGE_HEAD.
- 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 - So, just in case, when the lock file appears stale, we delay for one
- file, since git does so by writing the new content to index.lock. - 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. - Returns true if locks were cleaned up.
-} -}
repairStaleGitLocks :: Git.Repo -> Assistant Bool repairStaleGitLocks :: Git.Repo -> Assistant Bool
repairStaleGitLocks r = do repairStaleGitLocks r = do
lockfiles <- filter (not . isInfixOf "gc.pid") lockfiles <- liftIO $ filter islock <$> findgitfiles r
. filter (".lock" `isSuffixOf`)
<$> liftIO (findgitfiles r)
repairStaleLocks lockfiles repairStaleLocks lockfiles
return $ not $ null lockfiles return $ not $ null lockfiles
where where
findgitfiles = dirContentsRecursiveSkipping (== dropTrailingPathSeparator annexDir) True . Git.localGitDir 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 :: [FilePath] -> Assistant ()
repairStaleLocks lockfiles = go =<< getsizes repairStaleLocks lockfiles = go =<< getsizes
where 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. since this is used for password prompting.
* Avoid looping if long-running git cat-file or git hash-object crashes * Avoid looping if long-running git cat-file or git hash-object crashes
and keeps crashing when restarted. 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 -- Joey Hess <joeyh@debian.org> Tue, 31 Dec 2013 13:41:18 -0400