]> dgit.raspbian.org Git - git-annex.git/commitdiff
renameremote: Better handling of case where there are multiple special remotes with...
authorJoey Hess <joeyh@joeyh.name>
Wed, 5 Jan 2022 19:24:02 +0000 (15:24 -0400)
committerJoey Hess <joeyh@joeyh.name>
Wed, 5 Jan 2022 19:24:02 +0000 (15:24 -0400)
Instead of renaming one at random, error out and ask that a uuid be
specified.

Sponsored-by: Brett Eisenberg on Patreon
Annex/SpecialRemote.hs
Assistant/MakeRemote.hs
CHANGELOG
Command/InitRemote.hs
Command/RenameRemote.hs

index c6b736f8ad46e4eaae6013d4c7ed4171ff79d5ae..5e2a1c2325ebeae35bcadb4b7f73f0e5ab65f967 100644 (file)
@@ -30,10 +30,10 @@ import qualified Data.Map as M
  -
  - Remotes that are not dead come first in the list
  - when a name appears multiple times. -}
-findExisting :: RemoteName -> Annex (Maybe (UUID, RemoteConfig, Maybe (ConfigFrom UUID)))
+findExisting :: RemoteName -> Annex [(UUID, RemoteConfig, Maybe (ConfigFrom UUID))]
 findExisting name = do
        (a, b) <- findExisting' name
-       return (headMaybe (a++b))
+       return (a++b)
 
 {- Dead remotes with the name are in the second list, all others in the
  - first list. -}
index 45ceb013370edfd2869dd204efd9d289e351b914..46daa33a04bf051d341cf947080e2f1a53b744d2 100644 (file)
@@ -55,9 +55,9 @@ makeRsyncRemote :: RemoteName -> String -> Annex String
 makeRsyncRemote name location = makeRemote name location $ const $ void $
        go =<< Annex.SpecialRemote.findExisting name
   where
-       go Nothing = setupSpecialRemote name Rsync.remote config Nothing
+       go [] = setupSpecialRemote name Rsync.remote config Nothing
                (Nothing, R.Init, Annex.SpecialRemote.newConfig name Nothing mempty mempty) Nothing
-       go (Just (u, c, mcu)) = setupSpecialRemote name Rsync.remote config Nothing
+       go ((u, c, mcu):_) = setupSpecialRemote name Rsync.remote config Nothing
                (Just u, R.Enable c, c) mcu
        config = M.fromList
                [ (encryptionField, Proposed "shared")
@@ -86,16 +86,16 @@ initSpecialRemote name remotetype mcreds config = go 0
        go n = do
                let fullname = if n == 0  then name else name ++ show n
                Annex.SpecialRemote.findExisting fullname >>= \case
-                       Nothing -> setupSpecialRemote fullname remotetype config mcreds
+                       [] -> setupSpecialRemote fullname remotetype config mcreds
                                (Nothing, R.Init, Annex.SpecialRemote.newConfig fullname Nothing mempty mempty) Nothing
-                       Just _ -> go (n + 1)
+                       _ -> go (n + 1)
 
 {- Enables an existing special remote. -}
 enableSpecialRemote :: SpecialRemoteMaker
 enableSpecialRemote name remotetype mcreds config =
        Annex.SpecialRemote.findExisting name >>= \case
-               Nothing -> error $ "Cannot find a special remote named " ++ name
-               Just (u, c, mcu) -> setupSpecialRemote' False name remotetype config mcreds (Just u, R.Enable c, c) mcu
+               [] -> error $ "Cannot find a special remote named " ++ name
+               ((u, c, mcu):_) -> setupSpecialRemote' False name remotetype config mcreds (Just u, R.Enable c, c) mcu
 
 setupSpecialRemote :: RemoteName -> RemoteType -> R.RemoteConfig -> Maybe CredPair -> (Maybe UUID, R.SetupStage, R.RemoteConfig) -> Maybe (Annex.SpecialRemote.ConfigFrom UUID) -> Annex RemoteName
 setupSpecialRemote = setupSpecialRemote' True
index 0c0833434b32a5e1b0399c37743438d9b6f33f97..b8c375d3236d6f5f6187a33fdf1cab0f1d5a1be2 100644 (file)
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,7 +3,7 @@ git-annex (8.20211232) UNRELEASED; urgency=medium
   * export: When a non-annexed symlink is in the tree to be exported, skip it.
   * import: When the previously exported tree contained a non-annexed symlink,
     preserve it in the imported tree so it does not get deleted.
-  * enableremote: Better handling of the unusual case where
+  * enableremote, renameremote: Better handling of the unusual case where
     multiple special remotes have been initialized with the same name.
 
  -- Joey Hess <id@joeyh.name>  Mon, 03 Jan 2022 14:01:14 -0400
index ece74560899d67e26b0fe9f1fc1cd38b7b6c1f4e..b1bfc4e1e905480f7b60e125a5771303ca16d97b 100644 (file)
@@ -64,7 +64,7 @@ seek o = withWords (commandAction . (start o)) (cmdparams o)
 
 start :: InitRemoteOptions -> [String] -> CommandStart
 start _ [] = giveup "Specify a name for the remote."
-start o (name:ws) = ifM (isJust <$> findExisting name)
+start o (name:ws) = ifM (not . null <$> findExisting name)
        ( giveup $ "There is already a special remote named \"" ++ name ++
                "\". (Use enableremote to enable an existing special remote.)"
        , ifM (isJust <$> Remote.byNameOnly name)
index fd4683f1f1c9d4f7c7df5883c335489391333300..3366182aa246ec55c08696091ccaee919fce9e56 100644 (file)
@@ -1,6 +1,6 @@
 {- git-annex command
  -
- - Copyright 2019 Joey Hess <id@joeyh.name>
+ - Copyright 2019-2021 Joey Hess <id@joeyh.name>
  -
  - Licensed under the GNU AGPL version 3 or higher.
  -}
@@ -28,19 +28,20 @@ seek = withWords (commandAction . start)
 
 start :: [String] -> CommandStart
 start ps@(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 mcu
+       ((u, cfg, mcu):[]) -> Annex.SpecialRemote.findExisting newname >>= \case
+               [] -> go u cfg mcu
+               _ -> giveup $ "The name " ++ newname ++ " is already used by a special remote."
        -- 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.
-       Nothing -> Remote.nameToUUID' oldname >>= \case
+       [] -> Remote.nameToUUID' oldname >>= \case
                Left e -> giveup e
                Right u -> do
                        m <- Logs.Remote.remoteConfigMap
                        case M.lookup u m of
                                Nothing -> giveup "That is not a special remote."
                                Just cfg -> go u cfg Nothing
+       _ -> giveup $ "There are multiple special remotes named " ++ oldname ++ ". Provide instead the uuid or description of the remote to rename."
   where
        ai = ActionItemOther Nothing
        si = SeekInput ps