From 6165284e39ddcded27a7dd28d2e441f1c2939dad Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 24 Nov 2013 13:20:58 -0400 Subject: [PATCH] add support for fully automatic upgrades The Upgrader avoids checking for upgrades on startup when it was just upgraded. This avoids an upgrade loop if something goes wrong. One example of something going wrong would be if the upgrade info file and the distribution file get out of sync (or the distribution file is cached in a proxy), so it thinks it has upgraded to a new version, but has really not. --- Assistant.hs | 2 +- Assistant/Threads/UpgradeWatcher.hs | 8 ++++---- Assistant/Threads/Upgrader.hs | 26 +++++++++++++++++--------- doc/assistant/upgradecomplete.png | Bin 0 -> 4817 bytes 4 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 doc/assistant/upgradecomplete.png diff --git a/Assistant.hs b/Assistant.hs index 6b6b98ebc6..d4786f99ad 100644 --- a/Assistant.hs +++ b/Assistant.hs @@ -153,7 +153,7 @@ startDaemon assistant foreground startdelay cannotrun listenhost startbrowser = #endif , assist $ netWatcherThread , assist $ upgraderThread urlrenderer - , assist $ upgradWatcherThread urlrenderer + , assist $ upgradeWatcherThread urlrenderer , assist $ netWatcherFallbackThread , assist $ transferScannerThread urlrenderer , assist $ cronnerThread urlrenderer diff --git a/Assistant/Threads/UpgradeWatcher.hs b/Assistant/Threads/UpgradeWatcher.hs index c127e3b2fc..80b11e71a1 100644 --- a/Assistant/Threads/UpgradeWatcher.hs +++ b/Assistant/Threads/UpgradeWatcher.hs @@ -8,7 +8,7 @@ {-# LANGUAGE CPP #-} module Assistant.Threads.UpgradeWatcher ( - upgradWatcherThread + upgradeWatcherThread ) where import Assistant.Common @@ -30,9 +30,9 @@ import qualified Data.Text as T data WatcherState = InStartupScan | Started | Upgrading deriving (Eq) -upgradWatcherThread :: UrlRenderer -> NamedThread -upgradWatcherThread urlrenderer = namedThread "UpgradeWatcher" $ do - whenM (liftIO $ checkSuccessfulUpgrade) $ +upgradeWatcherThread :: UrlRenderer -> NamedThread +upgradeWatcherThread urlrenderer = namedThread "UpgradeWatcher" $ do + whenM (liftIO checkSuccessfulUpgrade) $ showSuccessfulUpgrade urlrenderer go =<< liftIO upgradeFlagFile where diff --git a/Assistant/Threads/Upgrader.hs b/Assistant/Threads/Upgrader.hs index 7a95a711d0..95796be226 100644 --- a/Assistant/Threads/Upgrader.hs +++ b/Assistant/Threads/Upgrader.hs @@ -12,6 +12,8 @@ module Assistant.Threads.Upgrader ( ) where import Assistant.Common +import Assistant.Upgrade + import Assistant.Types.UrlRenderer import Assistant.DaemonStatus import Assistant.Alert @@ -31,11 +33,14 @@ import Data.Time.Clock import qualified Data.Text as T upgraderThread :: UrlRenderer -> NamedThread -upgraderThread urlrenderer = namedThread "Upgrader" $ do - checkUpgrade urlrenderer +upgraderThread urlrenderer = namedThread "Upgrader" $ when (isJust Build.SysConfig.upgradelocation) $ do + {- Check for upgrade on startup, unless it was just + - upgraded. -} + unlessM (liftIO checkSuccessfulUpgrade) $ + checkUpgrade urlrenderer h <- liftIO . newNotificationHandle False . networkConnectedNotifier =<< getDaemonStatus - go h Nothing + go h =<< liftIO getCurrentTime where {- Wait for a network connection event. Then see if it's been - half a day since the last upgrade check. If so, proceed with @@ -47,10 +52,10 @@ upgraderThread urlrenderer = namedThread "Upgrader" $ do then go h lastchecked else do now <- liftIO getCurrentTime - if maybe True (\t -> diffUTCTime now t > halfday) lastchecked + if diffUTCTime now lastchecked > halfday then do checkUpgrade urlrenderer - go h =<< Just <$> liftIO getCurrentTime + go h =<< liftIO getCurrentTime else go h lastchecked halfday = 12 * 60 * 60 @@ -71,13 +76,16 @@ checkUpgrade urlrenderer = do else debug [ "No new version found." ] canUpgrade :: AlertPriority -> UrlRenderer -> GitAnnexDistribution -> Assistant () -canUpgrade urgency urlrenderer d = do +canUpgrade urgency urlrenderer d = ifM autoUpgradeEnabled + ( startDistributionDownload d + , do #ifdef WITH_WEBAPP - button <- mkAlertButton True (T.pack "Upgrade") urlrenderer (ConfigStartUpgradeR d) - void $ addAlert (canUpgradeAlert urgency button) + button <- mkAlertButton True (T.pack "Upgrade") urlrenderer (ConfigStartUpgradeR d) + void $ addAlert (canUpgradeAlert urgency button) #else - noop + noop #endif + ) getDistributionInfo :: Assistant (Maybe GitAnnexDistribution) getDistributionInfo = do diff --git a/doc/assistant/upgradecomplete.png b/doc/assistant/upgradecomplete.png new file mode 100644 index 0000000000000000000000000000000000000000..3f8c7f3c2b203e96c149dea3f4d8d31e94673939 GIT binary patch literal 4817 zcmZ{ocTm$y*T;XMNR=+V3P>jcQVdNHDT4GaO_1IMLXj>?RRj$n0SUbb5_)f;U#ike zs3IjGRS1Sq9`3#K%=`TF&d%uTI2XC(&!;HH+Qnjrvy6t8Vf zQiAK1;#nQ#^>)KvTSE=F`g`QG6~nGQWG^%={I28le@_sQ@tOJBNdnb+@`z-Sf|-_H z{s~z^CjijdXsM|f2hHzhc|z%D;Qd$Q!{%vs)o10p(rD9cQM0Xbk)5-;E}D@TkZB{)I(J{N!i7cRDqC}&mi4C5Z2o3NH+#L!7@5T;qciTch}{+ zp&(2cx<*xg+{6&=yQA{I_c5?G{7)9&8w>x*;va8xpIEdc%WB1&;AY4pgLjr{s@Dci zB$w>{Q;aqb*qWX6hWLbkp8n6E(WZ;=EBFM5;a0+%MhN;Mykqlo$n7;5y7(<)XYz#H%1UjbvY7%Ms!aS5w%#kWWtV=a!AM{@#;`!JlD%ZD$0^m?G7UEk5iMmNGH0 zw6rucWk6s(^`V(n)~*@SN&>DkJ%=sxg0*3DZatEqql!3R%0#}0S?_xKJ!bqmcaY97 zoL~~r9>xwZ`%NDGf-wT}%kms;rVm@*O&-;tXA(o0)mqP*W#i00eT08@S6K=#`#lNL z*yqb2XMxShN;9X`F^&58*T<^nV(U!-^?aWI7258*^o$LFd0Ke|?)wk#gVNidb8=#T8pu__7xp_!xBYah8jJ^=Y1E%jInu z@el9vFUmirchrpMyWZ}7xsiDz@=vhx(#*oQ8fwu&)J$LDsp}_2Wm3S)d$*NL0Eq5#$FBITK{2 z+GNqJe$}rBG+dmDVspyS>$q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