git-annex/Upgrade.hs

59 lines
1.5 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
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
2010-11-14 18:44:24 +00:00
checkUpgrade :: Version -> Annex ()
2013-11-17 18:58:35 +00:00
checkUpgrade = maybe noop error <=< needsUpgrade
needsUpgrade :: Version -> Annex (Maybe String)
needsUpgrade v
| v `elem` supportedVersions = ok
2013-11-17 18:58:35 +00:00
| v `elem` autoUpgradeableVersions = ifM (upgrade True)
( ok
, err "Automatic upgrade failed!"
)
| v `elem` upgradableVersions = err "Upgrade this repository: git-annex upgrade"
| otherwise = err "Upgrade git-annex."
where
2013-11-17 18:58:35 +00:00
err msg = return $ Just $ "Repository version " ++ v ++
" is not supported. " ++ msg
2013-11-17 18:58:35 +00:00
ok = return Nothing
upgrade :: Bool -> Annex Bool
upgrade automatic = do
upgraded <- go =<< getVersion
when upgraded $
setVersion latestVersion
return upgraded
2012-11-11 04:51:07 +00:00
where
2013-08-04 17:07:55 +00:00
#ifndef mingw32_HOST_OS
2012-11-11 04:51:07 +00:00
go (Just "0") = Upgrade.V0.upgrade
go (Just "1") = Upgrade.V1.upgrade
#else
go (Just "0") = error "upgrade from v0 on Windows not supported"
go (Just "1") = error "upgrade from v1 on Windows not supported"
#endif
2012-11-11 04:51:07 +00:00
go (Just "2") = Upgrade.V2.upgrade
go (Just "3") = Upgrade.V3.upgrade automatic
go (Just "4") = Upgrade.V4.upgrade automatic
go (Just "5") = Upgrade.V5.upgrade automatic
2012-11-11 04:51:07 +00:00
go _ = return True