git-annex/Upgrade.hs
Joey Hess 0a4479b8ec
Avoid backtraces on expected failures when built with ghc 8; only use backtraces for unexpected errors.
ghc 8 added backtraces on uncaught errors. This is great, but git-annex was
using error in many places for a error message targeted at the user, in
some known problem case. A backtrace only confuses such a message, so omit it.

Notably, commands like git annex drop that failed due to eg, numcopies,
used to use error, so had a backtrace.

This commit was sponsored by Ethan Aubin.
2016-11-15 21:29:54 -04:00

59 lines
1.6 KiB
Haskell

{- git-annex upgrade support
-
- Copyright 2010, 2013 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
{-# LANGUAGE CPP #-}
module Upgrade where
import Annex.Common
import Annex.Version
#ifndef mingw32_HOST_OS
import qualified Upgrade.V0
import qualified Upgrade.V1
#endif
import qualified Upgrade.V2
import qualified Upgrade.V3
import qualified Upgrade.V4
import qualified Upgrade.V5
checkUpgrade :: Version -> Annex ()
checkUpgrade = maybe noop giveup <=< needsUpgrade
needsUpgrade :: Version -> Annex (Maybe String)
needsUpgrade v
| v `elem` supportedVersions = ok
| v `elem` autoUpgradeableVersions = ifM (upgrade True defaultVersion)
( ok
, err "Automatic upgrade failed!"
)
| v `elem` upgradableVersions = err "Upgrade this repository: git-annex upgrade"
| otherwise = err "Upgrade git-annex."
where
err msg = return $ Just $ "Repository version " ++ v ++
" is not supported. " ++ msg
ok = return Nothing
upgrade :: Bool -> Version -> Annex Bool
upgrade automatic destversion = do
upgraded <- go =<< getVersion
when upgraded $
setVersion destversion
return upgraded
where
go (Just v) | v >= destversion = return True
#ifndef mingw32_HOST_OS
go (Just "0") = Upgrade.V0.upgrade
go (Just "1") = Upgrade.V1.upgrade
#else
go (Just "0") = giveup "upgrade from v0 on Windows not supported"
go (Just "1") = giveup "upgrade from v1 on Windows not supported"
#endif
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
go _ = return True