automatically launch git repository repair
Added a RemoteChecker thread, that waits for problems to be reported with remotes, and checks if their git repository is in need of repair. Currently, only failures to sync with the remote cause a problem to be reported. This seems enough, but we'll see. Plugging in a removable drive with a repository on it that is corrupted does automatically repair the repository, as long as the corruption causes git push or git pull to fail. Some types of corruption do not, eg missing/corrupt objects for blobs that git push doesn't need to look at. So, this is not really a replacement for scheduled git repository fscking. But it does make the assistant more robust. This commit is sponsored by Fernando Jimenez.
This commit is contained in:
parent
3c08fee76b
commit
a7821c0581
11 changed files with 129 additions and 39 deletions
46
Assistant/Threads/RemoteChecker.hs
Normal file
46
Assistant/Threads/RemoteChecker.hs
Normal file
|
@ -0,0 +1,46 @@
|
|||
{- git-annex assistant remote checker thread
|
||||
-
|
||||
- Copyright 2013 Joey Hess <joey@kitenet.net>
|
||||
-
|
||||
- Licensed under the GNU GPL version 3 or higher.
|
||||
-}
|
||||
|
||||
module Assistant.Threads.RemoteChecker (
|
||||
remoteCheckerThread
|
||||
) where
|
||||
|
||||
import Assistant.Common
|
||||
import Utility.ThreadScheduler
|
||||
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 Assistant.RemoteProblem
|
||||
import Assistant.Sync
|
||||
|
||||
import Data.Function
|
||||
|
||||
{- Waits for problems with remotes, and tries to fsck the remote and repair
|
||||
- the problem. -}
|
||||
remoteCheckerThread :: UrlRenderer -> NamedThread
|
||||
remoteCheckerThread urlrenderer = namedThread "RemoteChecker" $ forever $ do
|
||||
mapM_ (handleProblem urlrenderer)
|
||||
=<< liftIO . filterM (checkAvailable True)
|
||||
=<< nubremotes <$> getRemoteProblems
|
||||
liftIO $ threadDelaySeconds (Seconds 60)
|
||||
where
|
||||
nubremotes = nubBy ((==) `on` Remote.uuid)
|
||||
|
||||
handleProblem :: UrlRenderer -> Remote -> Assistant ()
|
||||
handleProblem urlrenderer rmt
|
||||
| Git.repoIsLocal r && not (Git.repoIsLocalUnknown r) = do
|
||||
fsckresults <- showFscking urlrenderer (Just $ Remote.name rmt) $ tryNonAsync $
|
||||
Git.Fsck.findBroken True r
|
||||
whenM (repairWhenNecessary urlrenderer (Remote.uuid rmt) (Just rmt) fsckresults) $
|
||||
syncRemote rmt
|
||||
| otherwise = noop
|
||||
where
|
||||
r = Remote.repo rmt
|
Loading…
Add table
Add a link
Reference in a new issue