From: Nathaniel Filardo Date: Sun, 18 Aug 2019 16:45:53 +0000 (-0500) Subject: main: don't lose line prefixes in filter_output X-Git-Tag: 0.30~21 X-Git-Url: https://arthur.barton.de/gitweb/?p=bup.git;a=commitdiff_plain;h=afd3ffec3570ee1c0f471bd9399568a9892d076b main: don't lose line prefixes in filter_output If the watched process ends a push to the pipe without a newline at the end, but with newlines in the middle, then sep_rx.split() will return with multiple entries, the last of which will not end with a newline and yet not be the empty string. This line prefix needs to be stashed into the pending buffer, too. This turns out to be exactly the same logic as if sep_rx.split had not split the string, so eliminate one layer of conditionals. This version incorporates feedback from Rob Browning to continue to pass a list to extend(). Signed-off-by: Nathaniel Filardo [rlb@defaultvalue.org: adjust commit summary and remove extra space in "if split[0]" guard.] Reviewed-by: Rob Browning Tested-by: Rob Browning --- diff --git a/main.py b/main.py index c0679e3..7f632be 100755 --- a/main.py +++ b/main.py @@ -204,16 +204,15 @@ def filter_output(src_out, src_err, dest_out, dest_err): print_clean_line(dest, pending.pop(fd, []), width) else: split = sep_rx.split(buf) - if len(split) > 2: - while len(split) > 1: - content, sep = split[:2] - split = split[2:] - print_clean_line(dest, - pending.pop(fd, []) + [content], - width, - sep) - else: - assert(len(split) == 1) + while len(split) > 1: + content, sep = split[:2] + split = split[2:] + print_clean_line(dest, + pending.pop(fd, []) + [content], + width, + sep) + assert(len(split) == 1) + if split[0]: pending.setdefault(fd, []).extend(split) except BaseException as ex: pending_ex = chain_ex(add_ex_tb(ex), pending_ex)