fixes for enabling and autoenabling mask special remotes
authorJoey Hess <joeyh@joeyh.name>
Fri, 11 Apr 2025 17:11:21 +0000 (13:11 -0400)
committerJoey Hess <joeyh@joeyh.name>
Fri, 11 Apr 2025 17:18:23 +0000 (13:18 -0400)
Remote/Mask.hs
doc/git-annex.mdwn

index b4b981fbe9bdb601633a79f5b2ba3f80de18a462..c17c370fdab63d6d91e96e5109551585206a9089 100644 (file)
@@ -104,8 +104,13 @@ maskSetup setupstage mu _ c gc = do
                                (M.lookup remoteField c)
                        setupremote =<< findnamed maskremotename
                _ -> case M.lookup remoteField c of
-                       Just (Proposed maskremotename) ->
-                               setupremote =<< findnamed maskremotename
+                       -- enableremote with remote= overrides the remote
+                       -- name that was used with initremote.
+                       Just (Proposed maskremotename) -> do
+                               r <- findnamed maskremotename
+                               unless (uuid r == maskremoteuuid) $
+                                       giveup $ "Remote \"" ++ maskremotename ++ "\" does not have the expected uuid (" ++ fromUUID maskremoteuuid ++ ")" 
+                               setupremote r
                        _ -> enableremote remotelist
   where
        setupremote r = do
@@ -117,18 +122,20 @@ maskSetup setupstage mu _ c gc = do
                u <- maybe (liftIO genUUID) return mu
                gitConfigSpecialRemote u c'' [ ("mask", name r) ]
                return (c'', u)
+               
+       maskremoteuuid = fromMaybe NoUUID $ 
+               toUUID . fromProposedAccepted
+                       <$> M.lookup remoteUUIDField c
                                
        enableremote remotelist = do
-               let maskremoteuuid = fromMaybe NoUUID $ 
-                       toUUID . fromProposedAccepted
-                               <$> M.lookup remoteUUIDField c
                case filter (\r -> uuid r == maskremoteuuid) remotelist of
                        (r:_) -> setupremote r
                        [] -> case setupstage of
                                Enable _ ->
                                        missingMaskedRemote maskremoteuuid
                                -- When autoenabling, the masked remote may
-                               -- get autoenabled later.
+                               -- get autoenabled later, or need to be
+                               -- manually enabled.
                                _ -> do
                                        (c', _) <- encryptionSetup c gc
                                        u <- maybe (liftIO genUUID) return mu
@@ -170,14 +177,17 @@ findMaskedRemote c gc myuuid = case remoteAnnexMask gc of
        Just "true" -> 
                case getmaskedremoteuuid of
                        Just maskremoteuuid -> 
-                               selectremote maskremoteuuid
-                                       (\r -> uuid r == maskremoteuuid)
+                               selectremote maskremoteuuid $ \r ->
+                                       uuid r == maskremoteuuid
                        Nothing -> missingMaskedRemote NoUUID
        Just maskremotename ->
-               selectremote NoUUID (\r -> name r == maskremotename)
+               selectremote (fromMaybe NoUUID getmaskedremoteuuid) $ \r -> 
+                       name r == maskremotename 
+                               && Just (uuid r) == getmaskedremoteuuid
        Nothing -> missingMaskedRemote NoUUID
   where
-       getmaskedremoteuuid = toUUID . fromProposedAccepted <$> M.lookup remoteField c
+       getmaskedremoteuuid = toUUID . fromProposedAccepted
+               <$> M.lookup remoteUUIDField c
        selectremote u f = do
                remotelist <- Annex.getState Annex.remotes
                case filter f remotelist of
index 25fb8ec3b2a1f9867ad967a0a23e308770137042..c3b1ea0745fd574d73e4171dac352bae89b9d202 100644 (file)
@@ -2053,7 +2053,9 @@ Remotes are configured using these settings in `.git/config`.
 
 * `remote.<name>.annex-mask`
 
-  Used by mask special remotes.
+  Used by mask special remotes, this is set to the name of the remote
+  that is masked. If this is set to "true", then any remote with the
+  right UUID will be used.
   Normally this is automatically set up by `git annex initremote`.
 
 * `remote.<name>.annex-externaltype`