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:
Joey Hess 2022-01-03 12:54:40 -04:00
parent 63d5c6f2c8
commit 19b87f7396
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38

View file

@ -1,6 +1,6 @@
{- 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.
-}
@ -27,7 +27,6 @@ import qualified P2P.IO as P2P
import qualified P2P.Annex as P2P
import Control.Concurrent.STM
import Control.Concurrent.Async
toRepo :: ConsumeStdin -> Git.Repo -> RemoteGitConfig -> SshCommand -> Annex (FilePath, [CommandParam])
toRepo cs r gc remotecmd = do
@ -178,18 +177,15 @@ rsyncParams r direction = do
gc = gitconfig r
-- A connection over ssh to git-annex shell speaking the P2P protocol.
type P2PSshConnection = P2P.ClosableConnection
(P2P.RunState, P2P.P2PConnection, ProcessHandle, TVar StderrHandlerState)
data StderrHandlerState = DiscardStderr | DisplayStderr | EndStderrHandler
type P2PSshConnection = P2P.ClosableConnection
(P2P.RunState, P2P.P2PConnection, ProcessHandle)
closeP2PSshConnection :: P2PSshConnection -> IO (P2PSshConnection, Maybe ExitCode)
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
uninterruptibleMask_ $ do
P2P.closeConnection conn
atomically $ writeTVar stderrhandlerst EndStderrHandler
exitcode <- waitForProcess pid
return (P2P.ClosedConnection, Just exitcode)
@ -244,11 +240,10 @@ openP2PSshConnection r connpool = do
Just (cmd, params) -> start cmd params =<< getRepo r
where
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))
{ std_in = CreatePipe
, std_out = CreatePipe
, std_err = CreatePipe
}
pidnum <- getPid pid
let conn = P2P.P2PConnection
@ -259,17 +254,14 @@ openP2PSshConnection r connpool = do
, P2P.connIdent = P2P.ConnIdent $
Just $ "ssh connection " ++ show pidnum
}
stderrhandlerst <- newStderrHandler err pid
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
-- will send an AUTH_SUCCESS with its uuid.
let proto = P2P.postAuth $
P2P.negotiateProtocolVersion P2P.maxProtocolVersion
tryNonAsync (P2P.runNetProto runst conn proto) >>= \case
Right (Right (Just theiruuid)) | theiruuid == uuid r -> do
atomically $
writeTVar stderrhandlerst DisplayStderr
Right (Right (Just theiruuid)) | theiruuid == uuid r ->
return $ Just c
_ -> do
(cclosed, exitcode) <- closeP2PSshConnection c
@ -284,25 +276,6 @@ openP2PSshConnection r connpool = do
modifyTVar' connpool $
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,
-- otherwise the fallback action.
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.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
Right r -> return (conn, Just r)
-- When runFullProto fails, the connection is no longer