2010-11-14 18:44:24 +00:00
|
|
|
{- git-annex upgrade support
|
|
|
|
-
|
2015-01-21 16:50:09 +00:00
|
|
|
- Copyright 2010, 2013 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
|
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."
|
|
|
|
Just newv -> ifM (upgrade True newv)
|
|
|
|
( ok
|
|
|
|
, err "Automatic upgrade failed!"
|
|
|
|
)
|
2013-11-05 20:42:59 +00:00
|
|
|
where
|
2018-10-25 21:23:53 +00:00
|
|
|
err msg = return $ Just $ "Repository version " ++
|
|
|
|
show (fromRepoVersion v) ++
|
2013-11-05 20:42:59 +00:00
|
|
|
" is not supported. " ++ 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
|