summaryrefslogtreecommitdiff
path: root/Messages.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2017-05-11 17:33:18 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2017-05-11 17:36:03 -0400
commita087841ae775a14197c1550488f54b5761f4700b (patch)
tree93b0c8f09107395bd58f9dc7210b8ee0817cf20d /Messages.hs
parentb09ac870e1dd2bc924c2ab4cd1d2280024a8a80a (diff)
Ssh password prompting improved when using -J
When ssh connection caching is enabled (and when GIT_ANNEX_USE_GIT_SSH is not set), only one ssh password prompt will be made per host, and only one ssh password prompt will be made at a time. This also fixes a race in prepSocket's stale ssh connection stopping when run with -J. It was possible for one thread to start a cached ssh connection, and another thread to immediately stop it, resulting in excess connections being made. This commit was supported by the NSF-funded DataLad project.
Diffstat (limited to 'Messages.hs')
-rw-r--r--Messages.hs16
1 files changed, 15 insertions, 1 deletions
diff --git a/Messages.hs b/Messages.hs
index 0036e5759..f3c44aebf 100644
--- a/Messages.hs
+++ b/Messages.hs
@@ -1,6 +1,6 @@
{- git-annex output messages
-
- - Copyright 2010-2016 Joey Hess <id@joeyh.name>
+ - Copyright 2010-2017 Joey Hess <id@joeyh.name>
-
- Licensed under the GNU GPL version 3 or higher.
-}
@@ -41,12 +41,14 @@ module Messages (
outputMessage,
implicitMessage,
withMessageState,
+ prompt,
) where
import System.Log.Logger
import System.Log.Formatter
import System.Log.Handler (setFormatter)
import System.Log.Handler.Simple
+import Control.Concurrent
import Common
import Types
@@ -219,3 +221,15 @@ commandProgressDisabled = withMessageState $ \s -> return $
- output. -}
implicitMessage :: Annex () -> Annex ()
implicitMessage = whenM (implicitMessages <$> Annex.getState Annex.output)
+
+{- Prevents any concurrent console access while running an action, so
+ - that the action is the only thing using the console, and can eg prompt
+ - the user.
+ -}
+prompt :: (MessageState -> Annex a) -> Annex a
+prompt a = withMessageState $ \s ->
+ if concurrentOutputEnabled s
+ then
+ let l = promptLock s
+ in bracketIO (takeMVar l) (putMVar l) (const (a s))
+ else a s