only run sshCleanup when the command actually used ssh connection caching

Optimises query commands that do not. More importantly, avoids any ssh
connection cleanup delay causing problems at the end of such commands.
This commit is contained in:
Joey Hess 2014-03-13 19:30:13 -04:00
parent b63276309e
commit 8e2997aa69
3 changed files with 6 additions and 4 deletions

View file

@ -9,7 +9,6 @@
module Annex.Ssh ( module Annex.Ssh (
sshCachingOptions, sshCachingOptions,
sshCleanup,
sshCacheDir, sshCacheDir,
sshReadPort, sshReadPort,
) where ) where
@ -24,6 +23,7 @@ import qualified Build.SysConfig as SysConfig
import qualified Annex import qualified Annex
import Config import Config
import Utility.Env import Utility.Env
import Types.CleanupActions
#ifndef mingw32_HOST_OS #ifndef mingw32_HOST_OS
import Annex.Perms import Annex.Perms
#endif #endif
@ -31,7 +31,9 @@ import Annex.Perms
{- 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. -}
sshCachingOptions :: (String, Maybe Integer) -> [CommandParam] -> Annex [CommandParam] sshCachingOptions :: (String, Maybe Integer) -> [CommandParam] -> Annex [CommandParam]
sshCachingOptions (host, port) opts = go =<< sshInfo (host, port) sshCachingOptions (host, port) opts = do
Annex.addCleanup SshCachingCleanup sshCleanup
go =<< sshInfo (host, port)
where where
go (Nothing, params) = ret params go (Nothing, params) = ret params
go (Just socketfile, params) = do go (Just socketfile, params) = do
@ -146,6 +148,7 @@ sshCleanup = go =<< sshCacheDir
[ Params "-O stop" [ Params "-O stop"
] ++ params ++ [Param "any"]) ] ++ params ++ [Param "any"])
{ cwd = Just dir } { cwd = Just dir }
liftIO $ nukeFile socketfile
-- Cannot remove the lock file; other processes may -- Cannot remove the lock file; other processes may
-- be waiting on our exclusive lock to use it. -- be waiting on our exclusive lock to use it.

View file

@ -26,7 +26,6 @@ import qualified Annex
import qualified Git import qualified Git
import qualified Git.AutoCorrect import qualified Git.AutoCorrect
import Annex.Content import Annex.Content
import Annex.Ssh
import Annex.Environment import Annex.Environment
import Command import Command
import Types.Messages import Types.Messages
@ -107,4 +106,3 @@ shutdown nocommit = do
saveState nocommit saveState nocommit
sequence_ =<< M.elems <$> Annex.getState Annex.cleanup sequence_ =<< M.elems <$> Annex.getState Annex.cleanup
liftIO reapZombies -- zombies from long-running git processes liftIO reapZombies -- zombies from long-running git processes
sshCleanup -- ssh connection caching

View file

@ -13,4 +13,5 @@ data CleanupAction
= RemoteCleanup UUID = RemoteCleanup UUID
| StopHook UUID | StopHook UUID
| FsckCleanup | FsckCleanup
| SshCachingCleanup
deriving (Eq, Ord) deriving (Eq, Ord)