Support GIT_SSH and GIT_SSH_COMMAND
They are handled close the same as they are by git. However, unlike git, git-annex sometimes needs to pass the -n parameter when using these. So, this has the potential for breaking some setup, and perhaps there ought to be a ANNEX_USE_GIT_SSH=1 needed to use these. But I'd rather avoid that if possible, so let's see if anyone complains. Almost all places where "ssh" was run have been changed to support the env vars. Anything still calling sshOptions does not support them. In particular, rsync special remotes don't. Seems that annex-rsync-transport already gives sufficient control there. (Fixed in passing: Remote.Helper.Ssh.toRepo used to extract remoteAnnexSshOptions and pass them to sshOptions, which was redundant since sshOptions also extracts those.) This commit was sponsored by Jeff Goeke-Smith on Patreon.
This commit is contained in:
parent
8cd473c716
commit
faecd73f32
11 changed files with 175 additions and 46 deletions
|
@ -212,11 +212,11 @@ storeBupUUID u buprepo = do
|
|||
v = fromUUID u
|
||||
|
||||
onBupRemote :: Git.Repo -> (FilePath -> [CommandParam] -> IO a) -> FilePath -> [CommandParam] -> Annex a
|
||||
onBupRemote r a command params = do
|
||||
onBupRemote r runner command params = do
|
||||
c <- Annex.getRemoteGitConfig r
|
||||
sshparams <- Ssh.toRepo NoConsumeStdin r c [Param $
|
||||
"cd " ++ dir ++ " && " ++ unwords (command : toCommand params)]
|
||||
liftIO $ a "ssh" sshparams
|
||||
let remotecmd = "cd " ++ dir ++ " && " ++ unwords (command : toCommand params)
|
||||
(sshcmd, sshparams) <- Ssh.toRepo NoConsumeStdin r c remotecmd
|
||||
liftIO $ runner sshcmd sshparams
|
||||
where
|
||||
path = Git.repoPath r
|
||||
base = fromMaybe path (stripPrefix "/~/" path)
|
||||
|
|
|
@ -121,13 +121,12 @@ splitRemoteDdarRepo ddarrepo =
|
|||
ddarRemoteCall :: ConsumeStdin -> DdarRepo -> Char -> [CommandParam] -> Annex (String, [CommandParam])
|
||||
ddarRemoteCall cs ddarrepo cmd params
|
||||
| ddarLocal ddarrepo = return ("ddar", localParams)
|
||||
| otherwise = do
|
||||
os <- sshOptions cs (host, Nothing) (ddarRepoConfig ddarrepo) []
|
||||
return ("ssh", os ++ remoteParams)
|
||||
| otherwise = sshCommand cs (host, Nothing) (ddarRepoConfig ddarrepo) remoteCommand
|
||||
where
|
||||
(host, ddarrepo') = splitRemoteDdarRepo ddarrepo
|
||||
localParams = Param [cmd] : Param (ddarRepoLocation ddarrepo) : params
|
||||
remoteParams = Param host : Param "ddar" : Param [cmd] : Param ddarrepo' : params
|
||||
remoteCommand = unwords $ map shellEscape $ toCommand $
|
||||
[Param "ddar", Param [cmd], Param ddarrepo'] ++ params
|
||||
|
||||
{- Specialized ddarRemoteCall that includes extraction command and flags -}
|
||||
ddarExtractRemoteCall :: ConsumeStdin -> DdarRepo -> Key -> Annex (String, [CommandParam])
|
||||
|
@ -159,23 +158,19 @@ ddarDirectoryExists ddarrepo
|
|||
Left _ -> Right False
|
||||
Right status -> Right $ isDirectory status
|
||||
| otherwise = do
|
||||
ps <- sshOptions NoConsumeStdin (host, Nothing)
|
||||
(ddarRepoConfig ddarrepo) []
|
||||
exitCode <- liftIO $ safeSystem "ssh" (ps ++ params)
|
||||
let remotecmd = unwords $ map shellEscape
|
||||
[ "test", "-d", ddarrepo' ]
|
||||
(sshcmd, sshps) <- sshCommand NoConsumeStdin (host, Nothing)
|
||||
(ddarRepoConfig ddarrepo) remotecmd
|
||||
exitCode <- liftIO $ safeSystem sshcmd sshps
|
||||
case exitCode of
|
||||
ExitSuccess -> return $ Right True
|
||||
ExitFailure 1 -> return $ Right False
|
||||
ExitFailure code -> return $ Left $ "ssh call " ++
|
||||
show (unwords $ toCommand params) ++
|
||||
ExitFailure code -> return $ Left $ "ssh " ++
|
||||
show (unwords $ toCommand sshps) ++
|
||||
" failed with status " ++ show code
|
||||
where
|
||||
(host, ddarrepo') = splitRemoteDdarRepo ddarrepo
|
||||
params =
|
||||
[ Param host
|
||||
, Param "test"
|
||||
, Param "-d"
|
||||
, Param ddarrepo'
|
||||
]
|
||||
|
||||
{- Use "ddar t" to determine if a given key is present in a ddar archive -}
|
||||
inDdarManifest :: DdarRepo -> Key -> Annex (Either String Bool)
|
||||
|
|
|
@ -23,15 +23,10 @@ import Types.Remote
|
|||
import Types.Transfer
|
||||
import Config
|
||||
|
||||
{- Generates parameters to ssh to a repository's host and run a command.
|
||||
- Caller is responsible for doing any neccessary shellEscaping of the
|
||||
- passed command. -}
|
||||
toRepo :: ConsumeStdin -> Git.Repo -> RemoteGitConfig -> [CommandParam] -> Annex [CommandParam]
|
||||
toRepo cs r gc sshcmd = do
|
||||
let opts = map Param $ remoteAnnexSshOptions gc
|
||||
toRepo :: ConsumeStdin -> Git.Repo -> RemoteGitConfig -> SshCommand -> Annex (FilePath, [CommandParam])
|
||||
toRepo cs r gc remotecmd = do
|
||||
let host = fromMaybe (giveup "bad ssh url") $ Git.Url.hostuser r
|
||||
params <- sshOptions cs (host, Git.Url.port r) gc opts
|
||||
return $ params ++ Param host : sshcmd
|
||||
sshCommand cs (host, Git.Url.port r) gc remotecmd
|
||||
|
||||
{- Generates parameters to run a git-annex-shell command on a remote
|
||||
- repository. -}
|
||||
|
@ -49,8 +44,7 @@ git_annex_shell cs r command params fields
|
|||
: map shellEscape (toCommand shellopts) ++
|
||||
uuidcheck u ++
|
||||
map shellEscape (toCommand fieldopts)
|
||||
sshparams <- toRepo cs r gc [Param sshcmd]
|
||||
return $ Just ("ssh", sshparams)
|
||||
Just <$> toRepo cs r gc sshcmd
|
||||
| otherwise = return Nothing
|
||||
where
|
||||
dir = Git.repoPath r
|
||||
|
|
|
@ -121,7 +121,6 @@ rsyncTransport gc url
|
|||
"ssh":sshopts -> do
|
||||
let (port, sshopts') = sshReadPort sshopts
|
||||
userhost = takeWhile (/=':') url
|
||||
-- Connection caching
|
||||
(Param "ssh":) <$> sshOptions ConsumeStdin
|
||||
(userhost, port) gc
|
||||
(map Param $ loginopt ++ sshopts')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue