finish conversion to hGetLineUntilExitOrEOF

started in aafae46bcb
This commit is contained in:
Joey Hess 2020-11-18 14:54:02 -04:00
parent 7ec22489da
commit e6d741af79
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 14 additions and 16 deletions

View file

@ -290,12 +290,11 @@ commandMeterExitCode' progressparser oh mmeter meterupdate cmd params mkprocess
meterupdate bytes meterupdate bytes
feedprogress sendtotalsize' bytes buf' h feedprogress sendtotalsize' bytes buf' h
handlestderr ph h = unlessM (hIsEOF h) $ do handlestderr ph h = hGetLineUntilExitOrEOF ph h >>= \case
cancelOnExit ph (hGetLine h) >>= \case Just l -> do
Just l -> do stderrHandler oh l
stderrHandler oh l handlestderr ph h
handlestderr ph h Nothing -> return ()
Nothing -> return ()
{- Runs a command, that may display one or more progress meters on {- Runs a command, that may display one or more progress meters on
- either stdout or stderr, and prevents the meters from being displayed. - 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). - beginning of the line when updating a progress display).
-} -}
avoidProgress :: Bool -> ProcessHandle -> Handle -> (String -> IO ()) -> IO () avoidProgress :: Bool -> ProcessHandle -> Handle -> (String -> IO ()) -> IO ()
avoidProgress doavoid ph h emitter = unlessM (hIsEOF h) $ avoidProgress doavoid ph h emitter = hGetLineUntilExitOrEOF ph h >>= \case
cancelOnExit ph (hGetLine h) >>= \case Just s -> do
Just s -> do unless (doavoid && '\r' `elem` s) $
unless (doavoid && '\r' `elem` s) $ emitter s
emitter s avoidProgress doavoid ph h emitter
avoidProgress doavoid ph h emitter Nothing -> return ()
Nothing -> return ()
outputFilter outputFilter
:: FilePath :: FilePath

View file

@ -231,9 +231,9 @@ cleanupProcess (mb_stdin, mb_stdout, mb_stderr, pid) = do
void $ waitForProcess pid void $ waitForProcess pid
#endif #endif
{- | Like hGetLine, reads a line from the Handle. If the Handle is already {- | Like hGetLine, reads a line from the Handle. Returns Nothing if end of
- closed, returns Nothing. If the process exits without writing a line, - file is reached, or if the process has exited and there is nothing more
- also returns Nothing. - buffered to read from the handle.
- -
- This is useful to protect against situations where the process might - This is useful to protect against situations where the process might
- have transferred the handle being read to another process, and so - have transferred the handle being read to another process, and so