From: Rob Browning Date: Thu, 28 May 2020 06:56:13 +0000 (-0500) Subject: sampledata: include random binary paths X-Git-Tag: 0.31~55 X-Git-Url: https://arthur.barton.de/gitweb/?p=bup.git;a=commitdiff_plain;h=f3b164a6242f950591a950b47a2c164038465aea sampledata: include random binary paths Thanks to Johannes Berg for the xargs -0 addition fix. Signed-off-by: Rob Browning Signed-off-by: Johannes Berg --- diff --git a/t/configure-sampledata b/t/configure-sampledata index cec49eb..487a0f5 100755 --- a/t/configure-sampledata +++ b/t/configure-sampledata @@ -5,8 +5,7 @@ set -o pipefail # NOTE: any relevant changes to var/ must be accompanied by an # increment to the revision. -revision=2 -readonly revision +revision=3 top="$(pwd)" || exit $? @@ -49,6 +48,8 @@ case "$1" in cp -pP "$top"/cmd/*.py cmd/ || exit $? cp -pP "$top"/Documentation/*.md doc/ || exit $? cp -pP "$top"/lib/bup/*.py lib/bup || exit $? + mkdir path-zoo || exit $? + "$top"/t/make-random-paths 3000 path-zoo || exit $? # The "v" ensures that if "configure-sampledata # --revision" and/or the setup above fails somehow, # callers like make will be looking for a file that won't diff --git a/t/make-random-paths b/t/make-random-paths new file mode 100755 index 0000000..d500fb4 --- /dev/null +++ b/t/make-random-paths @@ -0,0 +1,56 @@ +#!/bin/sh +"""": # -*-python-*- +bup_python="$(dirname "$0")/../cmd/bup-python" || exit $? +exec "$bup_python" "$0" ${1+"$@"} +""" +# end of bup preamble + +from __future__ import absolute_import, print_function + +from os.path import abspath, dirname +from random import randint +from sys import argv, exit, stderr, stdout +import errno, re, sys + +script_home = abspath(dirname(sys.argv[0] or '.')) +sys.path[:0] = [abspath(script_home + '/../lib'), abspath(script_home + '/..')] + +from bup.compat import fsencode, range + + +def usage(out=stdout): + print('Usage:', argv[0], 'NUM', 'DEST_DIR', file=out) + +def misuse(): + usage(stderr) + exit(2) + +if sys.version_info[0] >= 3: + def bytes_from_ints(ints): + return bytes(ints) +else: + def bytes_from_ints(ints): + return ''.join([chr(x) for x in ints]) + +invalid_fragments = re.compile(br'(\x00|[./]|\.\.)') + +def random_filename(): + n = randint(1, 32) + def random_candidate(): + return invalid_fragments.sub(b'', bytes_from_ints([randint(1, 255) + for x in range(n)])) + candidate = random_candidate() + while not candidate: + candidate = random_candidate() + return candidate + +if len(argv) != 3: + misuse() + +count, dest = argv[1:] +count = int(count) + +i = 0 +while i < count: + with open(fsencode(dest) + b'/' + random_filename(), 'w') as _: + i += 1 diff --git a/t/test-meta.sh b/t/test-meta.sh index f251065..eb1f97b 100755 --- a/t/test-meta.sh +++ b/t/test-meta.sh @@ -45,8 +45,8 @@ genstat() ( export PATH="$TOP:$PATH" # pick up bup # Skip atime (test elsewhere) to avoid the observer effect. - WVPASS find . | WVPASS sort \ - | WVPASS xargs bup xstat \ + WVPASS find . -print0 | WVPASS sort -z \ + | WVPASS xargs -0 bup xstat \ --mtime-resolution "$mtime_resolution"ns \ --exclude-fields ctime,atime,size )