git-annex/Upgrade.hs

70 lines
1.9 KiB
Haskell
Raw Normal View History

2010-11-14 18:44:24 +00:00
{- git-annex upgrade support
-
- 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.
-}
{-# LANGUAGE CPP #-}
2010-11-14 18:44:24 +00:00
module Upgrade where
import Annex.Common
2011-10-04 04:40:47 +00:00
import Annex.Version
import Types.RepoVersion
2013-08-04 17:07:55 +00:00
#ifndef mingw32_HOST_OS
import qualified Upgrade.V0
import qualified Upgrade.V1
#endif
2011-06-22 21:51:48 +00:00
import qualified Upgrade.V2
import qualified Upgrade.V3
import qualified Upgrade.V4
import qualified Upgrade.V5
import qualified Upgrade.V6
2010-11-14 18:44:24 +00:00
import qualified Data.Map as M
checkUpgrade :: RepoVersion -> Annex ()
checkUpgrade = maybe noop giveup <=< needsUpgrade
2013-11-17 18:58:35 +00:00
needsUpgrade :: RepoVersion -> Annex (Maybe String)
2013-11-17 18:58:35 +00:00
needsUpgrade v
| v `elem` supportedVersions = ok
| 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!"
)
where
err msg = return $ Just $ "Repository version " ++
show (fromRepoVersion v) ++
" is not supported. " ++ msg
2013-11-17 18:58:35 +00:00
ok = return Nothing
upgrade :: Bool -> RepoVersion -> Annex Bool
upgrade automatic destversion = do
upgraded <- go =<< getVersion
when upgraded $
setVersion destversion
return upgraded
2012-11-11 04:51:07 +00:00
where
go (Just v) | v >= destversion = return True
2013-08-04 17:07:55 +00:00
#ifndef mingw32_HOST_OS
go (Just (RepoVersion 0)) = Upgrade.V0.upgrade
go (Just (RepoVersion 1)) = Upgrade.V1.upgrade
#else
go (Just (RepoVersion 0)) = giveup "upgrade from V0 on Windows not supported"
go (Just (RepoVersion 1)) = giveup "upgrade from V1 on Windows not supported"
#endif
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