add annex.sshcaching config setting

This commit is contained in:
Joey Hess 2012-01-20 17:13:36 -04:00
parent 47250a153a
commit 6ef82665de
2 changed files with 23 additions and 10 deletions

View file

@ -15,28 +15,37 @@ import System.IO.Error (try)
import Common.Annex import Common.Annex
import Annex.LockPool import Annex.LockPool
import qualified Git
import qualified Git.Config
{- Generates parameters to ssh to a given host (or user@host) on a given {- Generates parameters to ssh to a given host (or user@host) on a given
- port, with connection caching. -} - port, with connection caching. -}
sshParams :: (String, Maybe Integer) -> Annex [CommandParam] sshParams :: (String, Maybe Integer) -> Annex [CommandParam]
sshParams (host, port) = do sshParams (host, port) = go =<< sshInfo (host, port)
cleanstale
(socketfile, params) <- sshInfo (host, port)
liftIO $ createDirectoryIfMissing True $ parentDir socketfile
lockFile $ socket2lock socketfile
return params
where 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 -- If the lock pool is empty, this is the first ssh of this
-- run. There could be stale ssh connections hanging around -- run. There could be stale ssh connections hanging around
-- from a previous git-annex run that was interrupted. -- from a previous git-annex run that was interrupted.
cleanstale = whenM (null . filter isLock . M.keys <$> getPool) $ cleanstale = whenM (null . filter isLock . M.keys <$> getPool) $
sshCleanup sshCleanup
sshInfo :: (String, Maybe Integer) -> Annex (FilePath, [CommandParam]) sshInfo :: (String, Maybe Integer) -> Annex (Maybe FilePath, [CommandParam])
sshInfo (host, port) = do sshInfo (host, port) = do
dir <- fromRepo $ gitAnnexSshDir caching <- Git.configTrue <$> fromRepo (Git.Config.get "annex.sshcaching" "true")
let socketfile = dir </> hostport2socket host port if caching
return $ (socketfile, cacheParams socketfile ++ portParams port ++ [Param host]) 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 :: FilePath -> [CommandParam]
cacheParams socketfile = cacheParams socketfile =

View file

@ -575,6 +575,10 @@ Here are all the supported configuration settings.
Automatically maintained, and used to automate upgrades between versions. Automatically maintained, and used to automate upgrades between versions.
* `annex.sshcaching`
By default, git-annex caches ssh connections. To disable this, set to `false`.
* `remote.<name>.annex-cost` * `remote.<name>.annex-cost`
When determining which repository to When determining which repository to