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
38 export PYTHONPATH="$top/lib"
39 exec "$top/cmd/bup-python" "\$0" \${1+"\$@"}
41 from bup import metadata
42 orig_from_path = metadata.from_path
43 def from_path(path, *args, **kw):
44 if path.endswith(b'/5'):
45 raise IOError('intentionally failing metadata read for .../5')
46 return orig_from_path(path, *args, **kw)
47 metadata.from_path = from_path
49 exec(open("$top/cmd/bup-save", "rb").read())
51 chmod +x "$tmpdir/bup-save"
53 # use it to save the data
54 "$tmpdir/bup-save" -n test "$tmpdir/save"
56 # this should work anyway
57 WVPASS bup ls -l "test/latest/$tmpdir/save"
58 # also check the *right* data was returned
59 lsout="$(bup ls -l "test/latest/$tmpdir/save")"
60 for f in 1 2 3 4 6 7 8 9 ; do
61 if ! echo "$lsout" | grep "200${f}-01-01 00:00 $f" ; then
62 WVFAIL echo incorrect date for $f
65 # and ensure we actually failed, and the above script/hack didn't break
66 if ! echo "$lsout" | grep "1970-01-01 00:00 5" ; then
67 WVFAIL echo unexpected date for file 5
71 WVSTART "metadata read error for a folder"
72 WVPASS bup index --clear
73 WVPASS bup index "$tmpdir/save"
75 cat > "$tmpdir/bup-save" << EOF
78 export PYTHONPATH="$top/lib"
79 exec "$top/cmd/bup-python" "\$0" \${1+"\$@"}
81 from bup import metadata
82 orig_from_path = metadata.from_path
83 def from_path(path, *args, **kw):
84 if path.endswith(b'/a'):
85 raise IOError('intentionally failing metadata read for .../a')
86 return orig_from_path(path, *args, **kw)
87 metadata.from_path = from_path
89 exec(open("$top/cmd/bup-save", "rb").read())
91 chmod +x "$tmpdir/bup-save"
93 # use it to save the data
94 "$tmpdir/bup-save" -n test "$tmpdir/save"
96 # this should work anyway
97 WVPASS bup ls -l "test/latest/$tmpdir/save"
98 if ! bup ls -l "test/latest/$tmpdir/save/a" | grep '1999-01-01 00:00 1' ; then
99 WVFAIL unexpected date for file a/1
101 # and ensure we actually failed, and the above script/hack didn't break
102 if ! bup ls -l "test/latest/$tmpdir/save" | grep "1970-01-01 00:00 a" ; then
103 WVFAIL unexpected date for directory a
107 WVSTART "duplicate entries"
108 WVPASS bup index --clear
109 WVPASS bup index "$tmpdir/save"
111 cat > "$tmpdir/bup-save" << EOF
112 #!$top/cmd/bup-python
113 from bup import index
115 Reader = index.Reader
116 class DupReader(index.Reader):
117 def filter(self, *args, **kw):
118 for transname, ent in Reader.filter(self, *args, **kw):
119 # duplicate a file and a folder
120 if ent.name.endswith(b'/5') or ent.name.endswith(b'/a/'):
123 index.Reader = DupReader
125 exec(open("$top/cmd/bup-save", "rb").read())
127 chmod +x "$tmpdir/bup-save"
129 # use it to save the data
130 "$tmpdir/bup-save" -n test "$tmpdir/save"
133 WVPASS bup ls -l "test/latest/$tmpdir/save"
135 # check that there are no duplicates
136 lsout=$(bup ls -l "test/latest/$tmpdir/save")
137 WVPASSEQ "$(echo "$lsout" | sort | uniq -d)" ""
139 # and we should get the *right* data for each entry
140 for f in $(seq 9) ; do
141 if ! echo "$lsout" | grep "200${f}-01-01 00:00 $f" ; then
142 WVFAIL echo incorrect metadata for $f
147 WVPASS rm -rf "$tmpdir"