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
|
|
|
-
|
|
|
|
- Licensed under the GNU GPL version 3 or higher.
|
|
|
|
-}
|
|
|
|
|
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
|
2016-10-05 20:23:09 +00:00
|
|
|
go (Just v) | v >= destversion = return True
|
2013-08-04 17:07:55 +00:00
|
|
|
#ifndef mingw32_HOST_OS
|
2018-10-25 21:23:53 +00:00
|
|
|
go (Just (RepoVersion 0)) = Upgrade.V0.upgrade
|
|
|
|
go (Just (RepoVersion 1)) = Upgrade.V1.upgrade
|
2013-05-11 20:03:00 +00:00
|
|
|
#else
|
2018-10-25 21:23:53 +00:00
|
|
|
go (Just (RepoVersion 0)) = giveup "upgrade from V0 on Windows not supported"
|
|
|
|
go (Just (RepoVersion 1)) = giveup "upgrade from V1 on Windows not supported"
|
2013-05-11 20:03:00 +00:00
|
|
|
#endif
|
2018-10-25 21:23:53 +00:00
|
|
|
go (Just (RepoVersion 2)) = Upgrade.V2.upgrade
|
|
|
|
go (Just (RepoVersion 3)) = Upgrade.V3.upgrade automatic
|
|
|
|
go (Just (RepoVersion 4)) = Upgrade.V4.upgrade automatic
|
|
|
|
go (Just (RepoVersion 5)) = Upgrade.V5.upgrade automatic
|
|
|
|
go (Just (RepoVersion 6)) = Upgrade.V6.upgrade automatic
|
2012-11-11 04:51:07 +00:00
|
|
|
go _ = return True
|