2010-12-28 21:44:55 +00:00
|
|
|
{- git-annex command
|
|
|
|
-
|
2021-01-07 13:59:52 +00:00
|
|
|
- Copyright 2010-2021 Joey Hess <id@joeyh.name>
|
2010-12-28 21:44:55 +00:00
|
|
|
-
|
2019-03-13 19:48:14 +00:00
|
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
2010-12-28 21:44:55 +00:00
|
|
|
-}
|
|
|
|
|
|
|
|
module Command.Trust where
|
|
|
|
|
|
|
|
import Command
|
2011-03-27 20:55:43 +00:00
|
|
|
import qualified Remote
|
2021-01-07 13:59:52 +00:00
|
|
|
import qualified Annex
|
2014-02-20 19:17:39 +00:00
|
|
|
import Types.TrustLevel
|
2011-10-15 20:21:08 +00:00
|
|
|
import Logs.Trust
|
2014-02-20 19:12:35 +00:00
|
|
|
import Logs.Group
|
|
|
|
|
|
|
|
import qualified Data.Set as S
|
2010-12-28 21:44:55 +00:00
|
|
|
|
2015-07-08 16:33:27 +00:00
|
|
|
cmd :: Command
|
2015-07-08 19:08:02 +00:00
|
|
|
cmd = command "trust" SectionSetup "trust a repository"
|
|
|
|
(paramRepeating paramRemote) (withParams seek)
|
2010-12-30 19:06:26 +00:00
|
|
|
|
2015-07-08 19:08:02 +00:00
|
|
|
seek :: CmdParams -> CommandSeek
|
2014-02-20 19:12:35 +00:00
|
|
|
seek = trustCommand "trust" Trusted
|
2010-12-28 21:44:55 +00:00
|
|
|
|
2015-07-08 19:08:02 +00:00
|
|
|
trustCommand :: String -> TrustLevel -> CmdParams -> CommandSeek
|
2018-10-01 18:12:06 +00:00
|
|
|
trustCommand c level = withWords (commandAction . start)
|
2014-02-20 19:12:35 +00:00
|
|
|
where
|
|
|
|
start ws = do
|
|
|
|
let name = unwords ws
|
|
|
|
u <- Remote.nameToUUID name
|
2020-09-14 20:49:33 +00:00
|
|
|
let si = SeekInput ws
|
2021-01-07 13:59:52 +00:00
|
|
|
starting c (ActionItemOther (Just name)) si (perform name u)
|
|
|
|
perform name uuid = do
|
|
|
|
when (level >= Trusted) $
|
2022-06-28 19:28:14 +00:00
|
|
|
unlessM (Annex.getRead Annex.force) $
|
2021-01-07 13:59:52 +00:00
|
|
|
giveup $ trustedNeedsForce name
|
2014-02-20 19:12:35 +00:00
|
|
|
trustSet uuid level
|
|
|
|
when (level == DeadTrusted) $
|
|
|
|
groupSet uuid S.empty
|
2014-02-20 19:17:39 +00:00
|
|
|
l <- lookupTrust uuid
|
|
|
|
when (l /= level) $
|
2017-09-13 16:08:46 +00:00
|
|
|
warning $ "This remote's trust level is overridden to " ++ showTrustLevel l ++ "."
|
2014-02-20 19:12:35 +00:00
|
|
|
next $ return True
|
2021-01-07 13:59:52 +00:00
|
|
|
|
|
|
|
trustedNeedsForce :: String -> String
|
2021-01-11 17:14:09 +00:00
|
|
|
trustedNeedsForce name = unwords
|
2021-01-07 13:59:52 +00:00
|
|
|
[ "Trusting a repository can lead to data loss."
|
|
|
|
, "If you're sure you know what you're doing, use --force to"
|
|
|
|
, "make this take effect."
|
|
|
|
, "If you choose to do so, bear in mind that any time you drop"
|
|
|
|
, "content from " ++ name ++ ", you will risk losing data."
|
|
|
|
]
|