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 # Inject save errors while reading metadata via --import-py-module.
33 WVPASS rm -rf "$tmpdir/mod"
34 WVPASS mkdir -p "$tmpdir/mod"
35 cat > "$tmpdir/mod/bup_fail_on_5.py" << EOF
36 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
46 PYTHONPATH="$tmpdir/mod" \
47 bup --import-py-module bup_fail_on_5 save -n test "$tmpdir/save"
49 # this should work anyway
50 WVPASS bup ls -l "test/latest/$tmpdir/save"
51 # also check the *right* data was returned
52 lsout="$(bup ls -l "test/latest/$tmpdir/save")"
53 for f in 1 2 3 4 6 7 8 9 ; do
54 if ! echo "$lsout" | grep "200${f}-01-01 00:00 $f" ; then
55 WVFAIL echo incorrect date for $f
58 # and ensure we actually failed, and the above script/hack didn't break
59 if echo "$lsout" | grep " 5$" ; then
60 WVFAIL echo unexpectedly stored data for file 5
64 WVSTART "metadata read error for a folder"
65 WVPASS bup index --clear
66 WVPASS bup index "$tmpdir/save"
68 # Inject save errors while reading metadata via --import-py-module.
69 WVPASS rm -rf "$tmpdir/mod"
70 WVPASS mkdir -p "$tmpdir/mod"
71 cat > "$tmpdir/mod/bup_fail_on_a.py" << EOF
72 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
82 PYTHONPATH="$tmpdir/mod" \
83 bup --import-py-module bup_fail_on_a save -n test "$tmpdir/save"
85 # this should work anyway
86 WVPASS bup ls -l "test/latest/$tmpdir/save"
87 if ! bup ls -l "test/latest/$tmpdir/save/a" | grep '1999-01-01 00:00 1' ; then
88 WVFAIL unexpected date for file a/1
90 # and ensure we actually failed, and the above script/hack didn't break
91 if ! bup ls -l "test/latest/$tmpdir/save" | grep "1970-01-01 00:00 a" ; then
92 WVFAIL unexpected date for directory a
96 WVSTART "duplicate entries"
97 WVPASS bup index --clear
98 WVPASS bup index "$tmpdir/save"
100 # Inject save errors while reading metadata via --import-py-module.
101 WVPASS rm -rf "$tmpdir/mod"
102 WVPASS mkdir -p "$tmpdir/mod"
103 cat > "$tmpdir/mod/bup_dup_reader_path.py" << EOF
104 from bup import index
106 Reader = index.Reader
107 class DupReader(index.Reader):
108 def filter(self, *args, **kw):
109 for transname, ent in Reader.filter(self, *args, **kw):
110 # duplicate a file and a folder
111 if ent.name.endswith(b'/5') or ent.name.endswith(b'/a/'):
114 index.Reader = DupReader
117 PYTHONPATH="$tmpdir/mod" \
118 bup --import-py-module bup_dup_reader_path save -n test "$tmpdir/save"
121 WVPASS bup ls -l "test/latest/$tmpdir/save"
123 # check that there are no duplicates
124 lsout=$(bup ls -l "test/latest/$tmpdir/save")
125 WVPASSEQ "$(echo "$lsout" | sort | uniq -d)" ""
127 # and we should get the *right* data for each entry
128 for f in $(seq 9) ; do
129 if ! echo "$lsout" | grep "200${f}-01-01 00:00 $f" ; then
130 WVFAIL echo incorrect metadata for $f
135 WVPASS rm -rf "$tmpdir"