fix stale git locks as part of repo repair

This commit is contained in:
Joey Hess 2013-10-29 13:52:19 -04:00
parent fabb0c50b7
commit 791c8535b5
3 changed files with 12 additions and 9 deletions

View file

@ -119,15 +119,16 @@ runRepair u mrmt destructiverepair = do
- 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.
-}
checkStaleGitLocks :: Assistant ()
checkStaleGitLocks = do
repairStaleGitLocks :: Git.Repo -> Assistant ()
repairStaleGitLocks r = do
lockfiles <- filter (not . isInfixOf "gc.pid")
. filter (".lock" `isSuffixOf`)
<$> (liftIO . dirContentsRecursiveSkipping (== dropTrailingPathSeparator annexDir)
=<< liftAnnex (fromRepo Git.localGitDir))
checkStaleLocks lockfiles
checkStaleLocks :: [FilePath] -> Assistant ()
checkStaleLocks lockfiles = go =<< getsizes
<$> liftIO (findgitfiles r)
repairStaleLocks lockfiles
where
findgitfiles = dirContentsRecursiveSkipping (== dropTrailingPathSeparator annexDir) . Git.localGitDir
repairStaleLocks :: [FilePath] -> Assistant ()
repairStaleLocks lockfiles = go =<< getsizes
where
getsize lf = catchMaybeIO $
(\s -> (lf, fileSize s)) <$> getFileStatus lf

View file

@ -41,6 +41,7 @@ handleRemoteProblem :: UrlRenderer -> Remote -> Assistant ()
handleRemoteProblem urlrenderer rmt
| Git.repoIsLocal r && not (Git.repoIsLocalUnknown r) =
whenM (liftIO $ checkAvailable True rmt) $ do
repairStaleGitLocks r
fsckresults <- showFscking urlrenderer (Just $ Remote.name rmt) $ tryNonAsync $
Git.Fsck.findBroken True r
whenM (repairWhenNecessary urlrenderer (Remote.uuid rmt) (Just rmt) fsckresults) $
@ -50,4 +51,5 @@ handleRemoteProblem urlrenderer rmt
r = Remote.repo rmt
handleLocalRepoProblem :: UrlRenderer -> Assistant ()
handleLocalRepoProblem urlrenderer = error "TODO"
handleLocalRepoProblem urlrenderer = do
repairStaleGitLocks =<< liftAnnex gitRepo

View file

@ -33,7 +33,7 @@ import Data.Time.Clock.POSIX
- being nonresponsive.) -}
sanityCheckerStartupThread :: Maybe Duration -> NamedThread
sanityCheckerStartupThread startupdelay = namedThreadUnchecked "SanityCheckerStartup" $ do
checkStaleGitLocks
repairStaleGitLocks =<< liftAnnex gitRepo
liftIO $ maybe noop (threadDelaySeconds . Seconds . fromIntegral . durationSeconds) startupdelay