]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/main.py
PackWriter._end: always try to release objcache and parentfd
[bup.git] / lib / bup / main.py
index 0c21c88f57037d48fa1a35e7c25af723bbafe7c4..4adae0b69fbddf4dc8c9714128d61cbb6745b851 100755 (executable)
@@ -31,7 +31,6 @@ from bup.helpers import (
     columnate,
     handle_ctrl_c,
     log,
-    merge_dict,
     tty_width
 )
 from bup.git import close_catpipes
@@ -193,18 +192,16 @@ if not cmd_module:
 
 already_fixed = int(environ.get(b'BUP_FORCE_TTY', 0))
 if subcmd_name in [b'mux', b'ftp', b'help']:
-    already_fixed = True
-fix_stdout = not already_fixed and os.isatty(1)
-fix_stderr = not already_fixed and os.isatty(2)
+    fix_stdout = False
+    fix_stderr = False
+else:
+    fix_stdout = not (already_fixed & 1) and os.isatty(1)
+    fix_stderr = not (already_fixed & 2) and os.isatty(2)
 
 if fix_stdout or fix_stderr:
-    tty_env = merge_dict(environ,
-                         {b'BUP_FORCE_TTY': (b'%d'
-                                             % ((fix_stdout and 1 or 0)
-                                                + (fix_stderr and 2 or 0))),
-                          b'BUP_TTY_WIDTH': b'%d' % _tty_width(), })
-else:
-    tty_env = environ
+    _ttymask = (fix_stdout and 1 or 0) + (fix_stderr and 2 or 0)
+    environ[b'BUP_FORCE_TTY'] = b'%d' % _ttymask
+    environ[b'BUP_TTY_WIDTH'] = b'%d' % _tty_width()
 
 
 sep_rx = re.compile(br'([\r\n])')
@@ -224,7 +221,7 @@ def print_clean_line(dest, content, width, sep=None):
         assert not sep_rx.match(x)
     content = b''.join(content)
     if sep == b'\r' and len(content) > width:
-        content = content[width:]
+        content = content[:width]
     os.write(dest, content)
     if len(content) < width:
         os.write(dest, b' ' * (width - len(content)))
@@ -382,7 +379,7 @@ def run_subproc_cmd(args):
         p = subprocess.Popen(c,
                              stdout=PIPE if fix_stdout else out,
                              stderr=PIPE if fix_stderr else err,
-                             env=tty_env, bufsize=4096, close_fds=True)
+                             bufsize=4096, close_fds=True)
         # Assume p will receive these signals and quit, which will
         # then cause us to quit.
         for sig in (signal.SIGINT, signal.SIGTERM, signal.SIGQUIT):