diff options
author | Joey Hess <joey@kitenet.net> | 2013-10-22 16:02:52 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-10-22 16:02:52 -0400 |
commit | 3ca53d2779c695ebb6cbdd210fea2167562637ff (patch) | |
tree | 9fc7fe17043d36ec22b62039de7e2ef16bc2edb2 /Assistant | |
parent | de5fdb11a238249c1b9b89a29277777a09f1cdb9 (diff) |
add git fsck to cronner, and UI for repository repair (not yet wired up)
Diffstat (limited to 'Assistant')
-rw-r--r-- | Assistant/Alert.hs | 19 | ||||
-rw-r--r-- | Assistant/Threads/Cronner.hs | 35 | ||||
-rw-r--r-- | Assistant/Threads/WebApp.hs | 1 |
3 files changed, 43 insertions, 12 deletions
diff --git a/Assistant/Alert.hs b/Assistant/Alert.hs index 3455d0563..4e6dab033 100644 --- a/Assistant/Alert.hs +++ b/Assistant/Alert.hs @@ -79,6 +79,22 @@ warningAlert name msg = Alert , alertButton = Nothing } +errorAlert :: String -> AlertButton -> Alert +errorAlert msg button = Alert + { alertClass = Error + , alertHeader = Just $ tenseWords ["error"] + , alertMessageRender = renderData + , alertData = [UnTensed $ T.pack msg] + , alertCounter = 0 + , alertBlockDisplay = True + , alertClosable = True + , alertPriority = Pinned + , alertIcon = Just ErrorIcon + , alertCombiner = Nothing + , alertName = Nothing + , alertButton = Just button + } + activityAlert :: Maybe TenseText -> [TenseChunk] -> Alert activityAlert header dat = baseActivityAlert { alertHeader = header @@ -158,6 +174,9 @@ fsckAlert button n = baseActivityAlert , alertButton = Just button } +brokenRepositoryAlert :: AlertButton -> Alert +brokenRepositoryAlert = errorAlert "Your repository needs repairs." + pairingAlert :: AlertButton -> Alert pairingAlert button = baseActivityAlert { alertData = [ UnTensed "Pairing in progress" ] diff --git a/Assistant/Threads/Cronner.hs b/Assistant/Threads/Cronner.hs index 8eb3d472e..786044b20 100644 --- a/Assistant/Threads/Cronner.hs +++ b/Assistant/Threads/Cronner.hs @@ -32,6 +32,8 @@ import Remote import Assistant.WebApp.Types #endif import Git.Remote (RemoteName) +import qualified Git.Fsck +import Logs.FsckResults import Control.Concurrent.Async import Control.Concurrent.MVar @@ -182,15 +184,24 @@ runActivity urlrenderer activity nowt = do runActivity' :: UrlRenderer -> ScheduledActivity -> Assistant () runActivity' urlrenderer (ScheduledSelfFsck _ d) = do program <- liftIO $ readProgramFile - void $ runFsck urlrenderer Nothing $ - batchCommand program (Param "fsck" : fsckParams d) + g <- liftAnnex gitRepo + fsckresults <- showFscking urlrenderer Nothing $ tryNonAsync $ do + r <- Git.Fsck.findBroken True g + void $ batchCommand program (Param "fsck" : annexFsckParams d) + return r + when (Git.Fsck.foundBroken fsckresults) $ do + u <- liftAnnex getUUID + liftAnnex $ writeFsckResults u fsckresults + button <- mkAlertButton True (T.pack "Repair") urlrenderer $ + RepairRepositoryR u + void $ addAlert $ brokenRepositoryAlert button mapM_ reget =<< liftAnnex (dirKeys gitAnnexBadDir) where reget k = queueTransfers "fsck found bad file; redownloading" Next k Nothing Download runActivity' urlrenderer (ScheduledRemoteFsck u s d) = go =<< liftAnnex (remoteFromUUID u) where go (Just r) = void $ case Remote.remoteFsck r of - Nothing -> void $ runFsck urlrenderer (Just $ Remote.name r) $ do + Nothing -> void $ showFscking urlrenderer (Just $ Remote.name r) $ tryNonAsync $ do program <- readProgramFile batchCommand program $ [ Param "fsck" @@ -198,28 +209,28 @@ runActivity' urlrenderer (ScheduledRemoteFsck u s d) = go =<< liftAnnex (remoteF , Param "--fast" , Param "--from" , Param $ Remote.name r - ] ++ fsckParams d + ] ++ annexFsckParams d Just mkfscker -> {- Note that having mkfsker return an IO action - avoids running a long duration fsck in the - Annex monad. -} - void . runFsck urlrenderer (Just $ Remote.name r) - =<< liftAnnex (mkfscker (fsckParams d)) + void . showFscking urlrenderer (Just $ Remote.name r) . tryNonAsync + =<< liftAnnex (mkfscker (annexFsckParams d)) go Nothing = debug ["skipping remote fsck of uuid without a configured remote", fromUUID u, fromSchedule s] -runFsck :: UrlRenderer -> Maybe RemoteName -> IO Bool -> Assistant Bool -runFsck urlrenderer remotename a = do +showFscking :: UrlRenderer -> Maybe RemoteName -> IO (Either E.SomeException a) -> Assistant a +showFscking urlrenderer remotename a = do #ifdef WITH_WEBAPP button <- mkAlertButton False (T.pack "Configure") urlrenderer ConfigFsckR - r <- alertDuring (fsckAlert button remotename) $ liftIO $ do - E.try a :: IO (Either E.SomeException Bool) + r <- alertDuring (fsckAlert button remotename) $ + liftIO a either (liftIO . E.throwIO) return r #else a #endif -fsckParams :: Duration -> [CommandParam] -fsckParams d = +annexFsckParams :: Duration -> [CommandParam] +annexFsckParams d = [ Param "--incremental-schedule=1d" , Param $ "--time-limit=" ++ fromDuration d ] diff --git a/Assistant/Threads/WebApp.hs b/Assistant/Threads/WebApp.hs index 2c5b1dbd2..a5f4f4201 100644 --- a/Assistant/Threads/WebApp.hs +++ b/Assistant/Threads/WebApp.hs @@ -33,6 +33,7 @@ import Assistant.WebApp.Configurators.Fsck import Assistant.WebApp.Documentation import Assistant.WebApp.Control import Assistant.WebApp.OtherRepos +import Assistant.WebApp.Repair import Assistant.Types.ThreadedMonad import Utility.WebApp import Utility.Tmp |