summaryrefslogtreecommitdiff
path: root/Annex/Ssh.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-07-21 14:14:54 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-07-21 14:14:54 -0400
commit57d9c438a76f6b06cce5bda0fcc436cf3a694932 (patch)
treec0ac2ff1fbb8d038e712ab0ac2e0d6b4d5733ca5 /Annex/Ssh.hs
parentc45bf9887bef31d082d4e152bb2105edf59e7985 (diff)
stop cached ssh connection w/o needing to look up host and port
Turns out that with -O stop -S socketfile, ssh does not need the real hostname, or port to be specificed. This is because it simply talks to the ssh behind the socket and tells it to stop. So, can eliminate the conversion back from a socketfile to host and port. Which will allow using shorter filenames for sockets in the future.
Diffstat (limited to 'Annex/Ssh.hs')
-rw-r--r--Annex/Ssh.hs27
1 files changed, 10 insertions, 17 deletions
diff --git a/Annex/Ssh.hs b/Annex/Ssh.hs
index 940cbb5a7..397fdb75c 100644
--- a/Annex/Ssh.hs
+++ b/Annex/Ssh.hs
@@ -51,17 +51,18 @@ sshInfo (host, port) = go =<< sshCacheDir
go (Just dir) = do
let socketfile = dir </> hostport2socket host port
if valid_unix_socket_path socketfile
- then return (Just socketfile, cacheparams socketfile)
+ then return (Just socketfile, sshConnectionCachingParams socketfile)
else do
socketfile' <- liftIO $ relPathCwdToFile socketfile
if valid_unix_socket_path socketfile'
- then return (Just socketfile', cacheparams socketfile')
+ then return (Just socketfile', sshConnectionCachingParams socketfile')
else return (Nothing, [])
- cacheparams :: FilePath -> [CommandParam]
- cacheparams socketfile =
- [ Param "-S", Param socketfile
- , Params "-o ControlMaster=auto -o ControlPersist=yes"
- ]
+
+sshConnectionCachingParams :: FilePath -> [CommandParam]
+sshConnectionCachingParams socketfile =
+ [ Param "-S", Param socketfile
+ , Params "-o ControlMaster=auto -o ControlPersist=yes"
+ ]
{- ssh connection caching creates sockets, so will not work on a
- crippled filesystem. A GIT_ANNEX_TMP_DIR can be provided to use
@@ -116,14 +117,13 @@ sshCleanup = go =<< sshCacheDir
stopssh socketfile
#endif
stopssh socketfile = do
- let (host, port) = socket2hostport socketfile
- (_, params) <- sshInfo (host, port)
+ let params = sshConnectionCachingParams socketfile
-- "ssh -O stop" is noisy on stderr even with -q
void $ liftIO $ catchMaybeIO $
withQuietOutput createProcessSuccess $
proc "ssh" $ toCommand $
[ Params "-O stop"
- ] ++ params ++ [Param host]
+ ] ++ params ++ [Param "any"]
-- Cannot remove the lock file; other processes may
-- be waiting on our exclusive lock to use it.
@@ -131,13 +131,6 @@ hostport2socket :: String -> Maybe Integer -> FilePath
hostport2socket host Nothing = host
hostport2socket host (Just port) = host ++ "!" ++ show port
-socket2hostport :: FilePath -> (String, Maybe Integer)
-socket2hostport socket
- | null p = (h, Nothing)
- | otherwise = (h, readish p)
- where
- (h, p) = separate (== '!') $ takeFileName socket
-
socket2lock :: FilePath -> FilePath
socket2lock socket = socket ++ lockExt