From e6d741af79b04f9c2c09f73eb28d91f924c6d291 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Wed, 18 Nov 2020 14:54:02 -0400 Subject: [PATCH] finish conversion to hGetLineUntilExitOrEOF started in aafae46bcbb2a9533364b65be5fc05b379898aa1 --- Utility/Metered.hs | 24 +++++++++++------------- Utility/Process.hs | 6 +++--- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Utility/Metered.hs b/Utility/Metered.hs index d39e39bfaf..888e7e1416 100644 --- a/Utility/Metered.hs +++ b/Utility/Metered.hs @@ -290,12 +290,11 @@ commandMeterExitCode' progressparser oh mmeter meterupdate cmd params mkprocess meterupdate bytes feedprogress sendtotalsize' bytes buf' h - handlestderr ph h = unlessM (hIsEOF h) $ do - cancelOnExit ph (hGetLine h) >>= \case - Just l -> do - stderrHandler oh l - handlestderr ph h - Nothing -> return () + handlestderr ph h = hGetLineUntilExitOrEOF ph h >>= \case + Just l -> do + stderrHandler oh l + handlestderr ph h + Nothing -> return () {- Runs a command, that may display one or more progress meters on - either stdout or stderr, and prevents the meters from being displayed. @@ -323,13 +322,12 @@ demeterCommandEnv oh cmd params environ = do - beginning of the line when updating a progress display). -} avoidProgress :: Bool -> ProcessHandle -> Handle -> (String -> IO ()) -> IO () -avoidProgress doavoid ph h emitter = unlessM (hIsEOF h) $ - cancelOnExit ph (hGetLine h) >>= \case - Just s -> do - unless (doavoid && '\r' `elem` s) $ - emitter s - avoidProgress doavoid ph h emitter - Nothing -> return () +avoidProgress doavoid ph h emitter = hGetLineUntilExitOrEOF ph h >>= \case + Just s -> do + unless (doavoid && '\r' `elem` s) $ + emitter s + avoidProgress doavoid ph h emitter + Nothing -> return () outputFilter :: FilePath diff --git a/Utility/Process.hs b/Utility/Process.hs index 7552264710..1348e9ee92 100644 --- a/Utility/Process.hs +++ b/Utility/Process.hs @@ -231,9 +231,9 @@ cleanupProcess (mb_stdin, mb_stdout, mb_stderr, pid) = do void $ waitForProcess pid #endif -{- | Like hGetLine, reads a line from the Handle. If the Handle is already - - closed, returns Nothing. If the process exits without writing a line, - - also returns Nothing. +{- | Like hGetLine, reads a line from the Handle. Returns Nothing if end of + - file is reached, or if the process has exited and there is nothing more + - buffered to read from the handle. - - This is useful to protect against situations where the process might - have transferred the handle being read to another process, and so