From a4f58b2e4bb1a0208a9cec4b76a596d36134a881 Mon Sep 17 00:00:00 2001 From: Rob Browning Date: Sun, 7 Jun 2020 09:05:26 -0500 Subject: [PATCH] Bypass Python 3 glibc argv problems by routing args through env 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 Tested-by: Rob Browning --- lib/bup/compat.py | 35 +++++++++++++++++++++++++++++++++ lib/cmd/bloom-cmd.py | 15 +++++++++++--- lib/cmd/bup | 20 ++++++++++++++----- lib/cmd/cat-file-cmd.py | 15 +++++++++++--- lib/cmd/daemon-cmd.py | 16 ++++++++++++--- lib/cmd/damage-cmd.py | 15 +++++++++++--- lib/cmd/drecurse-cmd.py | 15 +++++++++++--- lib/cmd/fsck-cmd.py | 15 +++++++++++--- lib/cmd/ftp-cmd.py | 15 +++++++++++--- lib/cmd/fuse-cmd.py | 15 +++++++++++--- lib/cmd/gc-cmd.py | 15 +++++++++++--- lib/cmd/get-cmd.py | 17 ++++++++++++---- lib/cmd/help-cmd.py | 15 +++++++++++--- lib/cmd/import-duplicity-cmd.py | 15 +++++++++++--- lib/cmd/index-cmd.py | 15 +++++++++++--- lib/cmd/init-cmd.py | 15 +++++++++++--- lib/cmd/join-cmd.py | 15 +++++++++++--- lib/cmd/list-idx-cmd.py | 15 +++++++++++--- lib/cmd/ls-cmd.py | 15 +++++++++++--- lib/cmd/margin-cmd.py | 15 +++++++++++--- lib/cmd/memtest-cmd.py | 15 +++++++++++--- lib/cmd/meta-cmd.py | 15 +++++++++++--- lib/cmd/midx-cmd.py | 15 +++++++++++--- lib/cmd/mux-cmd.py | 15 +++++++++++--- lib/cmd/on--server-cmd.py | 15 +++++++++++--- lib/cmd/on-cmd.py | 15 +++++++++++--- lib/cmd/prune-older-cmd.py | 15 +++++++++++--- lib/cmd/random-cmd.py | 15 +++++++++++--- lib/cmd/restore-cmd.py | 15 +++++++++++--- lib/cmd/rm-cmd.py | 14 +++++++++++-- lib/cmd/save-cmd.py | 16 ++++++++++++--- lib/cmd/server-cmd.py | 15 +++++++++++--- lib/cmd/split-cmd.py | 17 ++++++++++++---- lib/cmd/tag-cmd.py | 15 +++++++++++--- lib/cmd/tick-cmd.py | 16 ++++++++++++--- lib/cmd/version-cmd.py | 16 +++++++++++---- lib/cmd/web-cmd.py | 15 +++++++++++--- lib/cmd/xstat-cmd.py | 15 +++++++++++--- t/echo-argv-bytes | 18 ++++++++++++----- t/hardlink-sets | 18 ++++++++++++----- t/ns-timestamp-resolutions | 16 +++++++++++---- t/test-argv | 2 +- t/test-get | 16 +++++++++++---- 43 files changed, 538 insertions(+), 134 deletions(-) diff --git a/lib/bup/compat.py b/lib/bup/compat.py index f5819c2..37b31f1 100644 --- a/lib/bup/compat.py +++ b/lib/bup/compat.py @@ -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. diff --git a/lib/cmd/bloom-cmd.py b/lib/cmd/bloom-cmd.py index d7537ca..16d8f46 100755 --- a/lib/cmd/bloom-cmd.py +++ b/lib/cmd/bloom-cmd.py @@ -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') diff --git a/lib/cmd/bup b/lib/cmd/bup index 8f27c0f..92807a5 100755 --- a/lib/cmd/bup +++ b/lib/cmd/bup @@ -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) diff --git a/lib/cmd/cat-file-cmd.py b/lib/cmd/cat-file-cmd.py index 3f776a2..849cb45 100755 --- a/lib/cmd/cat-file-cmd.py +++ b/lib/cmd/cat-file-cmd.py @@ -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() diff --git a/lib/cmd/daemon-cmd.py b/lib/cmd/daemon-cmd.py index ba4b86a..d47638e 100755 --- a/lib/cmd/daemon-cmd.py +++ b/lib/cmd/daemon-cmd.py @@ -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 diff --git a/lib/cmd/damage-cmd.py b/lib/cmd/damage-cmd.py index 07f0e03..d9e46da 100755 --- a/lib/cmd/damage-cmd.py +++ b/lib/cmd/damage-cmd.py @@ -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') diff --git a/lib/cmd/drecurse-cmd.py b/lib/cmd/drecurse-cmd.py index 3fa155f..22dc3e1 100755 --- a/lib/cmd/drecurse-cmd.py +++ b/lib/cmd/drecurse-cmd.py @@ -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") diff --git a/lib/cmd/fsck-cmd.py b/lib/cmd/fsck-cmd.py index 293024e..035300d 100755 --- a/lib/cmd/fsck-cmd.py +++ b/lib/cmd/fsck-cmd.py @@ -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() diff --git a/lib/cmd/ftp-cmd.py b/lib/cmd/ftp-cmd.py index 30e523d..87fd3ce 100755 --- a/lib/cmd/ftp-cmd.py +++ b/lib/cmd/ftp-cmd.py @@ -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() diff --git a/lib/cmd/fuse-cmd.py b/lib/cmd/fuse-cmd.py index 2eb28fb..eb5daf8 100755 --- a/lib/cmd/fuse-cmd.py +++ b/lib/cmd/fuse-cmd.py @@ -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 diff --git a/lib/cmd/gc-cmd.py b/lib/cmd/gc-cmd.py index c4eeaff..d8f7bc9 100755 --- a/lib/cmd/gc-cmd.py +++ b/lib/cmd/gc-cmd.py @@ -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') diff --git a/lib/cmd/get-cmd.py b/lib/cmd/get-cmd.py index 95d8f57..88a919e 100755 --- a/lib/cmd/get-cmd.py +++ b/lib/cmd/get-cmd.py @@ -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) diff --git a/lib/cmd/help-cmd.py b/lib/cmd/help-cmd.py index 4ad5f74..c078e82 100755 --- a/lib/cmd/help-cmd.py +++ b/lib/cmd/help-cmd.py @@ -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 """ 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 diff --git a/lib/cmd/import-duplicity-cmd.py b/lib/cmd/import-duplicity-cmd.py index 45666ef..bfb5183 100755 --- a/lib/cmd/import-duplicity-cmd.py +++ b/lib/cmd/import-duplicity-cmd.py @@ -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') diff --git a/lib/cmd/index-cmd.py b/lib/cmd/index-cmd.py index b131db9..030451e 100755 --- a/lib/cmd/index-cmd.py +++ b/lib/cmd/index-cmd.py @@ -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 \ diff --git a/lib/cmd/init-cmd.py b/lib/cmd/init-cmd.py index ad2ed82..cff5c5c 100755 --- a/lib/cmd/init-cmd.py +++ b/lib/cmd/init-cmd.py @@ -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") diff --git a/lib/cmd/join-cmd.py b/lib/cmd/join-cmd.py index 48bebe8..e17c315 100755 --- a/lib/cmd/join-cmd.py +++ b/lib/cmd/join-cmd.py @@ -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) diff --git a/lib/cmd/list-idx-cmd.py b/lib/cmd/list-idx-cmd.py index 78bb0a0..d9d318f 100755 --- a/lib/cmd/list-idx-cmd.py +++ b/lib/cmd/list-idx-cmd.py @@ -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=] find= display only objects that start with """ o = options.Options(optspec) -(opt, flags, extra) = o.parse(sys.argv[1:]) +opt, flags, extra = o.parse(compat.argv[1:]) handle_ctrl_c() diff --git a/lib/cmd/ls-cmd.py b/lib/cmd/ls-cmd.py index 28ecc53..b6900b9 100755 --- a/lib/cmd/ls-cmd.py +++ b/lib/cmd/ls-cmd.py @@ -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) diff --git a/lib/cmd/margin-cmd.py b/lib/cmd/margin-cmd.py index 14e7cd7..9dc854a 100755 --- a/lib/cmd/margin-cmd.py +++ b/lib/cmd/margin-cmd.py @@ -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") diff --git a/lib/cmd/memtest-cmd.py b/lib/cmd/memtest-cmd.py index bf5f0d5..85fd2f6 100755 --- a/lib/cmd/memtest-cmd.py +++ b/lib/cmd/memtest-cmd.py @@ -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') diff --git a/lib/cmd/meta-cmd.py b/lib/cmd/meta-cmd.py index 2f30ce8..e006c0b 100755 --- a/lib/cmd/meta-cmd.py +++ b/lib/cmd/meta-cmd.py @@ -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 diff --git a/lib/cmd/midx-cmd.py b/lib/cmd/midx-cmd.py index cadf7c3..53ea79c 100755 --- a/lib/cmd/midx-cmd.py +++ b/lib/cmd/midx-cmd.py @@ -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 diff --git a/lib/cmd/mux-cmd.py b/lib/cmd/mux-cmd.py index f7be4c2..53fe7e6 100755 --- a/lib/cmd/mux-cmd.py +++ b/lib/cmd/mux-cmd.py @@ -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') diff --git a/lib/cmd/on--server-cmd.py b/lib/cmd/on--server-cmd.py index e5b7b19..71ed4d1 100755 --- a/lib/cmd/on--server-cmd.py +++ b/lib/cmd/on--server-cmd.py @@ -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') diff --git a/lib/cmd/on-cmd.py b/lib/cmd/on-cmd.py index 2c0e9fc..fd89da4 100755 --- a/lib/cmd/on-cmd.py +++ b/lib/cmd/on-cmd.py @@ -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 split ... bup on 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') diff --git a/lib/cmd/prune-older-cmd.py b/lib/cmd/prune-older-cmd.py index fcc0fbd..4780009 100755 --- a/lib/cmd/prune-older-cmd.py +++ b/lib/cmd/prune-older-cmd.py @@ -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: diff --git a/lib/cmd/random-cmd.py b/lib/cmd/random-cmd.py index 3eef820..d939fb8 100755 --- a/lib/cmd/random-cmd.py +++ b/lib/cmd/random-cmd.py @@ -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") diff --git a/lib/cmd/restore-cmd.py b/lib/cmd/restore-cmd.py index a599363..f955cca 100755 --- a/lib/cmd/restore-cmd.py +++ b/lib/cmd/restore-cmd.py @@ -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) diff --git a/lib/cmd/rm-cmd.py b/lib/cmd/rm-cmd.py index c0f7e55..6c753e2 100755 --- a/lib/cmd/rm-cmd.py +++ b/lib/cmd/rm-cmd.py @@ -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') diff --git a/lib/cmd/save-cmd.py b/lib/cmd/save-cmd.py index b84d63e..02e6841 100755 --- a/lib/cmd/save-cmd.py +++ b/lib/cmd/save-cmd.py @@ -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) diff --git a/lib/cmd/server-cmd.py b/lib/cmd/server-cmd.py index 2c8cc05..5b91814 100755 --- a/lib/cmd/server-cmd.py +++ b/lib/cmd/server-cmd.py @@ -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') diff --git a/lib/cmd/split-cmd.py b/lib/cmd/split-cmd.py index bb4cf2e..d9cdc7e 100755 --- a/lib/cmd/split-cmd.py +++ b/lib/cmd/split-cmd.py @@ -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, diff --git a/lib/cmd/tag-cmd.py b/lib/cmd/tag-cmd.py index 44c5b33..2561aba 100755 --- a/lib/cmd/tag-cmd.py +++ b/lib/cmd/tag-cmd.py @@ -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() diff --git a/lib/cmd/tick-cmd.py b/lib/cmd/tick-cmd.py index 30e1d50..1a76350 100755 --- a/lib/cmd/tick-cmd.py +++ b/lib/cmd/tick-cmd.py @@ -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") diff --git a/lib/cmd/version-cmd.py b/lib/cmd/version-cmd.py index f7555a8..20fd218 100755 --- a/lib/cmd/version-cmd.py +++ b/lib/cmd/version-cmd.py @@ -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) diff --git a/lib/cmd/web-cmd.py b/lib/cmd/web-cmd.py index a967f34..8c084c1 100755 --- a/lib/cmd/web-cmd.py +++ b/lib/cmd/web-cmd.py @@ -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") diff --git a/lib/cmd/xstat-cmd.py b/lib/cmd/xstat-cmd.py index 626b4c7..297df72 100755 --- a/lib/cmd/xstat-cmd.py +++ b/lib/cmd/xstat-cmd.py @@ -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) diff --git a/t/echo-argv-bytes b/t/echo-argv-bytes index 99a145e..66c5c63 100755 --- a/t/echo-argv-bytes +++ b/t/echo-argv-bytes @@ -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') diff --git a/t/hardlink-sets b/t/hardlink-sets index bcb3cd0..4769154 100755 --- a/t/hardlink-sets +++ b/t/hardlink-sets @@ -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 ", 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) diff --git a/t/ns-timestamp-resolutions b/t/ns-timestamp-resolutions index e8be1ef..574fad5 100755 --- a/t/ns-timestamp-resolutions +++ b/t/ns-timestamp-resolutions @@ -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) diff --git a/t/test-argv b/t/test-argv index 2742364..6d83b76 100755 --- a/t/test-argv +++ b/t/test-argv @@ -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 diff --git a/t/test-get b/t/test-get index f6fe8cc..3f42a0c 100755 --- a/t/test-get +++ b/t/test-get @@ -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) -- 2.39.2