summaryrefslogtreecommitdiff
path: root/Annex
diff options
context:
space:
mode:
authorGravatar guilhem <guilhem@fripost.org>2013-04-14 00:10:49 +0200
committerGravatar Joey Hess <joey@kitenet.net>2013-04-13 19:26:24 -0400
commit0957b771da4c58f593f3ecaf194ffdd5c6d335a5 (patch)
tree02043c5c8bd88ccae712cc84ccdae96175facd53 /Annex
parent371dfdfbebd7b7e5142f147324f67fce3ed9cce0 (diff)
Allow rsync to use other remote shells.
Introduced a new per-remote option 'annex-rsync-transport' to specify the remote shell that it to be used with rsync. In case the value is 'ssh', connections are cached unless 'sshcaching' is unset.
Diffstat (limited to 'Annex')
-rw-r--r--Annex/Ssh.hs22
1 files changed, 17 insertions, 5 deletions
diff --git a/Annex/Ssh.hs b/Annex/Ssh.hs
index 0b8ce3b93..cf92bd248 100644
--- a/Annex/Ssh.hs
+++ b/Annex/Ssh.hs
@@ -8,8 +8,9 @@
{-# LANGUAGE CPP #-}
module Annex.Ssh (
- sshParams,
+ sshCachingOptions,
sshCleanup,
+ sshReadPort,
) where
import qualified Data.Map as M
@@ -24,8 +25,8 @@ import Config
{- Generates parameters to ssh to a given host (or user@host) on a given
- port, with connection caching. -}
-sshParams :: (String, Maybe Integer) -> [CommandParam] -> Annex [CommandParam]
-sshParams (host, port) opts = go =<< sshInfo (host, port)
+sshCachingOptions :: (String, Maybe Integer) -> [CommandParam] -> Annex [CommandParam]
+sshCachingOptions (host, port) opts = go =<< sshInfo (host, port)
where
go (Nothing, params) = ret params
go (Just socketfile, params) = do
@@ -33,8 +34,7 @@ sshParams (host, port) opts = go =<< sshInfo (host, port)
liftIO $ createDirectoryIfMissing True $ parentDir socketfile
lockFile $ socket2lock socketfile
ret params
- ret ps = return $ ps ++ opts ++ portParams port ++
- [Param "-T", Param host]
+ ret ps = return $ ps ++ opts ++ portParams port ++ [Param "-T"]
-- If the lock pool is empty, this is the first ssh of this
-- run. There could be stale ssh connections hanging around
-- from a previous git-annex run that was interrupted.
@@ -154,3 +154,15 @@ sizeof_sockaddr_un_sun_path = 100
- appear on disk. -}
valid_unix_socket_path :: FilePath -> Bool
valid_unix_socket_path f = length (decodeW8 f) < sizeof_sockaddr_un_sun_path
+
+{- Parses the SSH port, and returns the other OpenSSH options. If
+ - several ports are found, the last one takes precedence. -}
+sshReadPort :: [String] -> (Maybe Integer, [String])
+sshReadPort params = (port, reverse args)
+ where
+ (port,args) = aux (Nothing, []) params
+ aux (p,ps) [] = (p,ps)
+ aux (_,ps) ("-p":p:rest) = aux (readPort p, ps) rest
+ aux (p,ps) (q:rest) | "-p" `isPrefixOf` q = aux (readPort $ drop 2 q, ps) rest
+ | otherwise = aux (p,q:ps) rest
+ readPort p = fmap fst $ listToMaybe $ reads p