]> arthur.barton.de Git - bup.git/commitdiff
Bypass Python 3 glibc argv problems by routing args through env
authorRob Browning <rlb@defaultvalue.org>
Sun, 7 Jun 2020 14:05:26 +0000 (09:05 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sun, 5 Jul 2020 16:16:22 +0000 (11:16 -0500)
Until/unless https://sourceware.org/bugzilla/show_bug.cgi?id=26034 is
resolved by Python or GNU libc, sidestep the problem, which can crash
Python 3 during initialization, with a trivial sh wrapper that diverts
the command line arguments into BUP_ARGV_{0,1,2,...} environment
variables, since those can be safely retrieved.

Add compat.argvb and compat.argv and populate them at startup with the
BUP_ARGV_* values.  Adjust all the relevant commands to rely on those
vars instead of sys.argv.

Although the preamble say "rewritten during install", that's not in
place yet, but will be soon (when we drop LC_CTYPE and rework
bup-python).

Thanks to Johannes Berg for suggesting this, and help figuring out the
details.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
43 files changed:
lib/bup/compat.py
lib/cmd/bloom-cmd.py
lib/cmd/bup
lib/cmd/cat-file-cmd.py
lib/cmd/daemon-cmd.py
lib/cmd/damage-cmd.py
lib/cmd/drecurse-cmd.py
lib/cmd/fsck-cmd.py
lib/cmd/ftp-cmd.py
lib/cmd/fuse-cmd.py
lib/cmd/gc-cmd.py
lib/cmd/get-cmd.py
lib/cmd/help-cmd.py
lib/cmd/import-duplicity-cmd.py
lib/cmd/index-cmd.py
lib/cmd/init-cmd.py
lib/cmd/join-cmd.py
lib/cmd/list-idx-cmd.py
lib/cmd/ls-cmd.py
lib/cmd/margin-cmd.py
lib/cmd/memtest-cmd.py
lib/cmd/meta-cmd.py
lib/cmd/midx-cmd.py
lib/cmd/mux-cmd.py
lib/cmd/on--server-cmd.py
lib/cmd/on-cmd.py
lib/cmd/prune-older-cmd.py
lib/cmd/random-cmd.py
lib/cmd/restore-cmd.py
lib/cmd/rm-cmd.py
lib/cmd/save-cmd.py
lib/cmd/server-cmd.py
lib/cmd/split-cmd.py
lib/cmd/tag-cmd.py
lib/cmd/tick-cmd.py
lib/cmd/version-cmd.py
lib/cmd/web-cmd.py
lib/cmd/xstat-cmd.py
t/echo-argv-bytes
t/hardlink-sets
t/ns-timestamp-resolutions
t/test-argv
t/test-get

index f5819c281b220b7e6a3cfbc1edeb9e0c72134f2a..37b31f107806d08a37fdf094e0e415850253a4c7 100644 (file)
@@ -144,6 +144,41 @@ else:  # Python 2
     buffer = buffer
 
 
+argv = None
+argvb = None
+
+def _configure_argv():
+    global argv, argvb
+    assert not argv
+    assert not argvb
+    if len(sys.argv) > 1:
+        if environ.get(b'BUP_ARGV_0'):
+            print('error: BUP_ARGV* set and sys.argv not empty', file=sys.stderr)
+            sys.exit(2)
+        argv = sys.argv
+        argvb = [argv_bytes(x) for x in argv]
+        return
+    args = []
+    i = 0
+    arg = environ.get(b'BUP_ARGV_%d' % i)
+    while arg is not None:
+        args.append(arg)
+        i += 1
+        arg = environ.get(b'BUP_ARGV_%d' % i)
+    i -= 1
+    while i >= 0:
+        del environ[b'BUP_ARGV_%d' % i]
+        i -= 1
+    argvb = args
+    # System encoding?
+    if py3:
+        argv = [x.decode(errors='surrogateescape') for x in args]
+    else:
+        argv = argvb
+
+_configure_argv()
+
+
 def restore_lc_env():
     # Once we're up and running with iso-8859-1, undo the bup-python
     # LC_CTYPE hackery, so we don't affect unrelated subprocesses.
index d7537cafc2b9129b6339384107d58b95510a6e91..16d8f46d44d6ed3f6affd7bfbc2e019fee2b3419 100755 (executable)
@@ -1,14 +1,23 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import
 import glob, os, sys, tempfile
 
-from bup import options, git, bloom
+from bup import compat, options, git, bloom
 from bup.compat import argv_bytes, hexstr
 from bup.helpers import (add_error, debug1, handle_ctrl_c, log, progress, qprogress,
                          saved_errors)
@@ -146,7 +155,7 @@ def do_bloom(path, outfilename, k):
 handle_ctrl_c()
 
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 if extra:
     o.fatal('no positional parameters expected')
index 8f27c0faa8f35a85ecdc9b1aa0bf77ec6ae3394b..92807a50254ba244f904ff33628f4fde5bfbec8a 100755 (executable)
@@ -1,6 +1,16 @@
 #!/bin/sh
-"""": # -*-python-*- # -*-python-*-
+"""": # -*-python-*-
 set -e
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
+# Find our directory
 top="$(pwd)"
 cmdpath="$0"
 # loop because macos doesn't have recursive readlink/realpath utils
@@ -11,7 +21,7 @@ while test -L "$cmdpath"; do
 done
 script_home="$(cd "$(dirname "$cmdpath")" && pwd -P)"
 cd "$top"
-exec "$script_home/bup-python" "$0" ${1+"$@"}
+exec "$script_home/bup-python" "$0"
 """
 # end of bup preamble
 
@@ -78,14 +88,14 @@ def usage(msg=""):
         log("\n%s\n" % msg)
     sys.exit(99)
 
-
-if len(sys.argv) < 2:
+argv = compat.argv
+if len(argv) < 2:
     usage()
 
 # Handle global options.
 try:
     optspec = ['help', 'version', 'debug', 'profile', 'bup-dir=']
-    global_args, subcmd = getopt.getopt(sys.argv[1:], '?VDd:', optspec)
+    global_args, subcmd = getopt.getopt(argv[1:], '?VDd:', optspec)
 except getopt.GetoptError as ex:
     usage('error: %s' % ex.msg)
 
index 3f776a284d46f1ca83f8f31793c74f4d30b38ec0..849cb45667410882d034a904b6c00d0b263815e6 100755 (executable)
@@ -1,14 +1,23 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import
 import re, stat, sys
 
-from bup import options, git, vfs
+from bup import compat, options, git, vfs
 from bup.compat import argv_bytes
 from bup.helpers import chunkyreader, handle_ctrl_c, log, saved_errors
 from bup.io import byte_stream
@@ -24,7 +33,7 @@ bupm        print the target directory's .bupm file directly to stdout
 handle_ctrl_c()
 
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 git.check_repo_or_die()
 
index ba4b86a50f8917bf697e2a45864cfecb8ddb97ba..d47638eec6074864db76e4eba3e671110eb04f66 100755 (executable)
@@ -1,13 +1,23 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import
 import sys, getopt, socket, subprocess, fcntl
-from bup import options, path
+
+from bup import compat, options, path
 from bup.helpers import *
 
 optspec = """
@@ -17,7 +27,7 @@ l,listen  ip address to listen on, defaults to *
 p,port    port to listen on, defaults to 1982
 """
 o = options.Options(optspec, optfunc=getopt.getopt)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 host = opt.listen
 port = opt.port and int(opt.port) or 1982
index 07f0e03b25f3255d8ca522b4e661c61fd1fd91ff..d9e46da55d25189751eee193b97e8442a29aa271 100755 (executable)
@@ -1,14 +1,23 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import
 import sys, os, random
 
-from bup import options
+from bup import compat, options
 from bup.compat import argv_bytes, bytes_from_uint, range
 from bup.helpers import log
 from bup.io import path_msg
@@ -29,7 +38,7 @@ equal    spread damage evenly throughout the file
 S,seed=  random number seed (for repeatable tests)
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 if not extra:
     o.fatal('filenames expected')
index 3fa155fdd27548a748ac8890a9083cdd6045a4a6..22dc3e141a2ef544467b2c7700d26ca8a73542c8 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -9,7 +18,7 @@ from __future__ import absolute_import, print_function
 from os.path import relpath
 import sys
 
-from bup import options, drecurse
+from bup import compat, options, drecurse
 from bup.compat import argv_bytes
 from bup.helpers import log, parse_excludes, parse_rx_excludes, saved_errors
 from bup.io import byte_stream
@@ -27,7 +36,7 @@ q,quiet  don't actually print filenames
 profile  run under the python profiler
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 if len(extra) != 1:
     o.fatal("exactly one filename expected")
index 293024e8d81948492a857eef4d96903f1277ca66..035300d16d694e797f31879a16ff367a9c328bae 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -12,7 +21,7 @@ from subprocess import PIPE, Popen
 from tempfile import mkdtemp
 from binascii import hexlify
 
-from bup import options, git
+from bup import compat, options, git
 from bup.compat import argv_bytes
 from bup.helpers import Sha1, chunkyreader, istty2, log, progress
 from bup.io import byte_stream
@@ -184,7 +193,7 @@ par2-ok     immediately return 0 if par2 is ok, 1 if not
 disable-par2  ignore par2 even if it is available
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 opt.verbose = opt.verbose or 0
 
 par2_setup()
index 30e523de940f5041e4282e9434e44ebfb2f32b32..87fd3cedf9446c41119341d0641a5eb102944f62 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -13,7 +22,7 @@ exec "$bup_python" "$0" ${1+"$@"}
 from __future__ import absolute_import, print_function
 import sys, os, stat, fnmatch
 
-from bup import _helpers, options, git, shquote, ls, vfs
+from bup import _helpers, compat, options, git, shquote, ls, vfs
 from bup.compat import argv_bytes
 from bup.helpers import chunkyreader, handle_ctrl_c, log
 from bup.io import byte_stream, path_msg
@@ -115,7 +124,7 @@ optspec = """
 bup ftp [commands...]
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 git.check_repo_or_die()
 
index 2eb28fbcf8c0293844456c51cf9b4c2bdde09182..eb5daf834548bee8360170f7021f0dd6b4e601f9 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -32,7 +41,7 @@ if sys.version_info[0] > 2:
               file=sys.stderr)
         sys.exit(2)
 
-from bup import options, git, vfs, xstat
+from bup import compat, options, git, vfs, xstat
 from bup.compat import argv_bytes, fsdecode, py_maj
 from bup.helpers import log
 from bup.repo import LocalRepo
@@ -137,7 +146,7 @@ meta          report original metadata for paths when available
 v,verbose     increase log output (can be used more than once)
 """
 o = options.Options(optspec)
-opt, flags, extra = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 if not opt.verbose:
     opt.verbose = 0
 
index c4eeaffa8d4f9b430d81e0d69904390d13cf2c39..d8f7bc9810e305e145cb6b29cb2543787c2db27c 100755 (executable)
@@ -1,14 +1,23 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import
 import sys
 
-from bup import git, options
+from bup import compat, git, options
 from bup.gc import bup_gc
 from bup.helpers import die_if_errors, handle_ctrl_c, log
 
@@ -28,7 +37,7 @@ unsafe      use the command even though it may be DANGEROUS
 handle_ctrl_c()
 
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 if not opt.unsafe:
     o.fatal('refusing to run dangerous, experimental command without --unsafe')
index 95d8f57fabf0328d28996478fe65dedfaa14995e..88a919efa5e5e6430b786f8150b724bf4cf0a092 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -12,7 +21,7 @@ from collections import namedtuple
 from functools import partial
 from stat import S_ISDIR
 
-from bup import git, client, helpers, vfs
+from bup import compat, git, client, helpers, vfs
 from bup.compat import argv_bytes, environ, hexstr, items, wrap_main
 from bup.git import get_cat_data, parse_commit, walk_object
 from bup.helpers import add_error, debug1, handle_ctrl_c, log, saved_errors
@@ -389,7 +398,7 @@ def handle_append(item, src_repo, writer, opt):
     if item.src.type == 'tree':
         get_random_item(item.spec.src, src_oidx, src_repo, writer, opt)
         parent = item.dest.hash
-        msg = b'bup save\n\nGenerated by command:\n%r\n' % sys.argv
+        msg = b'bup save\n\nGenerated by command:\n%r\n' % compat.argvb
         userline = b'%s <%s@%s>' % (userfullname(), username(), hostname())
         now = time.time()
         commit = writer.new_commit(item.src.hash, parent,
@@ -572,7 +581,7 @@ def log_item(name, type, opt, tree=None, commit=None, tag=None):
 def main():
     handle_ctrl_c()
     is_reverse = environ.get(b'BUP_SERVER_REVERSE')
-    opt = parse_args(sys.argv)
+    opt = parse_args(compat.argv)
     git.check_repo_or_die()
     if opt.source:
         opt.source = argv_bytes(opt.source)
index 4ad5f74d102bfed40764926810fab09d4ec1e32b..c078e825c1f972afe5833196c65e1eaed5b4df2d 100755 (executable)
@@ -1,19 +1,28 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import
 import sys, os, glob
-from bup import options, path
+from bup import compat, options, path
 
 optspec = """
 bup help <command>
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 if len(extra) == 0:
     # the wrapper program provides the default usage string
index 45666efa72a6aef4b30ad5a4e7c533539b8199b2..bfb51831581b2e2c56f680af1fe16545175811da 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -14,7 +23,7 @@ import os
 import sys
 import tempfile
 
-from bup import git, helpers, options
+from bup import compat, git, helpers, options
 from bup.compat import argv_bytes, str_type
 from bup.helpers import (handle_ctrl_c,
                          log,
@@ -56,7 +65,7 @@ handle_ctrl_c()
 log('\nbup: import-duplicity is EXPERIMENTAL (proceed with caution)\n\n')
 
 o = options.Options(optspec)
-opt, flags, extra = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 if len(extra) < 1 or not extra[0]:
     o.fatal('duplicity source URL required')
index b131db990264b9079c2b41e1c2007d16075c01ff..030451e1339d8bcb9392d9558dccf0848c0934be 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -9,7 +18,7 @@ from __future__ import absolute_import, print_function
 from binascii import hexlify
 import sys, stat, time, os, errno, re
 
-from bup import metadata, options, git, index, drecurse, hlinkdb
+from bup import compat, metadata, options, git, index, drecurse, hlinkdb
 from bup.compat import argv_bytes
 from bup.drecurse import recursive_dirlist
 from bup.hashsplit import GIT_MODE_TREE, GIT_MODE_FILE
@@ -231,7 +240,7 @@ v,verbose  increase log output (can be used more than once)
 x,xdev,one-file-system  don't cross filesystem boundaries
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 if not (opt.modified or \
         opt['print'] or \
index ad2ed82877ab2bc643ee070f0ad7c75b5e5e959b..cff5c5cdd7ac3ba07762ffa1362099010bbc011b 100755 (executable)
@@ -1,14 +1,23 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import
 import sys
 
-from bup import git, options, client
+from bup import compat, git, options, client
 from bup.helpers import log, saved_errors
 from bup.compat import argv_bytes
 
@@ -19,7 +28,7 @@ optspec = """
 r,remote=  remote repository path
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 if extra:
     o.fatal("no arguments expected")
index 48bebe882f1c572f10d8d9ae015a8826d45873ea..e17c3159bcd2ed487e5cbf7b73e1e0cd07247066 100755 (executable)
@@ -1,14 +1,23 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import
 import sys
 
-from bup import git, options
+from bup import compat, git, options
 from bup.compat import argv_bytes
 from bup.helpers import linereader, log
 from bup.io import byte_stream
@@ -22,7 +31,7 @@ r,remote=  remote repository path
 o=         output filename
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 if opt.remote:
     opt.remote = argv_bytes(opt.remote)
 
index 78bb0a00fb94dc9d26e4756d35833d239d5a7e26..d9d318f4480361ac03fd27418c71346061f5ed38 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -9,7 +18,7 @@ from __future__ import absolute_import, print_function
 from binascii import hexlify, unhexlify
 import sys, os
 
-from bup import git, options
+from bup import compat, git, options
 from bup.compat import argv_bytes
 from bup.helpers import add_error, handle_ctrl_c, log, qprogress, saved_errors
 from bup.io import byte_stream
@@ -20,7 +29,7 @@ bup list-idx [--find=<prefix>] <idxfilenames...>
 find=   display only objects that start with <prefix>
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 handle_ctrl_c()
 
index 28ecc535113d40d49c90b83db87757d9af99ceac..b6900b93d9d580b31ba4ba5960dbdef2cdfb825e 100755 (executable)
@@ -1,14 +1,23 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import
 import sys
 
-from bup import git, ls
+from bup import compat, git, ls
 from bup.io import byte_stream
 
 
@@ -17,5 +26,5 @@ git.check_repo_or_die()
 sys.stdout.flush()
 out = byte_stream(sys.stdout)
 # Check out lib/bup/ls.py for the opt spec
-rc = ls.via_cmdline(sys.argv[1:], out=out)
+rc = ls.via_cmdline(compat.argv[1:], out=out)
 sys.exit(rc)
index 14e7cd7121167f36b74e09ef7d16f0fe2b2034e8..9dc854aaee57447607a93068bfb760029dcb37e4 100755 (executable)
@@ -1,14 +1,23 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import
 import sys, struct, math
 
-from bup import options, git, _helpers
+from bup import compat, options, git, _helpers
 from bup.helpers import log
 from bup.io import byte_stream
 
@@ -21,7 +30,7 @@ predict    Guess object offsets and report the maximum deviation
 ignore-midx  Don't use midx files; use only plain pack idx files.
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 if extra:
     o.fatal("no arguments expected")
index bf5f0d5a2b9365e7fd5ccef0ba206238d76cc5e9..85fd2f6e54dee1f738ec331b828ed6c2d1f0942e 100755 (executable)
@@ -1,14 +1,23 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import, print_function
 import sys, re, struct, time, resource
 
-from bup import git, bloom, midx, options, _helpers
+from bup import compat, git, bloom, midx, options, _helpers
 from bup.compat import range
 from bup.helpers import handle_ctrl_c
 from bup.io import byte_stream
@@ -80,7 +89,7 @@ ignore-midx  ignore .midx files, use only .idx files
 existing   test with existing objects instead of fake ones
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 if extra:
     o.fatal('no arguments expected')
index 2f30ce8ced2c1e5a255b26aa7faccfdd692ac717..e006c0bc7421b59c50bacec2d16cdf9d6e3e2384 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -14,7 +23,7 @@ exec "$bup_python" "$0" ${1+"$@"}
 
 from __future__ import absolute_import
 import sys
-from bup import metadata
+from bup import compat, metadata
 from bup import options
 from bup.compat import argv_bytes
 from bup.io import byte_stream
@@ -68,7 +77,7 @@ handle_ctrl_c()
 
 o = options.Options(optspec)
 (opt, flags, remainder) = o.parse(['--paths', '--symlinks', '--recurse']
-                                  + sys.argv[1:])
+                                  + compat.argv[1:])
 
 opt.verbose = opt.verbose or 0
 opt.quiet = opt.quiet or 0
index cadf7c3760b543342afbe9c219afa50bd8a7db1e..53ea79c8b4252955d687842e08b2150189e2916b 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -9,7 +18,7 @@ from __future__ import absolute_import, print_function
 from binascii import hexlify
 import glob, math, os, resource, struct, sys, tempfile
 
-from bup import options, git, midx, _helpers, xstat
+from bup import compat, options, git, midx, _helpers, xstat
 from bup.compat import argv_bytes, hexstr, range
 from bup.helpers import (Sha1, add_error, atomically_replaced_file, debug1, fdatasync,
                          handle_ctrl_c, log, mmap_readwrite, qprogress,
@@ -245,7 +254,7 @@ def do_midx_group(outdir, outfilename, infiles):
 handle_ctrl_c()
 
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 opt.dir = argv_bytes(opt.dir) if opt.dir else None
 opt.output = argv_bytes(opt.output) if opt.output else None
 
index f7be4c2f96da49f5b4accf636a84809cd94b67de..53fe7e6aefadf165153de47fab48ede9e3d1d071 100755 (executable)
@@ -1,14 +1,23 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import
 import os, sys, subprocess, struct
 
-from bup import options
+from bup import compat, options
 from bup.helpers import debug1, debug2, mux
 from bup.io import byte_stream
 
@@ -23,7 +32,7 @@ bup mux command [arguments...]
 --
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 if len(extra) < 1:
     o.fatal('command is required')
 
index e5b7b19054880be08d59387c783f556a378fa541..71ed4d1dc869bfdd3679ec88d71d37d469dae0a0 100755 (executable)
@@ -1,14 +1,23 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import
 import sys, os, struct
 
-from bup import options, helpers, path
+from bup import compat, options, helpers, path
 from bup.compat import environ, py_maj
 from bup.io import byte_stream
 
@@ -18,7 +27,7 @@ bup on--server
     This command is run automatically by 'bup on'
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 if extra:
     o.fatal('no arguments expected')
 
index 2c0e9fc808538ba4abb264be964bb3b36e0138c9..fd89da4e8bc51c9653f1b2aa968a75c1fa9c25d6 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -9,7 +18,7 @@ from __future__ import absolute_import
 from subprocess import PIPE
 import sys, os, struct, getopt, subprocess, signal
 
-from bup import options, ssh, path
+from bup import compat, options, ssh, path
 from bup.compat import argv_bytes
 from bup.helpers import DemuxConn, log
 from bup.io import byte_stream
@@ -22,7 +31,7 @@ bup on <hostname> split ...
 bup on <hostname> get ...
 """
 o = options.Options(optspec, optfunc=getopt.getopt)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 if len(extra) < 2:
     o.fatal('arguments expected')
 
index fcc0fbd2785f5378f2c9278c9a663a2befafe5d4..478000984389a9798afb03d6b5b50fba8f538044 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -13,7 +22,7 @@ from sys import stderr
 from time import localtime, strftime, time
 import re, sys
 
-from bup import git, options
+from bup import compat, git, options
 from bup.compat import argv_bytes, int_types
 from bup.gc import bup_gc
 from bup.helpers import die_if_errors, log, partition, period_as_secs
@@ -84,7 +93,7 @@ unsafe        use the command even though it may be DANGEROUS
 """
 
 o = options.Options(optspec)
-opt, flags, roots = o.parse(sys.argv[1:])
+opt, flags, roots = o.parse(compat.argv[1:])
 roots = [argv_bytes(x) for x in roots]
 
 if not opt.unsafe:
index 3eef820143be8ed3f506ce4af8381c6511fdca71..d939fb86ffcc9a59ea23fb275549b8302e3ffb41 100755 (executable)
@@ -1,14 +1,23 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import
 import os, sys
 
-from bup import options, _helpers
+from bup import compat, options, _helpers
 from bup.helpers import atoi, handle_ctrl_c, log, parse_num
 
 
@@ -20,7 +29,7 @@ f,force   print random data to stdout even if it's a tty
 v,verbose print byte counter to stderr
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+(opt, flags, extra) = o.parse(compat.argv[1:])
 
 if len(extra) != 1:
     o.fatal("exactly one argument expected")
index a5993638eaab1cb3380892953661c8e27907c1e2..f955cca743144dd83b6bfb1edf7b00694196f052 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -9,7 +18,7 @@ from __future__ import absolute_import
 from stat import S_ISDIR
 import copy, errno, os, sys, stat, re
 
-from bup import options, git, metadata, vfs
+from bup import compat, options, git, metadata, vfs
 from bup._helpers import write_sparsely
 from bup.compat import argv_bytes, fsencode, wrap_main
 from bup.helpers import (add_error, chunkyreader, die_if_errors, handle_ctrl_c,
@@ -225,7 +234,7 @@ def restore(repo, parent_path, name, item, top, sparse, numeric_ids, owner_map,
 
 def main():
     o = options.Options(optspec)
-    opt, flags, extra = o.parse(sys.argv[1:])
+    opt, flags, extra = o.parse(compat.argv[1:])
     verbosity = (opt.verbose or 0) if not opt.quiet else -1
     if opt.remote:
         opt.remote = argv_bytes(opt.remote)
index c0f7e55bd9ade242cac2ca69f9f4257b01cdc695..6c753e2a735c274327c3cf35fbd5db1a0902485e 100755 (executable)
@@ -1,13 +1,23 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import
 import sys
 
+from bup import compat
 from bup.compat import argv_bytes
 from bup.git import check_repo_or_die
 from bup.options import Options
@@ -26,7 +36,7 @@ unsafe       use the command even though it may be DANGEROUS
 handle_ctrl_c()
 
 o = Options(optspec)
-opt, flags, extra = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 if not opt.unsafe:
     o.fatal('refusing to run dangerous, experimental command without --unsafe')
index b84d63e1c910eb3112e85c362b3fe1e55ba56889..02e6841e33bd9dd100150656645c3022c3a2dcd6 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -11,7 +20,8 @@ from errno import EACCES
 from io import BytesIO
 import os, sys, stat, time, math
 
-from bup import hashsplit, git, options, index, client, metadata, hlinkdb
+from bup import compat, hashsplit, git, options, index, client, metadata
+from bup import hlinkdb
 from bup.compat import argv_bytes, environ
 from bup.hashsplit import GIT_MODE_TREE, GIT_MODE_FILE, GIT_MODE_SYMLINK
 from bup.helpers import (add_error, grafted_path_components, handle_ctrl_c,
@@ -42,7 +52,7 @@ graft=     a graft point *old_path*=*new_path* (can be used more than once)
 #,compress=  set compression level to # (0-9, 9 is highest) [1]
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 if opt.indexfile:
     opt.indexfile = argv_bytes(opt.indexfile)
index 2c8cc051a9febdf583e967e5ee378e5176a9baea..5b918140af4d98337d316865388a8e095e5a439b 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -9,7 +18,7 @@ from __future__ import absolute_import
 from binascii import hexlify, unhexlify
 import os, sys, struct, subprocess
 
-from bup import options, git, vfs, vint
+from bup import compat, options, git, vfs, vint
 from bup.compat import environ, hexstr
 from bup.git import MissingObject
 from bup.helpers import (Conn, debug1, debug2, linereader, lines_until_sentinel,
@@ -265,7 +274,7 @@ optspec = """
 bup server
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+(opt, flags, extra) = o.parse(compat.argv[1:])
 
 if extra:
     o.fatal('no arguments expected')
index bb4cf2e619bbb178c9974bed4e166b9776af8ba8..d9cdc7ed2b2934e55d23202476612c706c945c65 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -9,7 +18,7 @@ from __future__ import absolute_import, division, print_function
 from binascii import hexlify
 import os, sys, time
 
-from bup import hashsplit, git, options, client
+from bup import compat, hashsplit, git, options, client
 from bup.compat import argv_bytes, environ
 from bup.helpers import (add_error, handle_ctrl_c, hostname, log, parse_num,
                          qprogress, reprogress, saved_errors,
@@ -49,7 +58,7 @@ bwlimit=   maximum bytes/sec to transmit to server
 handle_ctrl_c()
 
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 if opt.name: opt.name = argv_bytes(opt.name)
 if opt.remote: opt.remote = argv_bytes(opt.remote)
 if opt.verbose is None: opt.verbose = 0
@@ -211,7 +220,7 @@ if opt.verbose:
 if opt.tree:
     out.write(hexlify(tree) + b'\n')
 if opt.commit or opt.name:
-    msg = b'bup split\n\nGenerated by command:\n%r\n' % sys.argv
+    msg = b'bup split\n\nGenerated by command:\n%r\n' % compat.argvb
     ref = opt.name and (b'refs/heads/%s' % opt.name) or None
     userline = b'%s <%s@%s>' % (userfullname(), username(), hostname())
     commit = pack_writer.new_commit(tree, oldref, userline, date, None,
index 44c5b33f92aed6e73cd4fbd476c1dd080f5520d9..2561aba383633612ef072a14d42a94bb85f50f9b 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -9,7 +18,7 @@ from __future__ import absolute_import
 from binascii import hexlify
 import os, sys
 
-from bup import git, options
+from bup import compat, git, options
 from bup.compat import argv_bytes
 from bup.helpers import debug1, handle_ctrl_c, log
 from bup.io import byte_stream, path_msg
@@ -28,7 +37,7 @@ f,force     Overwrite existing tag, or ignore missing tag when deleting
 """
 
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 git.check_repo_or_die()
 
index 30e1d50f85815e5c8df77b2ad1d1818d18e71549..1a76350f12d333776e5d38c951710b6365b872d0 100755 (executable)
@@ -1,19 +1,29 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import
 import sys, time
-from bup import options
+
+from bup import compat, options
 
 optspec = """
 bup tick
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 if extra:
     o.fatal("no arguments expected")
index f7555a8aeaef8078d617cc41c1b7df089139cc46..20fd218c5fe83001436b4d6dec29836d18869184 100755 (executable)
@@ -1,15 +1,23 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import, print_function
 import re, sys
 
-from bup import options
-from bup import version
+from bup import compat, options, version
 
 version_rx = re.compile(r'^[0-9]+\.[0-9]+(\.[0-9]+)?(-[0-9]+-g[0-9abcdef]+)?$')
 
@@ -21,7 +29,7 @@ commit  display the git commit id of this version of bup
 tag     display the tag name of this version.  If no tag is available, display the commit id
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 
 total = (opt.date or 0) + (opt.commit or 0) + (opt.tag or 0)
index a967f34f1ba15648b30e8f05906036d42474c731..8c084c17b771d64585805ad81013e5817ad564d1 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -10,7 +19,7 @@ from collections import namedtuple
 import mimetypes, os, posixpath, signal, stat, sys, time, urllib, webbrowser
 from binascii import hexlify
 
-from bup import options, git, vfs
+from bup import compat, options, git, vfs
 from bup.helpers import (chunkyreader, debug1, format_filesize, handle_ctrl_c,
                          log, saved_errors)
 from bup.metadata import Metadata
@@ -250,7 +259,7 @@ human-readable    display human readable file sizes (i.e. 3.9K, 4.7M)
 browser           show repository in default browser (incompatible with unix://)
 """
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 if len(extra) > 1:
     o.fatal("at most one argument expected")
index 626b4c7e9d2f82476346c01184c21aab764457f8..297df7225e201ad7c1239af6dd80165d5ea11868 100755 (executable)
@@ -1,7 +1,16 @@
 #!/bin/sh
 """": # -*-python-*-
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+# Here to end of preamble replaced during install
 bup_python="$(dirname "$0")/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -13,7 +22,7 @@ exec "$bup_python" "$0" ${1+"$@"}
 from __future__ import absolute_import, print_function
 import sys, stat, errno
 
-from bup import metadata, options, xstat
+from bup import compat, metadata, options, xstat
 from bup.compat import argv_bytes
 from bup.helpers import add_error, handle_ctrl_c, parse_timestamp, saved_errors, \
     add_error, log
@@ -54,7 +63,7 @@ active_fields = metadata.all_fields
 handle_ctrl_c()
 
 o = options.Options(optspec)
-(opt, flags, remainder) = o.parse(sys.argv[1:])
+(opt, flags, remainder) = o.parse(compat.argv[1:])
 
 atime_resolution = parse_timestamp_arg('atime', opt.atime_resolution)
 mtime_resolution = parse_timestamp_arg('mtime', opt.mtime_resolution)
index 99a145ef0b9a7f8a1d30d9753887863d9c7e9d90..66c5c6361cc122c70a8670957e04601e1b6245d9 100755 (executable)
@@ -1,7 +1,15 @@
 #!/bin/sh
 """": # -*-python-*-
-bup_python="$(dirname "$0")/../cmd/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+bup_python="$(dirname "$0")/../lib/cmd/bup-python" || exit $?
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -11,11 +19,11 @@ from os.path import abspath, dirname
 from sys import stdout
 import os, sys
 
-script_home = abspath(dirname(sys.argv[0] or '.'))
+script_home = abspath(dirname(__file__))
 sys.path[:0] = [abspath(script_home + '/../lib'), abspath(script_home + '/..')]
 
-from bup.compat import argv_bytes
+from bup import compat
 
-for arg in [argv_bytes(x) for x in sys.argv]:
+for arg in compat.argvb:
     os.write(stdout.fileno(), arg)
     os.write(stdout.fileno(), b'\0\n')
index bcb3cd0ebcae5c5e0a1ec4b10e614f53f189c2d0..4769154c5b9f34ecb9a8dfdfd906d2d5da0d71a2 100755 (executable)
@@ -1,14 +1,22 @@
 #!/bin/sh
 """": # -*-python-*-
-bup_python="$(dirname "$0")/../cmd/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+bup_python="$(dirname "$0")/../lib/cmd/bup-python" || exit $?
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
 from __future__ import absolute_import, print_function
 import os, stat, sys
 
-from bup.compat import argv_bytes
+from bup import compat
 from bup.io import byte_stream
 
 
@@ -19,7 +27,7 @@ from bup.io import byte_stream
 def usage():
     print("Usage: hardlink-sets <paths ...>", file=sys.stderr)
 
-if len(sys.argv) < 2:
+if len(compat.argv) < 2:
     usage()
     sys.exit(1)
 
@@ -31,7 +39,7 @@ out = byte_stream(sys.stdout)
 
 hardlink_set = {}
 
-for p in (argv_bytes(x) for x in sys.argv[1:]):
+for p in compat.argvb[1:]:
   for root, dirs, files in os.walk(p, onerror = on_walk_error):
       for filename in files:
           full_path = os.path.join(root, filename)
index e8be1ef9cca727fc464f967a13f45ff7d7e03683..574fad5bb6979918e265742e08b7292f98c1b5ee 100755 (executable)
@@ -1,7 +1,15 @@
 #!/bin/sh
 """": # -*-python-*-
-bup_python="$(dirname "$0")/../cmd/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+bup_python="$(dirname "$0")/../lib/cmd/bup-python" || exit $?
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -11,7 +19,7 @@ import os, sys
 from bup.compat import argv_bytes
 from bup.helpers import handle_ctrl_c, saved_errors
 from bup.io import byte_stream
-from bup import metadata, options
+from bup import compat, metadata, options
 import bup.xstat as xstat
 
 
@@ -23,7 +31,7 @@ ns-timestamp-resolutions TEST_FILE_NAME
 handle_ctrl_c()
 
 o = options.Options(optspec)
-(opt, flags, extra) = o.parse(sys.argv[1:])
+opt, flags, extra = o.parse(compat.argv[1:])
 
 sys.stdout.flush()
 out = byte_stream(sys.stdout)
index 27423646feeccb63bea02fa571e4792f92d94451..6d83b763559539f3df5cb5ab03d650025f2a7e56 100755 (executable)
@@ -13,7 +13,7 @@ from subprocess import check_output
 from sys import stderr, stdout
 import sys
 
-script_home = abspath(dirname(sys.argv[0] or '.'))
+script_home = abspath(dirname(__file__))
 sys.path[:0] = [abspath(script_home + '/../lib'), abspath(script_home + '/..')]
 
 from wvtest import wvcheck, wvfail, wvmsg, wvpass, wvpasseq, wvpassne, wvstart
index f6fe8cc850ac127d8e9fc4e1b0584394730718b8..3f42a0c3a52a569db0484b0025bf0648b9a883bb 100755 (executable)
@@ -1,7 +1,15 @@
 #!/bin/sh
 """": # -*-python-*-
-bup_python="$(dirname "$0")/../cmd/bup-python" || exit $?
-exec "$bup_python" "$0" ${1+"$@"}
+# https://sourceware.org/bugzilla/show_bug.cgi?id=26034
+export "BUP_ARGV_0"="$0"
+arg_i=1
+for arg in "$@"; do
+    export "BUP_ARGV_${arg_i}"="$arg"
+    shift
+    arg_i=$((arg_i + 1))
+done
+bup_python="$(dirname "$0")/../lib/cmd/bup-python" || exit $?
+exec "$bup_python" "$0"
 """
 # end of bup preamble
 
@@ -962,11 +970,11 @@ dispositions_to_test = ('get',)
 if int(environ.get(b'BUP_TEST_LEVEL', b'0')) >= 11:
     dispositions_to_test += ('get-on', 'get-to')
 
-if len(sys.argv) == 1:
+if len(compat.argv) == 1:
     categories = ('replace', 'universal', 'ff', 'append', 'pick', 'new-tag',
              'unnamed')
 else:
-    categories = sys.argv[1:]
+    categories = compat.argv[1:]
     
 with test_tempdir(b'get-') as tmpdir:
     chdir(tmpdir)