aboutsummaryrefslogtreecommitdiff
path: root/Assistant/Threads/Upgrader.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-11-24 13:20:58 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-11-24 13:20:58 -0400
commit42b427f6fc711254ac9ff1f047568f3584a406f7 (patch)
treecb464fe3207a87f36d00892558659b1322dca913 /Assistant/Threads/Upgrader.hs
parent3a1ba10f775df8bf742a10cf8c8a8672b63f78b8 (diff)
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.
Diffstat (limited to 'Assistant/Threads/Upgrader.hs')
-rw-r--r--Assistant/Threads/Upgrader.hs26
1 files changed, 17 insertions, 9 deletions
diff --git a/Assistant/Threads/Upgrader.hs b/Assistant/Threads/Upgrader.hs
index 7a95a711d..95796be22 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