File: Trust.hs

package info (click to toggle)
git-annex 10.20230126-3
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 69,344 kB
  • sloc: haskell: 74,654; javascript: 9,103; sh: 1,304; makefile: 203; perl: 136; ansic: 44
file content (53 lines) | stat: -rw-r--r-- 1,549 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
{- git-annex command
 -
 - Copyright 2010-2021 Joey Hess <id@joeyh.name>
 -
 - Licensed under the GNU AGPL version 3 or higher.
 -}

module Command.Trust where

import Command
import qualified Remote
import qualified Annex
import Types.TrustLevel
import Logs.Trust
import Logs.Group

import qualified Data.Set as S

cmd :: Command
cmd = command "trust" SectionSetup "trust a repository"
	(paramRepeating paramRepository) (withParams seek)

seek :: CmdParams -> CommandSeek
seek = trustCommand "trust" Trusted

trustCommand :: String -> TrustLevel -> CmdParams -> CommandSeek
trustCommand _ _ [] = giveup "no repository name specified"
trustCommand c level ps = withStrings (commandAction . start) ps
  where
	start name = do
		u <- Remote.nameToUUID name
		let si = SeekInput [name]
		starting c (ActionItemOther (Just name)) si (perform name u)
	perform name uuid = do
		when (level >= Trusted) $
			unlessM (Annex.getRead Annex.force) $
				giveup $ trustedNeedsForce name
		trustSet uuid level
		when (level == DeadTrusted) $
			groupSet uuid S.empty
		l <- lookupTrust uuid
		when (l /= level) $
			warning $ "This remote's trust level is overridden to " ++ showTrustLevel l ++ "."
		next $ return True

trustedNeedsForce :: String -> String
trustedNeedsForce name = unwords
	[ "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."
	]