queue and start download of git-annex from web, using git-annex, when upgrade is started

This commit is contained in:
Joey Hess 2013-11-23 17:21:04 -04:00
parent 6802123f7d
commit 32acf908bb
4 changed files with 50 additions and 20 deletions

View file

@ -5,7 +5,7 @@
- Licensed under the GNU AGPL version 3 or higher.
-}
{-# LANGUAGE QuasiQuotes, TemplateHaskell, OverloadedStrings #-}
{-# LANGUAGE CPP, QuasiQuotes, TemplateHaskell, OverloadedStrings #-}
module Assistant.WebApp.Configurators.Upgrade where
@ -13,17 +13,50 @@ import Assistant.WebApp.Common
import Types.Distribution
import Assistant.Upgrade
import Assistant.Restart
import Utility.HumanTime
import Assistant.DaemonStatus
import Config
import Assistant.TransferQueue
import Assistant.TransferSlots
import Logs.Transfer
import Logs.Web
import Remote
import Data.Time.Clock
import qualified Data.Map as M
{- On Android, just redirect the user's web browser to the apk file
- to download it.
-
- Otherwise, register a hook action that will be called once the key
- is downloaded, and start downloading the key.
- -}
getConfigStartUpgradeR :: GitAnnexDistribution -> Handler Html
getConfigStartUpgradeR d = page "Upgrade git-annex" (Just Configuration) $ do
now <- liftIO getCurrentTime
let upgradeage = Duration $ floor $
now `diffUTCTime` distributionReleasedate d
$(widgetFile "configurators/upgrade/start")
getConfigStartUpgradeR d = do
#ifdef __ANDROID__
redirect (distributionUrl d)
#else
liftAssistant $ do
let k = distributionKey d
let u = distributionUrl d
liftAnnex $ setUrlPresent k u
hook <- asIO1 $ downloadComplete d
modifyDaemonStatus_ $ \status -> status
{ transferHook = M.insert k hook (transferHook status) }
let t = Transfer
{ transferDirection = Download
, transferUUID = webUUID
, transferKey = k
}
let f = takeFileName u ++ " (for upgrade)"
maybe noop (queueTransfer "upgrade" Next (Just f) t)
=<< liftAnnex (remoteFromUUID webUUID)
startTransfer t
redirect DashboardR
#endif
downloadComplete :: GitAnnexDistribution -> Transfer -> Assistant ()
downloadComplete d t = do
error "TODO"
liftAnnex $ setUrlMissing (distributionKey d) (distributionUrl d)
{- Finish upgrade by starting the new assistant in the same repository this
- one is running in, and redirecting to it. -}