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
38 sys.path[:0] = [os.path.dirname(os.path.realpath(__file__)) + '/../../../lib']
39 from bup import metadata
41 orig_from_path = metadata.from_path
42 def from_path(path, *args, **kw):
43 if path.endswith(b'/5'):
44 raise IOError('intentionally failing metadata read for .../5')
45 return orig_from_path(path, *args, **kw)
46 metadata.from_path = from_path
48 exec(open("$top/cmd/bup-save", "rb").read())
50 chmod +x "$tmpdir/bup-save"
52 # use it to save the data
53 "$tmpdir/bup-save" -n test "$tmpdir/save"
55 # this should work anyway
56 WVPASS bup ls -l "test/latest/$tmpdir/save"
57 # also check the *right* data was returned
58 lsout="$(bup ls -l "test/latest/$tmpdir/save")"
59 for f in 1 2 3 4 6 7 8 9 ; do
60 if ! echo "$lsout" | grep "200${f}-01-01 00:00 $f" ; then
61 WVFAIL echo incorrect date for $f
64 # and ensure we actually failed, and the above script/hack didn't break
65 if ! echo "$lsout" | grep "1970-01-01 00:00 5" ; then
66 WVFAIL echo unexpected date for file 5
70 WVSTART "metadata read error for a folder"
71 WVPASS bup index --clear
72 WVPASS bup index "$tmpdir/save"
74 cat > "$tmpdir/bup-save" << EOF
75 #!/usr/bin/env $top/cmd/bup-python
77 sys.path[:0] = [os.path.dirname(os.path.realpath(__file__)) + '/../../../lib']
78 from bup import metadata
80 orig_from_path = metadata.from_path
81 def from_path(path, *args, **kw):
82 if path.endswith(b'/a'):
83 raise IOError('intentionally failing metadata read for .../a')
84 return orig_from_path(path, *args, **kw)
85 metadata.from_path = from_path
87 exec(open("$top/cmd/bup-save", "rb").read())
89 chmod +x "$tmpdir/bup-save"
91 # use it to save the data
92 "$tmpdir/bup-save" -n test "$tmpdir/save"
94 # this should work anyway
95 WVPASS bup ls -l "test/latest/$tmpdir/save"
96 if ! bup ls -l "test/latest/$tmpdir/save/a" | grep '1999-01-01 00:00 1' ; then
97 WVFAIL unexpected date for file a/1
99 # and ensure we actually failed, and the above script/hack didn't break
100 if ! bup ls -l "test/latest/$tmpdir/save" | grep "1970-01-01 00:00 a" ; then
101 WVFAIL unexpected date for directory a
105 WVSTART "duplicate entries"
106 WVPASS bup index --clear
107 WVPASS bup index "$tmpdir/save"
109 cat > "$tmpdir/bup-save" << EOF
110 #!/usr/bin/env $top/cmd/bup-python
112 sys.path[:0] = [os.path.dirname(os.path.realpath(__file__)) + '/../../../lib']
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"