autoenable sameas remotes

This commit is contained in:
Joey Hess 2019-10-11 15:32:56 -04:00
parent ec778888d2
commit debafcba2b
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 44 additions and 29 deletions

View file

@ -1,6 +1,6 @@
{- git-annex command
-
- Copyright 2013-2016 Joey Hess <id@joeyh.name>
- Copyright 2013-2019 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU AGPL version 3 or higher.
-}

View file

@ -11,7 +11,6 @@ import qualified Data.Map as M
import Command
import Annex.SpecialRemote
import Annex.SpecialRemote.Config
import qualified Remote
import qualified Logs.Remote
import qualified Types.Remote as R

View file

@ -29,7 +29,7 @@ start :: [String] -> CommandStart
start (oldname:newname:[]) = Annex.SpecialRemote.findExisting oldname >>= \case
Just (u, cfg, mcu) -> Annex.SpecialRemote.findExisting newname >>= \case
Just _ -> giveup $ "The name " ++ newname ++ " is already used by a special remote."
Nothing -> go u cfg
Nothing -> go u cfg mcu
-- Support lookup by uuid or description as well as remote name,
-- as a fallback when there is nothing with the name in the
-- special remote log.
@ -39,17 +39,17 @@ start (oldname:newname:[]) = Annex.SpecialRemote.findExisting oldname >>= \case
m <- Logs.Remote.readRemoteLog
case M.lookup u m of
Nothing -> giveup "That is not a special remote."
Just cfg -> go u cfg
Just cfg -> go u cfg Nothing
where
go u cfg = starting "rename" (ActionItemOther Nothing) $
perform u cfg newname
go u cfg mcu = starting "rename" (ActionItemOther Nothing) $
perform u cfg mcu newname
start _ = giveup "Specify an old name (or uuid or description) and a new name."
perform :: UUID -> R.RemoteConfig -> String -> CommandPerform
perform u cfg newname = do
let namefield = case M.lookup sameasNameField cfg of
Just _ -> sameasNameField
Nothing -> nameField
Logs.Remote.configSet u (M.insert namefield newname cfg)
perform :: UUID -> R.RemoteConfig -> Maybe (Annex.SpecialRemote.ConfigFrom UUID) -> String -> CommandPerform
perform u cfg mcu newname = do
let (namefield, cu) = case mcu of
Nothing -> (nameField, u)
Just (Annex.SpecialRemote.ConfigFrom u') -> (sameasNameField, u')
Logs.Remote.configSet cu (M.insert namefield newname cfg)
next $ return True