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/cmd/bup-python
37 from bup import metadata
38 orig_from_path = metadata.from_path
39 def from_path(path, *args, **kw):
40 if path.endswith(b'/5'):
41 raise IOError('intentionally failing metadata read for .../5')
42 return orig_from_path(path, *args, **kw)
43 metadata.from_path = from_path
45 exec(open("$top/cmd/bup-save", "rb").read())
47 chmod +x "$tmpdir/bup-save"
49 # use it to save the data
50 "$tmpdir/bup-save" -n test "$tmpdir/save"
52 # this should work anyway
53 WVPASS bup ls -l "test/latest/$tmpdir/save"
54 # also check the *right* data was returned
55 lsout="$(bup ls -l "test/latest/$tmpdir/save")"
56 for f in 1 2 3 4 6 7 8 9 ; do
57 if ! echo "$lsout" | grep "200${f}-01-01 00:00 $f" ; then
58 WVFAIL echo incorrect date for $f
61 # and ensure we actually failed, and the above script/hack didn't break
62 if ! echo "$lsout" | grep "1970-01-01 00:00 5" ; then
63 WVFAIL echo unexpected date for file 5
67 WVSTART "metadata read error for a folder"
68 WVPASS bup index --clear
69 WVPASS bup index "$tmpdir/save"
71 cat > "$tmpdir/bup-save" << EOF
72 #!/usr/bin/env $top/cmd/bup-python
73 from bup import metadata
74 orig_from_path = metadata.from_path
75 def from_path(path, *args, **kw):
76 if path.endswith(b'/a'):
77 raise IOError('intentionally failing metadata read for .../a')
78 return orig_from_path(path, *args, **kw)
79 metadata.from_path = from_path
81 exec(open("$top/cmd/bup-save", "rb").read())
83 chmod +x "$tmpdir/bup-save"
85 # use it to save the data
86 "$tmpdir/bup-save" -n test "$tmpdir/save"
88 # this should work anyway
89 WVPASS bup ls -l "test/latest/$tmpdir/save"
90 if ! bup ls -l "test/latest/$tmpdir/save/a" | grep '1999-01-01 00:00 1' ; then
91 WVFAIL unexpected date for file a/1
93 # and ensure we actually failed, and the above script/hack didn't break
94 if ! bup ls -l "test/latest/$tmpdir/save" | grep "1970-01-01 00:00 a" ; then
95 WVFAIL unexpected date for directory a
99 WVSTART "duplicate entries"
100 WVPASS bup index --clear
101 WVPASS bup index "$tmpdir/save"
103 cat > "$tmpdir/bup-save" << EOF
104 #!/usr/bin/env $top/cmd/bup-python
105 from bup import index
107 Reader = index.Reader
108 class DupReader(index.Reader):
109 def filter(self, *args, **kw):
110 for transname, ent in Reader.filter(self, *args, **kw):
111 # duplicate a file and a folder
112 if ent.name.endswith(b'/5') or ent.name.endswith(b'/a/'):
115 index.Reader = DupReader
117 exec(open("$top/cmd/bup-save", "rb").read())
119 chmod +x "$tmpdir/bup-save"
121 # use it to save the data
122 "$tmpdir/bup-save" -n test "$tmpdir/save"
125 WVPASS bup ls -l "test/latest/$tmpdir/save"
127 # check that there are no duplicates
128 lsout=$(bup ls -l "test/latest/$tmpdir/save")
129 WVPASSEQ "$(echo "$lsout" | sort | uniq -d)" ""
131 # and we should get the *right* data for each entry
132 for f in $(seq 9) ; do
133 if ! echo "$lsout" | grep "200${f}-01-01 00:00 $f" ; then
134 WVFAIL echo incorrect metadata for $f
139 WVPASS rm -rf "$tmpdir"