diff options
author | Joey Hess <joey@kitenet.net> | 2012-01-20 17:13:36 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-01-20 17:15:46 -0400 |
commit | 6ef82665de86195a7da6cffcba40874eba06424f (patch) | |
tree | a9fb4874525b49d0693c2f7a5dac27afe3471cc1 /Annex/Ssh.hs | |
parent | 47250a153a6c5a2864fec15fb136290683aeb1c6 (diff) |
add annex.sshcaching config setting
Diffstat (limited to 'Annex/Ssh.hs')
-rw-r--r-- | Annex/Ssh.hs | 29 |
1 files changed, 19 insertions, 10 deletions
diff --git a/Annex/Ssh.hs b/Annex/Ssh.hs index cd832a373..7f5ba48d8 100644 --- a/Annex/Ssh.hs +++ b/Annex/Ssh.hs @@ -15,28 +15,37 @@ import System.IO.Error (try) import Common.Annex import Annex.LockPool +import qualified Git +import qualified Git.Config {- Generates parameters to ssh to a given host (or user@host) on a given - port, with connection caching. -} sshParams :: (String, Maybe Integer) -> Annex [CommandParam] -sshParams (host, port) = do - cleanstale - (socketfile, params) <- sshInfo (host, port) - liftIO $ createDirectoryIfMissing True $ parentDir socketfile - lockFile $ socket2lock socketfile - return params +sshParams (host, port) = go =<< sshInfo (host, port) where + go (Nothing, params) = return params + go (Just socketfile, params) = do + cleanstale + liftIO $ createDirectoryIfMissing True $ parentDir socketfile + lockFile $ socket2lock socketfile + return params -- 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. cleanstale = whenM (null . filter isLock . M.keys <$> getPool) $ sshCleanup -sshInfo :: (String, Maybe Integer) -> Annex (FilePath, [CommandParam]) +sshInfo :: (String, Maybe Integer) -> Annex (Maybe FilePath, [CommandParam]) sshInfo (host, port) = do - dir <- fromRepo $ gitAnnexSshDir - let socketfile = dir </> hostport2socket host port - return $ (socketfile, cacheParams socketfile ++ portParams port ++ [Param host]) + caching <- Git.configTrue <$> fromRepo (Git.Config.get "annex.sshcaching" "true") + if caching + then do + dir <- fromRepo $ gitAnnexSshDir + let socketfile = dir </> hostport2socket host port + return $ (Just socketfile, cacheParams socketfile ++ params) + else return (Nothing, params) + where + params = portParams port ++ [Param host] cacheParams :: FilePath -> [CommandParam] cacheParams socketfile = |