2010-11-14 18:44:24 +00:00
|
|
|
{- git-annex upgrade support
|
|
|
|
-
|
|
|
|
- Copyright 2010 Joey Hess <joey@kitenet.net>
|
|
|
|
-
|
|
|
|
- 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
|
|
|
|
|
2011-10-05 20:02:51 +00:00
|
|
|
import Common.Annex
|
2011-10-04 04:40:47 +00:00
|
|
|
import Annex.Version
|
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-11-05 20:42:59 +00:00
|
|
|
import qualified Upgrade.V4
|
2010-11-14 18:44:24 +00:00
|
|
|
|
2013-11-05 20:42:59 +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
|
|
|
|
| v `elem` autoUpgradeableVersions = ifM (upgrade True)
|
|
|
|
( ok
|
|
|
|
, err "Automatic upgrade failed!"
|
|
|
|
)
|
2013-11-05 20:42:59 +00:00
|
|
|
| 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 ++
|
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
|
|
|
|
|
|
|
upgrade :: Bool -> Annex Bool
|
|
|
|
upgrade automatic = go =<< getVersion
|
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
|
2013-05-11 20:03:00 +00:00
|
|
|
#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
|
2013-11-05 20:42:59 +00:00
|
|
|
go (Just "4") = Upgrade.V4.upgrade automatic
|
2012-11-11 04:51:07 +00:00
|
|
|
go _ = return True
|