From 35d7ffe128368d34795b38d931771624856111d1 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 11 Oct 2019 14:18:44 -0400 Subject: [PATCH] initremote --sameas fully working And using sameas remotes is working. Moved annex-config-uuid setting out of Remote.Helper.Special. EnableRemote will also have to set it. --- Command/InitRemote.hs | 30 ++++++++++++------- Remote/Helper/Special.hs | 3 -- ...ltiple_special_remotes_with_same_uuid.mdwn | 3 -- 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Command/InitRemote.hs b/Command/InitRemote.hs index aa5c07883a..8845d7d653 100644 --- a/Command/InitRemote.hs +++ b/Command/InitRemote.hs @@ -11,12 +11,15 @@ 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 +import Annex.UUID import Logs.UUID import Logs.Remote import Types.GitConfig +import Config cmd :: Command cmd = command "initremote" SectionSetup @@ -63,24 +66,31 @@ start o (name:ws) = ifM (isJust <$> findExisting name) <$> readRemoteLog t <- either giveup return (findType c) starting "initremote" (ActionItemOther (Just name)) $ - perform t name c + perform t name c o ) ) -perform :: RemoteType -> String -> R.RemoteConfig -> CommandPerform -perform t name c = do +perform :: RemoteType -> String -> R.RemoteConfig -> InitRemoteOptions -> CommandPerform +perform t name c o = do dummycfg <- liftIO dummyRemoteGitConfig - (c', u) <- R.setup t R.Init cu Nothing c dummycfg - next $ cleanup u name c' + (c', u) <- R.setup t R.Init (sameasu <|> uuidfromuser) Nothing c dummycfg + next $ cleanup u name c' o where - cu = case M.lookup "uuid" c of + uuidfromuser = case M.lookup "uuid" c of Just s | isUUID s -> Just (toUUID s) | otherwise -> giveup "invalid uuid" Nothing -> Nothing + sameasu = toUUID <$> M.lookup sameasUUIDField c -cleanup :: UUID -> String -> R.RemoteConfig -> CommandCleanup -cleanup u name c = do - describeUUID u (toUUIDDesc name) - Logs.Remote.configSet u c +cleanup :: UUID -> String -> R.RemoteConfig -> InitRemoteOptions -> CommandCleanup +cleanup u name c o = do + case sameas o of + Nothing -> do + describeUUID u (toUUIDDesc name) + Logs.Remote.configSet u c + Just _ -> do + cu <- liftIO genUUID + setConfig (remoteConfig c "config-uuid") (fromUUID cu) + Logs.Remote.configSet cu c return True diff --git a/Remote/Helper/Special.hs b/Remote/Helper/Special.hs index 7e607ef5a3..510793a8db 100644 --- a/Remote/Helper/Special.hs +++ b/Remote/Helper/Special.hs @@ -74,9 +74,6 @@ gitConfigSpecialRemote u c cfgs = do forM_ cfgs $ \(k, v) -> setConfig (remoteConfig c k) v storeUUIDIn (remoteConfig c "uuid") u - case M.lookup sameasUUIDField c of - Nothing -> noop - Just sameasuuid -> setConfig (remoteConfig c "config-uuid") sameasuuid -- RetrievalVerifiableKeysSecure unless overridden by git config. -- diff --git a/doc/todo/support_multiple_special_remotes_with_same_uuid.mdwn b/doc/todo/support_multiple_special_remotes_with_same_uuid.mdwn index e509f9a29e..15283c3ece 100644 --- a/doc/todo/support_multiple_special_remotes_with_same_uuid.mdwn +++ b/doc/todo/support_multiple_special_remotes_with_same_uuid.mdwn @@ -34,9 +34,6 @@ the remote.log. Eg, "B sameas=A foo=bar ..." Implementation notes: -initremote --sameas ends up with the annex-uuid and the annex-config-uuid -configured backwards. Oops. - Need to get enableremote working for sameas. Deal with the per-remote state issue.