]> arthur.barton.de Git - bup.git/commitdiff
bup: make sure stdout and stderr are binary for subcmds
authorRob Browning <rlb@defaultvalue.org>
Tue, 24 Dec 2019 18:49:12 +0000 (12:49 -0600)
committerRob Browning <rlb@defaultvalue.org>
Sat, 11 Jan 2020 20:39:27 +0000 (14:39 -0600)
Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
cmd/bup
lib/bup/io.py [new file with mode: 0644]

diff --git a/cmd/bup b/cmd/bup
index 4b5097d5a2cf7b2c2801b3fe665844ea9baa57a0..8c78570dcb7e75b5fe58dc4bd4337cdbee5ea8d4 100755 (executable)
--- a/cmd/bup
+++ b/cmd/bup
@@ -25,12 +25,12 @@ if sys.version_info[0] != 2 \
     sys.exit(2)
 
 from subprocess import PIPE
-from sys import stderr, stdout
 import select
 
 from bup import compat, path, helpers
 from bup.compat import add_ex_tb, add_ex_ctx, wrap_main
 from bup.helpers import atoi, columnate, debug1, log, merge_dict, tty_width
+from bup.io import byte_stream
 
 cmdpath = path.cmddir()
 
@@ -222,11 +222,15 @@ def run_subcmd(subcmd):
     if not (fix_stdout or fix_stderr):
         os.execvp(c[0], c)
 
+    sys.stdout.flush()
+    sys.stderr.flush()
+    out = byte_stream(sys.stdout)
+    err = byte_stream(sys.stderr)
     p = None
     try:
         p = subprocess.Popen(c,
-                             stdout=PIPE if fix_stdout else sys.stdout,
-                             stderr=PIPE if fix_stderr else sys.stderr,
+                             stdout=PIPE if fix_stdout else out,
+                             stderr=PIPE if fix_stderr else err,
                              env=tty_env, bufsize=4096, close_fds=True)
         # Assume p will receive these signals and quit, which will
         # then cause us to quit.
@@ -235,8 +239,8 @@ def run_subcmd(subcmd):
 
         filter_output(fix_stdout and p.stdout.fileno() or None,
                       fix_stderr and p.stderr.fileno() or None,
-                      fix_stdout and sys.stdout.fileno() or None,
-                      fix_stderr and sys.stderr.fileno() or None)
+                      fix_stdout and out.fileno() or None,
+                      fix_stderr and err.fileno() or None)
         return p.wait()
     except BaseException as ex:
         add_ex_tb(ex)
diff --git a/lib/bup/io.py b/lib/bup/io.py
new file mode 100644 (file)
index 0000000..6f4cca7
--- /dev/null
@@ -0,0 +1,12 @@
+
+from __future__ import absolute_import, print_function
+
+from bup import compat
+
+
+if compat.py_maj > 2:
+    def byte_stream(file):
+        return file.buffer
+else:
+    def byte_stream(file):
+        return file