From: Joey Hess Date: Mon, 26 Sep 2022 19:26:29 +0000 (-0400) Subject: fix breakage in wormhole's sendFile X-Git-Tag: archive/raspbian/10.20250416-2+rpi1~1^2~69^2~35 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=f1c85ac11b3b7004bf1b1917f9c504622d15e1aa;p=git-annex.git fix breakage in wormhole's sendFile Commit ff0927bde98e7b7fd4a7ef49b61b8770c6df294d broke this, it made it try to read all of the input before looking for the code. But, wormhole keeps running until it sends the file, so that caused a deadlock. Oops. Sponsored-by: Luke Shumaker on Patreon --- diff --git a/Utility/MagicWormhole.hs b/Utility/MagicWormhole.hs index a4128d1d5c..8aa950ef7d 100644 --- a/Utility/MagicWormhole.hs +++ b/Utility/MagicWormhole.hs @@ -120,16 +120,21 @@ sendFile f (CodeObserver observer) ps = do return (inout || inerr) where p = wormHoleProcess (ps ++ [Param "send", File f]) - findcode ph h = findcode' =<< getwords ph h [] + findcode ph h = hGetLineUntilExitOrEOF ph h >>= \case + Nothing -> return False + Just l -> ifM (findcode' (words l)) + ( drain ph h >> return True + , findcode ph h + ) findcode' [] = return False findcode' (w:ws) = case mkCode w of Just code -> do _ <- tryPutMVar observer code return True Nothing -> findcode' ws - getwords ph h c = hGetLineUntilExitOrEOF ph h >>= \case - Nothing -> return $ concatMap words $ reverse c - Just l -> getwords ph h (l:c) + drain ph h = hGetLineUntilExitOrEOF ph h >>= \case + Just _ -> drain ph h + Nothing -> return () -- | Receives a file. Once the receive is under way, the Code will be -- read from the CodeProducer, and fed to wormhole on stdin.