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.
This commit is contained in:
Joey Hess 2019-10-11 14:18:44 -04:00
parent c0e88b7695
commit 35d7ffe128
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 20 additions and 16 deletions

View file

@ -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

View file

@ -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.
--

View file

@ -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.