File: ConfigRemote.hs

package info (click to toggle)
git-annex 10.20250416-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 73,572 kB
  • sloc: haskell: 90,656; javascript: 9,103; sh: 1,469; makefile: 211; perl: 137; ansic: 44
file content (64 lines) | stat: -rw-r--r-- 2,343 bytes parent folder | download | duplicates (3)
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
54
55
56
57
58
59
60
61
62
63
64
{- git-annex command
 -
 - Copyright 2023 Joey Hess <id@joeyh.name>
 -
 - Licensed under the GNU AGPL version 3 or higher.
 -}

{-# LANGUAGE OverloadedStrings #-}

module Command.ConfigRemote where

import Command
import qualified Logs.Remote
import qualified Git.Types as Git
import qualified Annex.SpecialRemote as SpecialRemote
import qualified Types.Remote as Remote
import Types.ProposedAccepted
import Command.EnableRemote (unknownNameError, startSpecialRemote', PerformSpecialRemote, deadLast)

import qualified Data.Map as M

cmd :: Command
cmd = withAnnexOptions [jsonOptions] $
	command "configremote" SectionSetup
		"changes special remote configuration"
		(paramPair paramName $ paramOptional $ paramRepeating paramParamValue)
		(withParams seek)

seek :: CmdParams -> CommandSeek
seek = withWords (commandAction . start)

start :: [String] -> CommandStart
start [] = unknownNameError "Specify the remote to configure."
start (name:inputconfig) = deadLast name $
	startSpecialRemote (checkSafeConfig inputconfig) name
		(Logs.Remote.keyValToConfig Proposed inputconfig)

{- Since this command stores config without calling the remote's setup
 - method to validate it, it can only be used on fields that are known to
 - be safe to change in all remotes. -}
checkSafeConfig :: [String] -> Annex ()
checkSafeConfig cs = do
	let rc = Logs.Remote.keyValToConfig Proposed cs
	forM_ (M.keys rc) $ \k ->
		when (fromProposedAccepted k `notElem` safefields) $
			giveup $ "Cannot change field \"" ++ fromProposedAccepted k  ++ "\" with this command. Use git-annex enableremote instead."
	case SpecialRemote.parseRemoteConfig rc (Remote.RemoteConfigParser ps Nothing) of
		Left err -> giveup err
		Right _ -> return ()
  where
	ps = [ SpecialRemote.autoEnableFieldParser ]
	safefields = [ fromProposedAccepted SpecialRemote.autoEnableField ]

startSpecialRemote :: Annex () -> Git.RemoteName -> Remote.RemoteConfig -> [(UUID, Remote.RemoteConfig, Maybe (SpecialRemote.ConfigFrom UUID))] -> CommandStart
startSpecialRemote = startSpecialRemote' "configremote" . performSpecialRemote

performSpecialRemote :: Annex () -> PerformSpecialRemote
performSpecialRemote precheck _ u _ c _ mcu = do
	precheck
	case mcu of
		Nothing -> Logs.Remote.configSet u c
		Just (SpecialRemote.ConfigFrom cu) ->
			Logs.Remote.configSet cu c
	next $ return True