2010-11-14 18:44:24 +00:00
|
|
|
{- git-annex upgrade support
|
|
|
|
-
|
2020-03-09 20:47:57 +00:00
|
|
|
- Copyright 2010-2020 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
|
2020-03-09 20:47:57 +00:00
|
|
|
import Config
|
|
|
|
import Config.Files
|
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
|
2019-11-06 19:37:18 +00:00
|
|
|
import qualified Upgrade.V7
|
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
|
2020-03-09 20:47:57 +00:00
|
|
|
when upgraded
|
|
|
|
postupgrade
|
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
|
2020-03-09 20:47:57 +00:00
|
|
|
| otherwise = ifM upgradingRemote
|
|
|
|
( upgraderemote
|
|
|
|
, ifM (up v)
|
|
|
|
( go (Just (RepoVersion (fromRepoVersion v + 1)))
|
|
|
|
, return False
|
|
|
|
)
|
2018-10-26 18:29:52 +00:00
|
|
|
)
|
|
|
|
go _ = return True
|
|
|
|
|
2020-03-09 20:47:57 +00:00
|
|
|
postupgrade = ifM upgradingRemote
|
|
|
|
( reloadConfig
|
|
|
|
, setVersion destversion
|
|
|
|
)
|
|
|
|
|
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
|
2019-11-06 19:37:18 +00:00
|
|
|
up (RepoVersion 7) = Upgrade.V7.upgrade automatic
|
2018-10-26 18:29:52 +00:00
|
|
|
up _ = return True
|
2020-03-09 20:47:57 +00:00
|
|
|
|
|
|
|
-- Upgrade local remotes by running git-annex upgrade in them.
|
|
|
|
-- This avoids complicating the upgrade code by needing to handle
|
|
|
|
-- upgrading a git repo other than the current repo.
|
|
|
|
upgraderemote = do
|
|
|
|
rp <- fromRawFilePath <$> fromRepo Git.repoPath
|
|
|
|
cmd <- liftIO readProgramFile
|
|
|
|
liftIO $ boolSystem' cmd
|
|
|
|
[ Param "upgrade"
|
|
|
|
, Param "--quiet"
|
|
|
|
, Param "--autoonly"
|
|
|
|
]
|
|
|
|
(\p -> p { cwd = Just rp })
|
|
|
|
|
|
|
|
upgradingRemote :: Annex Bool
|
|
|
|
upgradingRemote = isJust <$> fromRepo Git.remoteName
|