8 top="$(WVPASS pwd)" || exit $?
9 tmpdir="$(WVPASS wvmktempdir)" || exit $?
10 export BUP_DIR="$tmpdir/bup"
12 bup() { "$top/bup" "$@"; }
16 # necessary for 0 == 1970-01-01 00:00
23 for f in $(seq 9) ; do
24 touch -t 200${f}01010000 "$tmpdir/save/$f"
26 mkdir "$tmpdir/save/a"
27 touch -t 199901010000 "$tmpdir/save/a/1"
29 WVSTART "metadata read error for a file"
30 WVPASS bup index "$tmpdir/save"
32 # now do a hack to inject save errors while reading metadata
33 # essentially, we create a bup-save command for ourselves
34 # that gets an error for the .../5 file in metadata.from_path()
35 cat > "$tmpdir/bup-save" << EOF
36 #!/usr/bin/env $top/dev/bup-python
37 from bup import metadata
39 orig_from_path = metadata.from_path
40 def from_path(path, *args, **kw):
41 if path.endswith(b'/5'):
42 raise IOError('intentionally failing metadata read for .../5')
43 return orig_from_path(path, *args, **kw)
44 metadata.from_path = from_path
46 exec(open("$top/lib/cmd/bup-save", "rb").read())
48 chmod +x "$tmpdir/bup-save"
50 # use it to save the data
51 "$tmpdir/bup-save" -n test "$tmpdir/save"
53 # this should work anyway
54 WVPASS bup ls -l "test/latest/$tmpdir/save"
55 # also check the *right* data was returned
56 lsout="$(bup ls -l "test/latest/$tmpdir/save")"
57 for f in 1 2 3 4 6 7 8 9 ; do
58 if ! echo "$lsout" | grep "200${f}-01-01 00:00 $f" ; then
59 WVFAIL echo incorrect date for $f
62 # and ensure we actually failed, and the above script/hack didn't break
63 if ! echo "$lsout" | grep "1970-01-01 00:00 5" ; then
64 WVFAIL echo unexpected date for file 5
68 WVSTART "metadata read error for a folder"
69 WVPASS bup index --clear
70 WVPASS bup index "$tmpdir/save"
72 cat > "$tmpdir/bup-save" << EOF
73 #!/usr/bin/env $top/dev/bup-python
74 from bup import metadata
76 orig_from_path = metadata.from_path
77 def from_path(path, *args, **kw):
78 if path.endswith(b'/a'):
79 raise IOError('intentionally failing metadata read for .../a')
80 return orig_from_path(path, *args, **kw)
81 metadata.from_path = from_path
83 exec(open("$top/lib/cmd/bup-save", "rb").read())
85 chmod +x "$tmpdir/bup-save"
87 # use it to save the data
88 "$tmpdir/bup-save" -n test "$tmpdir/save"
90 # this should work anyway
91 WVPASS bup ls -l "test/latest/$tmpdir/save"
92 if ! bup ls -l "test/latest/$tmpdir/save/a" | grep '1999-01-01 00:00 1' ; then
93 WVFAIL unexpected date for file a/1
95 # and ensure we actually failed, and the above script/hack didn't break
96 if ! bup ls -l "test/latest/$tmpdir/save" | grep "1970-01-01 00:00 a" ; then
97 WVFAIL unexpected date for directory a
101 WVSTART "duplicate entries"
102 WVPASS bup index --clear
103 WVPASS bup index "$tmpdir/save"
105 cat > "$tmpdir/bup-save" << EOF
106 #!/usr/bin/env $top/dev/bup-python
107 from bup import index
109 Reader = index.Reader
110 class DupReader(index.Reader):
111 def filter(self, *args, **kw):
112 for transname, ent in Reader.filter(self, *args, **kw):
113 # duplicate a file and a folder
114 if ent.name.endswith(b'/5') or ent.name.endswith(b'/a/'):
117 index.Reader = DupReader
119 exec(open("$top/lib/cmd/bup-save", "rb").read())
121 chmod +x "$tmpdir/bup-save"
123 # use it to save the data
124 "$tmpdir/bup-save" -n test "$tmpdir/save"
127 WVPASS bup ls -l "test/latest/$tmpdir/save"
129 # check that there are no duplicates
130 lsout=$(bup ls -l "test/latest/$tmpdir/save")
131 WVPASSEQ "$(echo "$lsout" | sort | uniq -d)" ""
133 # and we should get the *right* data for each entry
134 for f in $(seq 9) ; do
135 if ! echo "$lsout" | grep "200${f}-01-01 00:00 $f" ; then
136 WVFAIL echo incorrect metadata for $f
141 WVPASS rm -rf "$tmpdir"