added an optional cost= configuration to all special remotes

Note that when this is specified and an older git-annex is used to
enableremote such a special remote, it will simply ignore the cost= field
and use whatever the default cost is.

In passing, fixed adb to support the remote.name.cost and
remote.name.cost-command configs.

Sponsored-by: Dartmouth College's DANDI project
This commit is contained in:
Joey Hess 2023-01-12 13:42:28 -04:00
parent 400ce29a94
commit cfaae7e931
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
25 changed files with 83 additions and 42 deletions

View file

@ -1,6 +1,6 @@
{- git-annex special remote configuration
-
- Copyright 2019-2020 Joey Hess <id@joeyh.name>
- Copyright 2019-2023 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}
@ -17,9 +17,11 @@ import Types.UUID
import Types.ProposedAccepted
import Types.RemoteConfig
import Types.GitConfig
import Config.Cost
import qualified Data.Map as M
import qualified Data.Set as S
import Text.Read
import Data.Typeable
import GHC.Stack
@ -56,6 +58,9 @@ typeField = Accepted "type"
autoEnableField :: RemoteConfigField
autoEnableField = Accepted "autoenable"
costField :: RemoteConfigField
costField = Accepted "cost"
encryptionField :: RemoteConfigField
encryptionField = Accepted "encryption"
@ -106,6 +111,8 @@ commonFieldParsers =
(FieldDesc "type of special remote")
, trueFalseParser autoEnableField (Just False)
(FieldDesc "automatically enable special remote")
, costParser costField
(FieldDesc "default cost of this special remote")
, yesNoParser exportTreeField (Just False)
(FieldDesc "export trees of files to this remote")
, yesNoParser importTreeField (Just False)
@ -252,6 +259,13 @@ trueFalseParser' "true" = Just True
trueFalseParser' "false" = Just False
trueFalseParser' _ = Nothing
costParser :: RemoteConfigField -> FieldDesc -> RemoteConfigFieldParser
costParser f fd = genParser readcost f Nothing fd
(Just (ValueDesc "a number"))
where
readcost :: String -> Maybe Cost
readcost = readMaybe
genParser
:: Typeable t
=> (String -> Maybe t)