2010-11-14 18:44:24 +00:00
|
|
|
{- git-annex upgrade support
|
|
|
|
-
|
2019-09-01 17:29:55 +00:00
|
|
|
- Copyright 2010-2019 Joey Hess <id@joeyh.name>
|
2010-11-14 18:44:24 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2010-11-14 18:44:24 +00:00
|
|
|
-}
|
|
|
|
|
2013-05-11 20:03:00 +00:00
|
|
|
{-# LANGUAGE CPP #-}
|
|
|
|
|
2010-11-14 18:44:24 +00:00
|
|
|
module Upgrade where
|
|
|
|
|
2016-01-20 20:36:33 +00:00
|
|
|
import Annex.Common
|
2019-09-01 17:29:55 +00:00
|
|
|
import qualified Annex
|
|
|
|
import qualified Git
|
2011-10-04 04:40:47 +00:00
|
|
|
import Annex.Version
|
2018-10-25 21:23:53 +00:00
|
|
|
import Types.RepoVersion
|
2013-08-04 17:07:55 +00:00
|
|
|
#ifndef mingw32_HOST_OS
|
2011-03-16 05:23:20 +00:00
|
|
|
import qualified Upgrade.V0
|
|
|
|
import qualified Upgrade.V1
|
2013-05-11 20:03:00 +00:00
|
|
|
#endif
|
2011-06-22 21:51:48 +00:00
|
|
|
import qualified Upgrade.V2
|
2013-12-29 17:06:23 +00:00
|
|
|
import qualified Upgrade.V3
|
2013-11-05 20:42:59 +00:00
|
|
|
import qualified Upgrade.V4
|
2015-12-04 20:14:48 +00:00
|
|
|
import qualified Upgrade.V5
|
2018-10-25 21:23:53 +00:00
|
|
|
import qualified Upgrade.V6
|
2010-11-14 18:44:24 +00:00
|
|
|
|
2018-10-25 22:33:34 +00:00
|
|
|
import qualified Data.Map as M
|
|
|
|
|
2018-10-25 21:23:53 +00:00
|
|
|
checkUpgrade :: RepoVersion -> Annex ()
|
2016-11-16 01:29:54 +00:00
|
|
|
checkUpgrade = maybe noop giveup <=< needsUpgrade
|
2013-11-17 18:58:35 +00:00
|
|
|
|
2018-10-25 21:23:53 +00:00
|
|
|
needsUpgrade :: RepoVersion -> Annex (Maybe String)
|
2013-11-17 18:58:35 +00:00
|
|
|
needsUpgrade v
|
2015-12-04 20:14:48 +00:00
|
|
|
| v `elem` supportedVersions = ok
|
2018-10-25 22:33:34 +00:00
|
|
|
| otherwise = case M.lookup v autoUpgradeableVersions of
|
|
|
|
Nothing
|
|
|
|
| v `elem` upgradableVersions ->
|
|
|
|
err "Upgrade this repository: git-annex upgrade"
|
|
|
|
| otherwise ->
|
|
|
|
err "Upgrade git-annex."
|
2019-09-01 17:29:55 +00:00
|
|
|
Just newv -> ifM (annexAutoUpgradeRepository <$> Annex.getGitConfig)
|
|
|
|
( tryNonAsync (upgrade True newv) >>= \case
|
|
|
|
Right True -> ok
|
2019-09-01 20:42:49 +00:00
|
|
|
Right False -> err "Automatic upgrade failed!"
|
|
|
|
Left ex -> err $ "Automatic upgrade exception! " ++ show ex
|
2019-09-01 17:29:55 +00:00
|
|
|
, err "Automatic upgrade is disabled by annex.autoupgraderepository configuration. To upgrade this repository: git-annex upgrade"
|
2018-10-25 22:33:34 +00:00
|
|
|
)
|
2013-11-05 20:42:59 +00:00
|
|
|
where
|
2019-09-01 17:29:55 +00:00
|
|
|
err msg = do
|
|
|
|
g <- Annex.gitRepo
|
2019-12-09 17:49:05 +00:00
|
|
|
p <- liftIO $ absPath $ fromRawFilePath $ Git.repoPath g
|
2019-09-01 17:29:55 +00:00
|
|
|
return $ Just $ unwords
|
|
|
|
[ "Repository", p
|
|
|
|
, "is at unsupported version"
|
|
|
|
, show (fromRepoVersion v) ++ "."
|
|
|
|
, msg
|
|
|
|
]
|
2013-11-17 18:58:35 +00:00
|
|
|
ok = return Nothing
|
2013-11-05 20:42:59 +00:00
|
|
|
|
2018-10-25 21:23:53 +00:00
|
|
|
upgrade :: Bool -> RepoVersion -> Annex Bool
|
2016-10-05 20:23:09 +00:00
|
|
|
upgrade automatic destversion = do
|
2013-11-26 16:54:50 +00:00
|
|
|
upgraded <- go =<< getVersion
|
|
|
|
when upgraded $
|
2016-10-05 20:23:09 +00:00
|
|
|
setVersion destversion
|
2013-11-26 16:54:50 +00:00
|
|
|
return upgraded
|
2012-11-11 04:51:07 +00:00
|
|
|
where
|
2018-10-26 18:29:52 +00:00
|
|
|
go (Just v)
|
|
|
|
| v >= destversion = return True
|
|
|
|
| otherwise = ifM (up v)
|
|
|
|
( go (Just (RepoVersion (fromRepoVersion v + 1)))
|
|
|
|
, return False
|
|
|
|
)
|
|
|
|
go _ = return True
|
|
|
|
|
2013-08-04 17:07:55 +00:00
|
|
|
#ifndef mingw32_HOST_OS
|
2018-10-26 18:29:52 +00:00
|
|
|
up (RepoVersion 0) = Upgrade.V0.upgrade
|
|
|
|
up (RepoVersion 1) = Upgrade.V1.upgrade
|
2013-05-11 20:03:00 +00:00
|
|
|
#else
|
2018-10-26 18:29:52 +00:00
|
|
|
up (RepoVersion 0) = giveup "upgrade from v0 on Windows not supported"
|
|
|
|
up (RepoVersion 1) = giveup "upgrade from v1 on Windows not supported"
|
2013-05-11 20:03:00 +00:00
|
|
|
#endif
|
2018-10-26 18:29:52 +00:00
|
|
|
up (RepoVersion 2) = Upgrade.V2.upgrade
|
|
|
|
up (RepoVersion 3) = Upgrade.V3.upgrade automatic
|
|
|
|
up (RepoVersion 4) = Upgrade.V4.upgrade automatic
|
|
|
|
up (RepoVersion 5) = Upgrade.V5.upgrade automatic
|
|
|
|
up (RepoVersion 6) = Upgrade.V6.upgrade automatic
|
|
|
|
up _ = return True
|