refactor
This commit is contained in:
parent
74f937cc55
commit
a66c942645
2 changed files with 13 additions and 24 deletions
|
@ -334,7 +334,7 @@ showSshErr msg = sshConfigurator $
|
||||||
- is no controlling terminal. On Unix, that is set up when the assistant
|
- is no controlling terminal. On Unix, that is set up when the assistant
|
||||||
- starts, by calling createSession. On Windows, all of stdin, stdout, and
|
- starts, by calling createSession. On Windows, all of stdin, stdout, and
|
||||||
- stderr must be disconnected from the terminal. This is accomplished
|
- stderr must be disconnected from the terminal. This is accomplished
|
||||||
- by always providing an empty input string on stdin.
|
- by always providing input on stdin.
|
||||||
-}
|
-}
|
||||||
sshAuthTranscript :: SshInput -> [String] -> (Maybe String) -> Assistant (String, Bool)
|
sshAuthTranscript :: SshInput -> [String] -> (Maybe String) -> Assistant (String, Bool)
|
||||||
sshAuthTranscript sshinput opts input = case inputAuthMethod sshinput of
|
sshAuthTranscript sshinput opts input = case inputAuthMethod sshinput of
|
||||||
|
|
|
@ -167,10 +167,10 @@ processTranscript :: String -> [String] -> (Maybe String) -> IO (String, Bool)
|
||||||
processTranscript cmd opts input = processTranscript' cmd opts Nothing input
|
processTranscript cmd opts input = processTranscript' cmd opts Nothing input
|
||||||
|
|
||||||
processTranscript' :: String -> [String] -> Maybe [(String, String)] -> (Maybe String) -> IO (String, Bool)
|
processTranscript' :: String -> [String] -> Maybe [(String, String)] -> (Maybe String) -> IO (String, Bool)
|
||||||
|
processTranscript' cmd opts environ input = do
|
||||||
#ifndef mingw32_HOST_OS
|
#ifndef mingw32_HOST_OS
|
||||||
{- This implementation interleves stdout and stderr in exactly the order
|
{- This implementation interleves stdout and stderr in exactly the order
|
||||||
- the process writes them. -}
|
- the process writes them. -}
|
||||||
processTranscript' cmd opts environ input = do
|
|
||||||
(readf, writef) <- createPipe
|
(readf, writef) <- createPipe
|
||||||
readh <- fdToHandle readf
|
readh <- fdToHandle readf
|
||||||
writeh <- fdToHandle writef
|
writeh <- fdToHandle writef
|
||||||
|
@ -184,24 +184,13 @@ processTranscript' cmd opts environ input = do
|
||||||
hClose writeh
|
hClose writeh
|
||||||
|
|
||||||
get <- mkreader readh
|
get <- mkreader readh
|
||||||
|
writeinput input p
|
||||||
-- now write and flush any input
|
|
||||||
case input of
|
|
||||||
Just s -> do
|
|
||||||
let inh = stdinHandle p
|
|
||||||
unless (null s) $ do
|
|
||||||
hPutStr inh s
|
|
||||||
hFlush inh
|
|
||||||
hClose inh
|
|
||||||
Nothing -> return ()
|
|
||||||
|
|
||||||
transcript <- get
|
transcript <- get
|
||||||
|
|
||||||
ok <- checkSuccessProcess pid
|
ok <- checkSuccessProcess pid
|
||||||
return (transcript, ok)
|
return (transcript, ok)
|
||||||
#else
|
#else
|
||||||
{- This implementation for Windows puts stderr after stdout. -}
|
{- This implementation for Windows puts stderr after stdout. -}
|
||||||
processTranscript' cmd opts environ input = do
|
|
||||||
p@(_, _, _, pid) <- createProcess $
|
p@(_, _, _, pid) <- createProcess $
|
||||||
(proc cmd opts)
|
(proc cmd opts)
|
||||||
{ std_in = if isJust input then CreatePipe else Inherit
|
{ std_in = if isJust input then CreatePipe else Inherit
|
||||||
|
@ -212,17 +201,9 @@ processTranscript' cmd opts environ input = do
|
||||||
|
|
||||||
getout <- mkreader (stdoutHandle p)
|
getout <- mkreader (stdoutHandle p)
|
||||||
geterr <- mkreader (stderrHandle p)
|
geterr <- mkreader (stderrHandle p)
|
||||||
|
writeinput input p
|
||||||
case input of
|
|
||||||
Just s -> do
|
|
||||||
let inh = stdinHandle p
|
|
||||||
unless (null s) $ do
|
|
||||||
hPutStr inh s
|
|
||||||
hFlush inh
|
|
||||||
hClose inh
|
|
||||||
Nothing -> return ()
|
|
||||||
|
|
||||||
transcript <- (++) <$> getout <*> geterr
|
transcript <- (++) <$> getout <*> geterr
|
||||||
|
|
||||||
ok <- checkSuccessProcess pid
|
ok <- checkSuccessProcess pid
|
||||||
return (transcript, ok)
|
return (transcript, ok)
|
||||||
#endif
|
#endif
|
||||||
|
@ -237,6 +218,14 @@ processTranscript' cmd opts environ input = do
|
||||||
takeMVar v
|
takeMVar v
|
||||||
return s
|
return s
|
||||||
|
|
||||||
|
writeinput (Just s) p = do
|
||||||
|
let inh = stdinHandle p
|
||||||
|
unless (null s) $ do
|
||||||
|
hPutStr inh s
|
||||||
|
hFlush inh
|
||||||
|
hClose inh
|
||||||
|
writeinput Nothing _ = return ()
|
||||||
|
|
||||||
{- Runs a CreateProcessRunner, on a CreateProcess structure, that
|
{- Runs a CreateProcessRunner, on a CreateProcess structure, that
|
||||||
- is adjusted to pipe only from/to a single StdHandle, and passes
|
- is adjusted to pipe only from/to a single StdHandle, and passes
|
||||||
- the resulting Handle to an action. -}
|
- the resulting Handle to an action. -}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue