]> arthur.barton.de Git - bup.git/commitdiff
sampledata: include random binary paths
authorRob Browning <rlb@defaultvalue.org>
Thu, 28 May 2020 06:56:13 +0000 (01:56 -0500)
committerRob Browning <rlb@defaultvalue.org>
Sun, 5 Jul 2020 16:16:22 +0000 (11:16 -0500)
Thanks to Johannes Berg for the xargs -0 addition fix.

Signed-off-by: Rob Browning <rlb@defaultvalue.org>
Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
t/configure-sampledata
t/make-random-paths [new file with mode: 0755]
t/test-meta.sh

index cec49eb7b1d431e5cc709d69d47c57dee1af435a..487a0f59c3576ca92c518f90ed21959827809e67 100755 (executable)
@@ -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 (executable)
index 0000000..d500fb4
--- /dev/null
@@ -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
index f25106560acce071ac54456b23d9a856af297b64..eb1f97b4896dae028cc003934fea42a56cbc7142 100755 (executable)
@@ -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
     )