avoid no longer necessary piping of ssh stderr for p2pstdio
This was needed when supporting old git-annex-shell that do not support p2pstdio yet, in order to cleanly fall back to the old interface without error messages being displayed. That is no longer supported, so simplify to not intercept error messages. Sponsored-by: Dartmouth College's DANDI project
This commit is contained in:
parent
63d5c6f2c8
commit
19b87f7396
1 changed files with 8 additions and 35 deletions
|
@ -1,6 +1,6 @@
|
||||||
{- git-annex remote access with ssh and git-annex-shell
|
{- git-annex remote access with ssh and git-annex-shell
|
||||||
-
|
-
|
||||||
- Copyright 2011-2018 Joey Hess <id@joeyh.name>
|
- Copyright 2011-2022 Joey Hess <id@joeyh.name>
|
||||||
-
|
-
|
||||||
- Licensed under the GNU AGPL version 3 or higher.
|
- Licensed under the GNU AGPL version 3 or higher.
|
||||||
-}
|
-}
|
||||||
|
@ -27,7 +27,6 @@ import qualified P2P.IO as P2P
|
||||||
import qualified P2P.Annex as P2P
|
import qualified P2P.Annex as P2P
|
||||||
|
|
||||||
import Control.Concurrent.STM
|
import Control.Concurrent.STM
|
||||||
import Control.Concurrent.Async
|
|
||||||
|
|
||||||
toRepo :: ConsumeStdin -> Git.Repo -> RemoteGitConfig -> SshCommand -> Annex (FilePath, [CommandParam])
|
toRepo :: ConsumeStdin -> Git.Repo -> RemoteGitConfig -> SshCommand -> Annex (FilePath, [CommandParam])
|
||||||
toRepo cs r gc remotecmd = do
|
toRepo cs r gc remotecmd = do
|
||||||
|
@ -178,18 +177,15 @@ rsyncParams r direction = do
|
||||||
gc = gitconfig r
|
gc = gitconfig r
|
||||||
|
|
||||||
-- A connection over ssh to git-annex shell speaking the P2P protocol.
|
-- A connection over ssh to git-annex shell speaking the P2P protocol.
|
||||||
type P2PSshConnection = P2P.ClosableConnection
|
type P2PSshConnection = P2P.ClosableConnection
|
||||||
(P2P.RunState, P2P.P2PConnection, ProcessHandle, TVar StderrHandlerState)
|
(P2P.RunState, P2P.P2PConnection, ProcessHandle)
|
||||||
|
|
||||||
data StderrHandlerState = DiscardStderr | DisplayStderr | EndStderrHandler
|
|
||||||
|
|
||||||
closeP2PSshConnection :: P2PSshConnection -> IO (P2PSshConnection, Maybe ExitCode)
|
closeP2PSshConnection :: P2PSshConnection -> IO (P2PSshConnection, Maybe ExitCode)
|
||||||
closeP2PSshConnection P2P.ClosedConnection = return (P2P.ClosedConnection, Nothing)
|
closeP2PSshConnection P2P.ClosedConnection = return (P2P.ClosedConnection, Nothing)
|
||||||
closeP2PSshConnection (P2P.OpenConnection (_st, conn, pid, stderrhandlerst)) =
|
closeP2PSshConnection (P2P.OpenConnection (_st, conn, pid)) =
|
||||||
-- mask async exceptions, avoid cleanup being interrupted
|
-- mask async exceptions, avoid cleanup being interrupted
|
||||||
uninterruptibleMask_ $ do
|
uninterruptibleMask_ $ do
|
||||||
P2P.closeConnection conn
|
P2P.closeConnection conn
|
||||||
atomically $ writeTVar stderrhandlerst EndStderrHandler
|
|
||||||
exitcode <- waitForProcess pid
|
exitcode <- waitForProcess pid
|
||||||
return (P2P.ClosedConnection, Just exitcode)
|
return (P2P.ClosedConnection, Just exitcode)
|
||||||
|
|
||||||
|
@ -244,11 +240,10 @@ openP2PSshConnection r connpool = do
|
||||||
Just (cmd, params) -> start cmd params =<< getRepo r
|
Just (cmd, params) -> start cmd params =<< getRepo r
|
||||||
where
|
where
|
||||||
start cmd params repo = liftIO $ do
|
start cmd params repo = liftIO $ do
|
||||||
(Just from, Just to, Just err, pid) <- createProcess $
|
(Just from, Just to, Nothing, pid) <- createProcess $
|
||||||
(proc cmd (toCommand params))
|
(proc cmd (toCommand params))
|
||||||
{ std_in = CreatePipe
|
{ std_in = CreatePipe
|
||||||
, std_out = CreatePipe
|
, std_out = CreatePipe
|
||||||
, std_err = CreatePipe
|
|
||||||
}
|
}
|
||||||
pidnum <- getPid pid
|
pidnum <- getPid pid
|
||||||
let conn = P2P.P2PConnection
|
let conn = P2P.P2PConnection
|
||||||
|
@ -259,17 +254,14 @@ openP2PSshConnection r connpool = do
|
||||||
, P2P.connIdent = P2P.ConnIdent $
|
, P2P.connIdent = P2P.ConnIdent $
|
||||||
Just $ "ssh connection " ++ show pidnum
|
Just $ "ssh connection " ++ show pidnum
|
||||||
}
|
}
|
||||||
stderrhandlerst <- newStderrHandler err pid
|
|
||||||
runst <- P2P.mkRunState P2P.Client
|
runst <- P2P.mkRunState P2P.Client
|
||||||
let c = P2P.OpenConnection (runst, conn, pid, stderrhandlerst)
|
let c = P2P.OpenConnection (runst, conn, pid)
|
||||||
-- When the connection is successful, the remote
|
-- When the connection is successful, the remote
|
||||||
-- will send an AUTH_SUCCESS with its uuid.
|
-- will send an AUTH_SUCCESS with its uuid.
|
||||||
let proto = P2P.postAuth $
|
let proto = P2P.postAuth $
|
||||||
P2P.negotiateProtocolVersion P2P.maxProtocolVersion
|
P2P.negotiateProtocolVersion P2P.maxProtocolVersion
|
||||||
tryNonAsync (P2P.runNetProto runst conn proto) >>= \case
|
tryNonAsync (P2P.runNetProto runst conn proto) >>= \case
|
||||||
Right (Right (Just theiruuid)) | theiruuid == uuid r -> do
|
Right (Right (Just theiruuid)) | theiruuid == uuid r ->
|
||||||
atomically $
|
|
||||||
writeTVar stderrhandlerst DisplayStderr
|
|
||||||
return $ Just c
|
return $ Just c
|
||||||
_ -> do
|
_ -> do
|
||||||
(cclosed, exitcode) <- closeP2PSshConnection c
|
(cclosed, exitcode) <- closeP2PSshConnection c
|
||||||
|
@ -284,25 +276,6 @@ openP2PSshConnection r connpool = do
|
||||||
modifyTVar' connpool $
|
modifyTVar' connpool $
|
||||||
maybe (Just P2PSshUnsupported) Just
|
maybe (Just P2PSshUnsupported) Just
|
||||||
|
|
||||||
newStderrHandler :: Handle -> ProcessHandle -> IO (TVar StderrHandlerState)
|
|
||||||
newStderrHandler errh ph = do
|
|
||||||
-- stderr from git-annex-shell p2pstdio is initially discarded
|
|
||||||
-- because old versions don't support the command. Once it's known
|
|
||||||
-- to be running, this is changed to DisplayStderr.
|
|
||||||
v <- newTVarIO DiscardStderr
|
|
||||||
void $ async $ go v
|
|
||||||
return v
|
|
||||||
where
|
|
||||||
go v = do
|
|
||||||
hGetLineUntilExitOrEOF ph errh >>= \case
|
|
||||||
Nothing -> hClose errh
|
|
||||||
Just l -> atomically (readTVar v) >>= \case
|
|
||||||
DiscardStderr -> go v
|
|
||||||
DisplayStderr -> do
|
|
||||||
hPutStrLn stderr l
|
|
||||||
go v
|
|
||||||
EndStderrHandler -> hClose errh
|
|
||||||
|
|
||||||
-- Runs a P2P Proto action on a remote when it supports that,
|
-- Runs a P2P Proto action on a remote when it supports that,
|
||||||
-- otherwise the fallback action.
|
-- otherwise the fallback action.
|
||||||
runProto :: Remote -> P2PSshConnectionPool -> Annex a -> P2P.Proto a -> Annex (Maybe a)
|
runProto :: Remote -> P2PSshConnectionPool -> Annex a -> P2P.Proto a -> Annex (Maybe a)
|
||||||
|
@ -319,7 +292,7 @@ runProto r connpool onerr proto = Just <$>
|
||||||
|
|
||||||
runProtoConn :: P2P.Proto a -> P2PSshConnection -> Annex (P2PSshConnection, Maybe a)
|
runProtoConn :: P2P.Proto a -> P2PSshConnection -> Annex (P2PSshConnection, Maybe a)
|
||||||
runProtoConn _ P2P.ClosedConnection = return (P2P.ClosedConnection, Nothing)
|
runProtoConn _ P2P.ClosedConnection = return (P2P.ClosedConnection, Nothing)
|
||||||
runProtoConn a conn@(P2P.OpenConnection (runst, c, _, _)) = do
|
runProtoConn a conn@(P2P.OpenConnection (runst, c, _)) = do
|
||||||
P2P.runFullProto runst c a >>= \case
|
P2P.runFullProto runst c a >>= \case
|
||||||
Right r -> return (conn, Just r)
|
Right r -> return (conn, Just r)
|
||||||
-- When runFullProto fails, the connection is no longer
|
-- When runFullProto fails, the connection is no longer
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue