add sameas inherited configs to newConfig

This makes initremote --sameas work with encryption inherited.
This commit is contained in:
Joey Hess 2019-10-11 12:45:30 -04:00
parent 2bd6e81bb0
commit 91eed85fd4
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
5 changed files with 46 additions and 35 deletions

View file

@ -33,12 +33,21 @@ findExisting name = do
. findByName name
<$> Logs.Remote.readRemoteLog
newConfig :: RemoteName -> Maybe (Sameas UUID) -> RemoteConfig
newConfig name Nothing = M.singleton nameField name
newConfig name (Just (Sameas u)) = M.fromList
[ (sameasNameField, name)
, (sameasUUIDField, fromUUID u)
]
newConfig
:: RemoteName
-> Maybe (Sameas UUID)
-> RemoteConfig
-- ^ configuration provided by the user
-> M.Map UUID RemoteConfig
-- ^ configuration of other special remotes, to inherit from
-- when sameas is used
-> RemoteConfig
newConfig name sameas fromuser m = case sameas of
Nothing -> M.insert nameField name fromuser
Just (Sameas u) -> addSameasInherited m $ M.fromList
[ (sameasNameField, name)
, (sameasUUIDField, fromUUID u)
] `M.union` fromuser
findByName :: RemoteName -> M.Map UUID RemoteConfig -> [(UUID, RemoteConfig)]
findByName n = filter (matching . snd) . M.toList