From 5ff5d0a854c10e68f67d584505f5fc887fa1600e Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 24 Nov 2013 14:04:03 -0400 Subject: [PATCH] cleanup on failed upgrade --- Assistant/Alert.hs | 12 ++++++++---- Assistant/Repair.hs | 2 +- Assistant/Upgrade.hs | 14 +++++++++++--- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/Assistant/Alert.hs b/Assistant/Alert.hs index dc321f0970..c767d429d9 100644 --- a/Assistant/Alert.hs +++ b/Assistant/Alert.hs @@ -82,8 +82,8 @@ warningAlert name msg = Alert , alertButtons = [] } -errorAlert :: String -> AlertButton -> Alert -errorAlert msg button = Alert +errorAlert :: String -> [AlertButton] -> Alert +errorAlert msg buttons = Alert { alertClass = Error , alertHeader = Nothing , alertMessageRender = renderData @@ -95,7 +95,7 @@ errorAlert msg button = Alert , alertIcon = Just ErrorIcon , alertCombiner = Nothing , alertName = Nothing - , alertButtons = [button] + , alertButtons = buttons } activityAlert :: Maybe TenseText -> [TenseChunk] -> Alert @@ -256,7 +256,11 @@ upgradeFinishedAlert button version = baseUpgradeAlert (maybe [] (:[]) button) $ fromString $ "Finished upgrading git-annex to version " ++ version -brokenRepositoryAlert :: AlertButton -> Alert +upgradeFailedAlert :: String -> Alert +upgradeFailedAlert msg = (errorAlert msg []) + { alertHeader = Just $ fromString "Upgrade failed." } + +brokenRepositoryAlert :: [AlertButton] -> Alert brokenRepositoryAlert = errorAlert "Serious problems have been detected with your repository. This needs your immediate attention!" repairingAlert :: String -> Alert diff --git a/Assistant/Repair.hs b/Assistant/Repair.hs index 1f54451251..1369d31986 100644 --- a/Assistant/Repair.hs +++ b/Assistant/Repair.hs @@ -46,7 +46,7 @@ repairWhenNecessary urlrenderer u mrmt fsckresults unless ok $ do button <- mkAlertButton True (T.pack "Click Here") urlrenderer $ RepairRepositoryR u - void $ addAlert $ brokenRepositoryAlert button + void $ addAlert $ brokenRepositoryAlert [button] #endif return ok | otherwise = return False diff --git a/Assistant/Upgrade.hs b/Assistant/Upgrade.hs index bbf293e69d..70c5215195 100644 --- a/Assistant/Upgrade.hs +++ b/Assistant/Upgrade.hs @@ -96,8 +96,7 @@ distributionDownloadComplete :: GitAnnexDistribution -> Assistant () -> Transfer distributionDownloadComplete d cleanup t | transferDirection t == Download = do debug ["finished downloading git-annex distribution"] - maybe cleanup (upgradeToDistribution d cleanup) - =<< liftAnnex (withObjectLoc k fsckit (getM fsckit)) + maybe cleanup go =<< liftAnnex (withObjectLoc k fsckit (getM fsckit)) | otherwise = cleanup where k = distributionKey d @@ -109,6 +108,13 @@ distributionDownloadComplete d cleanup t ( return $ Just f , return Nothing ) + go f = do + ua <- asIO $ upgradeToDistribution d cleanup f + fa <- asIO1 failedupgrade + liftIO $ ua `catchNonAsync` fa + failedupgrade e = do + cleanup + void $ addAlert $ upgradeFailedAlert $ show e {- The upgrade method varies by OS. - @@ -144,9 +150,11 @@ upgradeToDistribution d cleanup f = do - into place. -} unpack = liftIO $ do olddir <- parentDir <$> readProgramFile + when (null olddir) $ + error $ "Cannot find old distribution bundle; not upgrading." newdir <- newVersionLocation d olddir "git-annex.linux." whenM (doesDirectoryExist newdir) $ - error $ "upgrade destination directory " ++ newdir ++ "already exists; not overwriting" + error $ "Upgrade destination directory " ++ newdir ++ "already exists; not overwriting." withTmpDirIn (parentDir newdir) "git-annex.upgrade" $ \tmpdir -> do let tarball = tmpdir "tar" -- Cannot rely on filename extension, and this also