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"
|
2022-10-03 17:49:42 +00:00
|
|
|
(paramRepeating paramRepository) (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
|
avoid combining multiple words provided to trust/untrust/dead
* trust, untrust, semitrust, dead: Fix behavior when provided with
multiple repositories to operate on.
* trust, untrust, semitrust, dead: When provided with no parameters,
do not operate on a repository that has an empty name.
The man page and usage already indicated that multiple repos could be
provided to these commands, but they actually used unwords to combine
everything into string, and found a repo matching that string. This was
especially bad when no parameters resulted in the empty string and some
repo happened to have an empty description.
This does change the behavior, and it's possible someone relied on the
current behavior to eg, trust a repo by name with the name not quoted into
a single parameter. But fixing the empty string bug and matching the
documentation are worth breaking that usage.
Note that git-annex init/reinit do still unwords multiple parameters when
provided to them. That is inconsistent behavior, but it certianly seems
possible that something does run git-annex init with an unquoted
description, and I don't think it's worth breaking that just to make it more
consistent with these other commands.
Sponsored-by: Boyd Stephen Smith Jr. on Patreon
2022-10-03 17:48:40 +00:00
|
|
|
trustCommand _ _ [] = giveup "no repository name specified"
|
|
|
|
trustCommand c level ps = withStrings (commandAction . start) ps
|
2014-02-20 19:12:35 +00:00
|
|
|
where
|
avoid combining multiple words provided to trust/untrust/dead
* trust, untrust, semitrust, dead: Fix behavior when provided with
multiple repositories to operate on.
* trust, untrust, semitrust, dead: When provided with no parameters,
do not operate on a repository that has an empty name.
The man page and usage already indicated that multiple repos could be
provided to these commands, but they actually used unwords to combine
everything into string, and found a repo matching that string. This was
especially bad when no parameters resulted in the empty string and some
repo happened to have an empty description.
This does change the behavior, and it's possible someone relied on the
current behavior to eg, trust a repo by name with the name not quoted into
a single parameter. But fixing the empty string bug and matching the
documentation are worth breaking that usage.
Note that git-annex init/reinit do still unwords multiple parameters when
provided to them. That is inconsistent behavior, but it certianly seems
possible that something does run git-annex init with an unquoted
description, and I don't think it's worth breaking that just to make it more
consistent with these other commands.
Sponsored-by: Boyd Stephen Smith Jr. on Patreon
2022-10-03 17:48:40 +00:00
|
|
|
start name = do
|
2014-02-20 19:12:35 +00:00
|
|
|
u <- Remote.nameToUUID name
|
avoid combining multiple words provided to trust/untrust/dead
* trust, untrust, semitrust, dead: Fix behavior when provided with
multiple repositories to operate on.
* trust, untrust, semitrust, dead: When provided with no parameters,
do not operate on a repository that has an empty name.
The man page and usage already indicated that multiple repos could be
provided to these commands, but they actually used unwords to combine
everything into string, and found a repo matching that string. This was
especially bad when no parameters resulted in the empty string and some
repo happened to have an empty description.
This does change the behavior, and it's possible someone relied on the
current behavior to eg, trust a repo by name with the name not quoted into
a single parameter. But fixing the empty string bug and matching the
documentation are worth breaking that usage.
Note that git-annex init/reinit do still unwords multiple parameters when
provided to them. That is inconsistent behavior, but it certianly seems
possible that something does run git-annex init with an unquoted
description, and I don't think it's worth breaking that just to make it more
consistent with these other commands.
Sponsored-by: Boyd Stephen Smith Jr. on Patreon
2022-10-03 17:48:40 +00:00
|
|
|
let si = SeekInput [name]
|
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."
|
|
|
|
]
|