]> arthur.barton.de Git - bup.git/commitdiff
tests: add test for save encountering duplicates
authorJohannes Berg <johannes@sipsolutions.net>
Sat, 25 Jan 2020 22:13:17 +0000 (23:13 +0100)
committerRob Browning <rlb@defaultvalue.org>
Mon, 24 Feb 2020 01:40:12 +0000 (19:40 -0600)
Add a test for save encountering duplicates in the index, both
for a file and a directory, which was fixed in the previous patch.

Signed-off-by: Johannes Berg <johannes@sipsolutions.net>
Reviewed-by: Rob Browning <rlb@defaultvalue.org>
Tested-by: Rob Browning <rlb@defaultvalue.org>
t/test-save-errors

index 152526103656ba753c052d18529661c9e06f965c..cafd227a0198da97ad301cc724e1f61d68e81fef 100755 (executable)
@@ -95,4 +95,45 @@ if ! bup ls -l "test/latest/$tmpdir/save" | grep "1970-01-01 00:00 a" ; then
     WVFAIL unexpected date for directory a
 fi
 
+
+WVSTART "duplicate entries"
+WVPASS bup index --clear
+WVPASS bup index "$tmpdir/save"
+
+cat > "$tmpdir/bup-save" << EOF
+#!$top/cmd/bup-python
+from bup import index
+
+Reader = index.Reader
+class DupReader(index.Reader):
+    def filter(self, *args, **kw):
+        for transname, ent in Reader.filter(self, *args, **kw):
+            # duplicate a file and a folder
+            if ent.name.endswith(b'/5') or ent.name.endswith(b'/a/'):
+                yield transname, ent
+            yield transname, ent
+index.Reader = DupReader
+
+exec(open("$top/cmd/bup-save", "rb").read())
+EOF
+chmod +x "$tmpdir/bup-save"
+
+# use it to save the data
+"$tmpdir/bup-save" -n test "$tmpdir/save"
+
+# this should work
+WVPASS bup ls -l "test/latest/$tmpdir/save"
+
+# check that there are no duplicates
+lsout=$(bup ls -l "test/latest/$tmpdir/save")
+WVPASSEQ "$(echo "$lsout" | sort | uniq -d)" ""
+
+# and we should get the *right* data for each entry
+for f in $(seq 9) ; do
+    if ! echo "$lsout" | grep "200${f}-01-01 00:00 $f" ; then
+        WVFAIL echo incorrect metadata for $f
+    fi
+done
+
+
 WVPASS rm -rf "$tmpdir"