2013-10-29 18:22:56 +00:00
|
|
|
{- git-annex assistant thread to handle fixing problems with repositories
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2013 Joey Hess <id@joeyh.name>
|
2013-10-29 18:22:56 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2013-10-29 18:22:56 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Assistant.Threads.ProblemFixer (
|
|
|
|
problemFixerThread
|
|
|
|
) where
|
|
|
|
|
|
|
|
import Assistant.Common
|
|
|
|
import Assistant.Types.RepoProblem
|
|
|
|
import Assistant.RepoProblem
|
|
|
|
import Assistant.Types.UrlRenderer
|
|
|
|
import Assistant.Alert
|
|
|
|
import Remote
|
|
|
|
import qualified Types.Remote as Remote
|
|
|
|
import qualified Git.Fsck
|
|
|
|
import Assistant.Repair
|
|
|
|
import qualified Git
|
|
|
|
import Annex.UUID
|
|
|
|
import Utility.ThreadScheduler
|
|
|
|
|
|
|
|
{- Waits for problems with a repo, and tries to fsck the repo and repair
|
|
|
|
- the problem. -}
|
|
|
|
problemFixerThread :: UrlRenderer -> NamedThread
|
|
|
|
problemFixerThread urlrenderer = namedThread "ProblemFixer" $
|
|
|
|
go =<< getRepoProblems
|
|
|
|
where
|
|
|
|
go problems = do
|
|
|
|
mapM_ (handleProblem urlrenderer) problems
|
|
|
|
liftIO $ threadDelaySeconds (Seconds 60)
|
|
|
|
-- Problems may have been re-reported while they were being
|
|
|
|
-- fixed, so ignore those. If a new unique problem happened
|
|
|
|
-- 60 seconds after the last was fixed, we're unlikely
|
|
|
|
-- to do much good anyway.
|
|
|
|
go =<< filter (\p -> not (any (sameRepoProblem p) problems))
|
|
|
|
<$> getRepoProblems
|
|
|
|
|
|
|
|
handleProblem :: UrlRenderer -> RepoProblem -> Assistant ()
|
|
|
|
handleProblem urlrenderer repoproblem = do
|
|
|
|
fixed <- ifM ((==) (problemUUID repoproblem) <$> liftAnnex getUUID)
|
|
|
|
( handleLocalRepoProblem urlrenderer
|
|
|
|
, maybe (return False) (handleRemoteProblem urlrenderer)
|
|
|
|
=<< liftAnnex (remoteFromUUID $ problemUUID repoproblem)
|
|
|
|
)
|
|
|
|
when fixed $
|
|
|
|
liftIO $ afterFix repoproblem
|
|
|
|
|
|
|
|
handleRemoteProblem :: UrlRenderer -> Remote -> Assistant Bool
|
2018-06-04 18:31:55 +00:00
|
|
|
handleRemoteProblem urlrenderer rmt = do
|
|
|
|
repo <- liftAnnex $ Remote.getRepo rmt
|
|
|
|
handleRemoteProblem' repo urlrenderer rmt
|
|
|
|
|
|
|
|
handleRemoteProblem' :: Git.Repo -> UrlRenderer -> Remote -> Assistant Bool
|
|
|
|
handleRemoteProblem' repo urlrenderer rmt
|
|
|
|
| Git.repoIsLocal repo && not (Git.repoIsLocalUnknown repo) =
|
2023-08-16 19:57:30 +00:00
|
|
|
ifM (liftAnnex $ checkAvailable True rmt)
|
2013-10-29 18:22:56 +00:00
|
|
|
( do
|
2018-06-04 18:31:55 +00:00
|
|
|
fixedlocks <- repairStaleGitLocks repo
|
2013-10-29 20:48:06 +00:00
|
|
|
fsckresults <- showFscking urlrenderer (Just rmt) $ tryNonAsync $
|
2021-06-30 21:57:49 +00:00
|
|
|
Git.Fsck.findBroken True True repo
|
2013-10-29 18:22:56 +00:00
|
|
|
repaired <- repairWhenNecessary urlrenderer (Remote.uuid rmt) (Just rmt) fsckresults
|
|
|
|
return $ fixedlocks || repaired
|
|
|
|
, return False
|
|
|
|
)
|
|
|
|
| otherwise = return False
|
|
|
|
|
|
|
|
{- This is not yet used, and should probably do a fsck. -}
|
|
|
|
handleLocalRepoProblem :: UrlRenderer -> Assistant Bool
|
2013-10-29 20:48:06 +00:00
|
|
|
handleLocalRepoProblem _urlrenderer = do
|
2013-10-29 18:22:56 +00:00
|
|
|
repairStaleGitLocks =<< liftAnnex gitRepo
|