]> arthur.barton.de Git - bup.git/blob - t/test-save-errors
index: fix -H option
[bup.git] / t / test-save-errors
1 #!/usr/bin/env bash
2 . wvtest.sh
3 . wvtest-bup.sh
4 . t/lib.sh
5
6 set -o pipefail
7
8 top="$(WVPASS pwd)" || exit $?
9 tmpdir="$(WVPASS wvmktempdir)" || exit $?
10 export BUP_DIR="$tmpdir/bup"
11
12 bup() { "$top/bup" "$@"; }
13
14 WVPASS cd "$tmpdir"
15
16 # necessary for 0 == 1970-01-01 00:00
17 export TZ=UTC
18
19 WVSTART "init"
20 WVPASS bup init
21
22 mkdir "$tmpdir/save"
23 for f in $(seq 9) ; do
24     touch -t 200${f}01010000 "$tmpdir/save/$f"
25 done
26 mkdir "$tmpdir/save/a"
27 touch -t 199901010000 "$tmpdir/save/a/1"
28
29 WVSTART "metadata read error for a file"
30 WVPASS bup index "$tmpdir/save"
31
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
44
45 exec(open("$top/cmd/bup-save", "rb").read())
46 EOF
47 chmod +x "$tmpdir/bup-save"
48
49 # use it to save the data
50 "$tmpdir/bup-save" -n test "$tmpdir/save"
51
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
59     fi
60 done
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
64 fi
65
66
67 WVSTART "metadata read error for a folder"
68 WVPASS bup index --clear
69 WVPASS bup index "$tmpdir/save"
70
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
80
81 exec(open("$top/cmd/bup-save", "rb").read())
82 EOF
83 chmod +x "$tmpdir/bup-save"
84
85 # use it to save the data
86 "$tmpdir/bup-save" -n test "$tmpdir/save"
87
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
92 fi
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
96 fi
97
98
99 WVSTART "duplicate entries"
100 WVPASS bup index --clear
101 WVPASS bup index "$tmpdir/save"
102
103 cat > "$tmpdir/bup-save" << EOF
104 #!/usr/bin/env $top/cmd/bup-python
105 from bup import index
106
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/'):
113                 yield transname, ent
114             yield transname, ent
115 index.Reader = DupReader
116
117 exec(open("$top/cmd/bup-save", "rb").read())
118 EOF
119 chmod +x "$tmpdir/bup-save"
120
121 # use it to save the data
122 "$tmpdir/bup-save" -n test "$tmpdir/save"
123
124 # this should work
125 WVPASS bup ls -l "test/latest/$tmpdir/save"
126
127 # check that there are no duplicates
128 lsout=$(bup ls -l "test/latest/$tmpdir/save")
129 WVPASSEQ "$(echo "$lsout" | sort | uniq -d)" ""
130
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
135     fi
136 done
137
138
139 WVPASS rm -rf "$tmpdir"