]> arthur.barton.de Git - bup.git/blobdiff - t/test-save-errors
cirrus: macos: use new brew installer
[bup.git] / t / test-save-errors
index 152526103656ba753c052d18529661c9e06f965c..14fd47f8fe2888896e97bc46a57d4809d51b249e 100755 (executable)
@@ -33,8 +33,9 @@ WVPASS bup index "$tmpdir/save"
 # essentially, we create a bup-save command for ourselves
 # that gets an error for the .../5 file in metadata.from_path()
 cat > "$tmpdir/bup-save" << EOF
-#!$top/cmd/bup-python
+#!/usr/bin/env $top/dev/bup-python
 from bup import metadata
+
 orig_from_path = metadata.from_path
 def from_path(path, *args, **kw):
     if path.endswith(b'/5'):
@@ -42,7 +43,7 @@ def from_path(path, *args, **kw):
     return orig_from_path(path, *args, **kw)
 metadata.from_path = from_path
 
-exec(open("$top/cmd/bup-save", "rb").read())
+exec(open("$top/lib/cmd/bup-save", "rb").read())
 EOF
 chmod +x "$tmpdir/bup-save"
 
@@ -69,8 +70,9 @@ WVPASS bup index --clear
 WVPASS bup index "$tmpdir/save"
 
 cat > "$tmpdir/bup-save" << EOF
-#!$top/cmd/bup-python
+#!/usr/bin/env $top/dev/bup-python
 from bup import metadata
+
 orig_from_path = metadata.from_path
 def from_path(path, *args, **kw):
     if path.endswith(b'/a'):
@@ -78,7 +80,7 @@ def from_path(path, *args, **kw):
     return orig_from_path(path, *args, **kw)
 metadata.from_path = from_path
 
-exec(open("$top/cmd/bup-save", "rb").read())
+exec(open("$top/lib/cmd/bup-save", "rb").read())
 EOF
 chmod +x "$tmpdir/bup-save"
 
@@ -95,4 +97,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
+#!/usr/bin/env $top/dev/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/lib/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"