]> arthur.barton.de Git - bup.git/commitdiff
main: don't lose line prefixes in filter_output
authorNathaniel Filardo <nwf20@cl.cam.ac.uk>
Sun, 18 Aug 2019 16:45:53 +0000 (11:45 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sun, 18 Aug 2019 17:24:49 +0000 (12:24 -0500)
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 <nwf20@cl.cam.ac.uk>
[rlb@defaultvalue.org: adjust commit summary and remove extra space in
 "if split[0]" guard.]
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
main.py

diff --git a/main.py b/main.py
index c0679e32919fa0a6b721ce70bd4eed8add70dcc4..7f632beaa997f0a7dd6bbff8066f32f4b80dff96 100755 (executable)
--- 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)