]> arthur.barton.de Git - bup.git/blob - t/test.sh
Move the --exclude-rx tests from test.sh to test-save-restore-exclude-rx.sh.
[bup.git] / t / test.sh
1 #!/usr/bin/env bash
2 . wvtest.sh
3 . t/lib.sh
4
5 set -o pipefail
6
7 TOP="$(WVPASS /bin/pwd)" || exit $?
8 export BUP_DIR="$TOP/buptest.tmp"
9
10 bup()
11 {
12     "$TOP/bup" "$@"
13 }
14
15 WVSTART "init"
16
17 WVPASS rm -rf "$BUP_DIR"
18 WVPASS bup init
19
20 WVSTART "index"
21 D=bupdata.tmp
22 WVPASS force-delete $D
23 WVPASS mkdir $D
24 WVFAIL bup index --exclude-from $D/cannot-exist $D
25 WVPASSEQ "$(bup index --check -p)" ""
26 WVPASSEQ "$(bup index --check -p $D)" ""
27 WVFAIL [ -e $D.fake ]
28 WVFAIL bup index --check -u $D.fake
29 WVPASS bup index --check -u $D
30 WVPASSEQ "$(bup index --check -p $D)" "$D/"
31 WVPASS touch $D/a
32 WVPASS bup random 128k >$D/b
33 WVPASS mkdir $D/d $D/d/e
34 WVPASS bup random 512 >$D/f
35 WVPASS ln -s non-existent-file $D/g
36 WVPASSEQ "$(bup index -s $D/)" "A $D/"
37 WVPASSEQ "$(bup index -s $D/b)" ""
38 WVPASSEQ "$(bup index --check -us $D/b)" "A $D/b"
39 WVPASSEQ "$(bup index --check -us $D/b $D/d)" \
40 "A $D/d/e/
41 A $D/d/
42 A $D/b"
43 WVPASS touch $D/d/z
44 WVPASS bup tick
45 WVPASSEQ "$(bup index --check -usx $D)" \
46 "A $D/g
47 A $D/f
48 A $D/d/z
49 A $D/d/e/
50 A $D/d/
51 A $D/b
52 A $D/a
53 A $D/"
54 WVPASSEQ "$(bup index --check -us $D/a $D/b --fake-valid)" \
55 "  $D/b
56   $D/a"
57 WVPASSEQ "$(bup index --check -us $D/a)" "  $D/a"  # stays unmodified
58 WVPASSEQ "$(bup index --check -us $D/d --fake-valid)" \
59 "  $D/d/z
60   $D/d/e/
61   $D/d/"
62 WVPASS touch $D/d/z
63 WVPASS bup index -u $D/d/z  # becomes modified
64 WVPASSEQ "$(bup index -s $D/a $D $D/b)" \
65 "A $D/g
66 A $D/f
67 M $D/d/z
68   $D/d/e/
69 M $D/d/
70   $D/b
71   $D/a
72 A $D/"
73
74 WVPASS bup index -u $D/d/e $D/a --fake-invalid
75 WVPASSEQ "$(cd $D && bup index -m .)" \
76 "./g
77 ./f
78 ./d/z
79 ./d/e/
80 ./d/
81 ./a
82 ./"
83 WVPASSEQ "$(cd $D && bup index -m)" \
84 "g
85 f
86 d/z
87 d/e/
88 d/
89 a
90 ./"
91 WVPASSEQ "$(cd $D && bup index -s .)" "$(cd $D && bup index -s .)"
92
93 WVFAIL bup save -t $D/doesnt-exist-filename
94
95 WVPASS mv $BUP_DIR/bupindex $BUP_DIR/bi.old
96 WVFAIL bup save -t $D/d/e/fifotest
97 WVPASS mkfifo $D/d/e/fifotest
98 WVPASS bup index -u $D/d/e/fifotest
99 WVPASS bup save -t $D/d/e/fifotest
100 WVPASS bup save -t $D/d/e
101 WVPASS rm -f $D/d/e/fifotest
102 WVPASS bup index -u $D/d/e
103 WVFAIL bup save -t $D/d/e/fifotest
104 WVPASS mv $BUP_DIR/bi.old $BUP_DIR/bupindex
105
106 WVPASS bup index -u $D/d/e
107 WVPASS bup save -t $D/d/e
108 WVPASSEQ "$(cd $D && bup index -m)" \
109 "g
110 f
111 d/z
112 d/
113 a
114 ./"
115 WVPASS bup save -t $D/d
116 WVPASS bup index --fake-invalid $D/d/z
117 WVPASS bup save -t $D/d/z
118 WVPASS bup save -t $D/d/z  # test regenerating trees when no files are changed
119 WVPASS bup save -t $D/d
120 WVPASSEQ "$(cd $D && bup index -m)" \
121 "g
122 f
123 a
124 ./"
125 WVPASS bup save -r :$BUP_DIR -n r-test $D
126 WVFAIL bup save -r :$BUP_DIR/fake/path -n r-test $D
127 WVFAIL bup save -r :$BUP_DIR -n r-test $D/fake/path
128
129 WVSTART "split"
130 WVPASS echo a >a.tmp
131 WVPASS echo b >b.tmp
132 WVPASS bup split -b a.tmp >taga.tmp
133 WVPASS bup split -b b.tmp >tagb.tmp
134 WVPASS cat a.tmp b.tmp | WVPASS bup split -b >tagab.tmp
135 WVPASSEQ $(cat taga.tmp | wc -l) 1
136 WVPASSEQ $(cat tagb.tmp | wc -l) 1
137 WVPASSEQ $(cat tagab.tmp | wc -l) 1
138 WVPASSEQ $(cat tag[ab].tmp | wc -l) 2
139 WVPASSEQ "$(bup split -b a.tmp b.tmp)" "$(cat tagab.tmp)"
140 WVPASSEQ "$(bup split -b --keep-boundaries a.tmp b.tmp)" "$(cat tag[ab].tmp)"
141 WVPASSEQ "$(cat tag[ab].tmp | bup split -b --keep-boundaries --git-ids)" \
142          "$(cat tag[ab].tmp)"
143 WVPASSEQ "$(cat tag[ab].tmp | bup split -b --git-ids)" \
144          "$(cat tagab.tmp)"
145 WVPASS bup split --bench -b <t/testfile1 >tags1.tmp
146 WVPASS bup split -vvvv -b t/testfile2 >tags2.tmp
147 WVPASS bup margin
148 WVPASS bup midx -f
149 WVPASS bup midx --check -a
150 WVPASS bup midx -o $BUP_DIR/objects/pack/test1.midx \
151         $BUP_DIR/objects/pack/*.idx
152 WVPASS bup midx --check -a
153 WVPASS bup midx -o $BUP_DIR/objects/pack/test1.midx \
154         $BUP_DIR/objects/pack/*.idx \
155         $BUP_DIR/objects/pack/*.idx
156 WVPASS bup midx --check -a
157 all=$(echo $BUP_DIR/objects/pack/*.idx $BUP_DIR/objects/pack/*.midx)
158 WVPASS bup midx -o $BUP_DIR/objects/pack/zzz.midx $all
159 WVPASS bup tick
160 WVPASS bup midx -o $BUP_DIR/objects/pack/yyy.midx $all
161 WVPASS bup midx -a
162 WVPASSEQ "$(echo $BUP_DIR/objects/pack/*.midx)" \
163         "$BUP_DIR/objects/pack/yyy.midx"
164 WVPASS bup margin
165 WVPASS bup split -t t/testfile2 >tags2t.tmp
166 WVPASS bup split -t t/testfile2 --fanout 3 >tags2tf.tmp
167 WVPASS bup split -r "$BUP_DIR" -c t/testfile2 >tags2c.tmp
168 WVPASS bup split -r :$BUP_DIR -c t/testfile2 >tags2c.tmp
169 WVPASS ls -lR \
170     | WVPASS bup split -r :$BUP_DIR -c --fanout 3 --max-pack-objects 3 -n lslr \
171     || exit $?
172 WVPASS bup ls
173 WVFAIL bup ls /does-not-exist
174 WVPASS bup ls /lslr
175 WVPASS bup ls /lslr/latest
176 WVPASS bup ls /lslr/latest/
177 #WVPASS bup ls /lslr/1971-01-01   # all dates always exist
178 WVFAIL diff -u tags1.tmp tags2.tmp
179
180 # fanout must be different from non-fanout
181 WVFAIL diff tags2t.tmp tags2tf.tmp
182 WVPASS wc -c t/testfile1 t/testfile2
183 WVPASS wc -l tags1.tmp tags2.tmp
184
185 WVSTART "bloom"
186 WVPASS bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
187 WVPASS rm $BUP_DIR/objects/pack/bup.bloom
188 WVPASS bup bloom -k 4
189 WVPASS bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
190 WVPASS bup bloom -d buptest.tmp/objects/pack --ruin --force
191 WVFAIL bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
192 WVPASS bup bloom --force -k 5
193 WVPASS bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
194
195 WVSTART "memtest"
196 WVPASS bup memtest -c1 -n100
197 WVPASS bup memtest -c1 -n100 --existing
198
199 WVSTART "join"
200 WVPASS bup join $(cat tags1.tmp) >out1.tmp
201 WVPASS bup join <tags2.tmp >out2.tmp
202 WVPASS bup join <tags2t.tmp -o out2t.tmp
203 WVPASS bup join -r "$BUP_DIR" <tags2c.tmp >out2c.tmp
204 WVPASS bup join -r ":$BUP_DIR" <tags2c.tmp >out2c.tmp
205 WVPASS diff -u t/testfile1 out1.tmp
206 WVPASS diff -u t/testfile2 out2.tmp
207 WVPASS diff -u t/testfile2 out2t.tmp
208 WVPASS diff -u t/testfile2 out2c.tmp
209
210 WVSTART "save/git-fsck"
211 (
212     WVPASS cd "$BUP_DIR"
213     #git repack -Ad
214     #git prune
215     (WVPASS cd "$TOP/t/sampledata" && WVPASS bup save -vvn master /) || exit $?
216     result="$(git fsck --full --strict 2>&1)" || exit $?
217     n=$(echo "$result" |
218         WVFAIL egrep -v 'dangling (commit|tree|blob)' |
219         WVPASS tee -a /dev/stderr |
220         WVPASS wc -l) || exit $?
221     WVPASS [ "$n" -eq 0 ]
222 ) || exit $?
223
224 WVSTART "restore"
225 WVPASS force-delete buprestore.tmp
226 WVFAIL bup restore boink
227 WVPASS touch $TOP/$D/$D
228 WVPASS bup index -u $TOP/$D
229 WVPASS bup save -n master /
230 WVPASS bup restore -C buprestore.tmp "/master/latest/$TOP/$D"
231 WVPASSEQ "$(ls buprestore.tmp)" "bupdata.tmp"
232 WVPASS force-delete buprestore.tmp
233 WVPASS bup restore -C buprestore.tmp "/master/latest/$TOP/$D/"
234 WVPASS touch $D/non-existent-file buprestore.tmp/non-existent-file # else diff fails
235 WVPASS diff -ur $D/ buprestore.tmp/
236
237 (
238     tmp=testrestore.tmp
239     WVPASS force-delete $tmp
240     WVPASS mkdir $tmp
241     export BUP_DIR="$(pwd)/$tmp/bup"
242     WVPASS WVPASS bup init
243     WVPASS mkdir -p $tmp/src/x/y/z
244     WVPASS bup random 8k > $tmp/src/x/y/random-1
245     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
246     WVPASS bup index -u $tmp/src
247     WVPASS bup save --strip -n foo $tmp/src
248
249     WVSTART "restore /foo/latest"
250     WVPASS bup restore -C $tmp/restore /foo/latest
251     WVPASS t/compare-trees $tmp/src/ $tmp/restore/latest/
252
253     WVSTART "restore /foo/latest/"
254     WVPASS force-delete "$tmp/restore"
255     WVPASS bup restore -C $tmp/restore /foo/latest/
256     for x in $tmp/src/*; do
257         WVPASS t/compare-trees $x/ $tmp/restore/$(basename $x);
258     done
259
260     WVSTART "restore /foo/latest/."
261     WVPASS force-delete "$tmp/restore"
262     WVPASS bup restore -C $tmp/restore /foo/latest/.
263     WVPASS t/compare-trees $tmp/src/ $tmp/restore/
264
265     WVSTART "restore /foo/latest/x"
266     WVPASS force-delete "$tmp/restore"
267     WVPASS bup restore -C $tmp/restore /foo/latest/x
268     WVPASS t/compare-trees $tmp/src/x/ $tmp/restore/x/
269
270     WVSTART "restore /foo/latest/x/"
271     WVPASS force-delete "$tmp/restore"
272     WVPASS bup restore -C $tmp/restore /foo/latest/x/
273     for x in $tmp/src/x/*; do
274         WVPASS t/compare-trees $x/ $tmp/restore/$(basename $x);
275     done
276
277     WVSTART "restore /foo/latest/x/."
278     WVPASS force-delete "$tmp/restore"
279     WVPASS bup restore -C $tmp/restore /foo/latest/x/.
280     WVPASS t/compare-trees $tmp/src/x/ $tmp/restore/
281 ) || exit $?
282
283
284 WVSTART "ftp"
285 WVPASS bup ftp "cat /master/latest/$TOP/$D/b" >$D/b.new
286 WVPASS bup ftp "cat /master/latest/$TOP/$D/f" >$D/f.new
287 WVPASS bup ftp "cat /master/latest/$TOP/$D/f"{,} >$D/f2.new
288 WVPASS bup ftp "cat /master/latest/$TOP/$D/a" >$D/a.new
289 WVPASSEQ "$(sha1sum <$D/b)" "$(sha1sum <$D/b.new)"
290 WVPASSEQ "$(sha1sum <$D/f)" "$(sha1sum <$D/f.new)"
291 WVPASSEQ "$(cat $D/f.new{,} | sha1sum)" "$(sha1sum <$D/f2.new)"
292 WVPASSEQ "$(sha1sum <$D/a)" "$(sha1sum <$D/a.new)"
293
294 WVSTART "tag"
295 WVFAIL bup tag -d v0.n 2>/dev/null
296 WVFAIL bup tag v0.n non-existant 2>/dev/null
297 WVPASSEQ "$(bup tag)" ""
298 WVPASS bup tag v0.1 master
299 WVPASSEQ "$(bup tag)" "v0.1"
300 WVFAIL bup tag v0.1 master
301 WVPASS bup tag -f v0.1 master
302 WVPASS bup tag -d v0.1
303 WVPASS bup tag -f -d v0.1
304 WVFAIL bup tag -d v0.1
305
306 # This section destroys data in the bup repository, so it is done last.
307 WVSTART "fsck"
308 WVPASS bup fsck
309 WVPASS bup fsck --quick
310 if bup fsck --par2-ok; then
311     WVSTART "fsck (par2)"
312 else
313     WVSTART "fsck (PAR2 IS MISSING)"
314 fi
315 WVPASS bup fsck -g
316 WVPASS bup fsck -r
317 WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n10 -s1 -S0
318 WVFAIL bup fsck --quick
319 WVFAIL bup fsck --quick --disable-par2
320 WVPASS chmod u+w $BUP_DIR/objects/pack/*.idx
321 WVPASS bup damage $BUP_DIR/objects/pack/*.idx -n10 -s1 -S0
322 WVFAIL bup fsck --quick -j4
323 WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n10 -s1024 --percent 0.4 -S0
324 WVFAIL bup fsck --quick
325 WVFAIL bup fsck --quick -rvv -j99   # fails because repairs were needed
326 if bup fsck --par2-ok; then
327     WVPASS bup fsck -r # ok because of repairs from last time
328     WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n202 -s1 --equal -S0
329     WVFAIL bup fsck
330     WVFAIL bup fsck -rvv   # too many errors to be repairable
331     WVFAIL bup fsck -r   # too many errors to be repairable
332 else
333     WVFAIL bup fsck --quick -r # still fails because par2 was missing
334 fi
335
336 WVSTART "exclude-bupdir"
337 D=exclude-bupdir.tmp
338 WVPASS force-delete $D
339 WVPASS mkdir $D
340 export BUP_DIR="$D/.bup"
341 WVPASS bup init
342 WVPASS touch $D/a
343 WVPASS bup random 128k >$D/b
344 WVPASS mkdir $D/d $D/d/e
345 WVPASS bup random 512 >$D/f
346 WVPASS bup index -ux $D
347 WVPASS bup save -n exclude-bupdir $D
348 WVPASSEQ "$(bup ls -a exclude-bupdir/latest/$TOP/$D/)" "a
349 b
350 d/
351 f"
352
353 WVSTART "exclude"
354 (
355     D=exclude.tmp
356     WVPASS force-delete $D
357     WVPASS mkdir $D
358     export BUP_DIR="$D/.bup"
359     WVPASS bup init
360     WVPASS touch $D/a
361     WVPASS bup random 128k >$D/b
362     WVPASS mkdir $D/d $D/d/e
363     WVPASS bup random 512 >$D/f
364     WVPASS bup random 512 >$D/j
365     WVPASS bup index -ux --exclude $D/d --exclude $D/j $D
366     WVPASS bup save -n exclude $D
367     WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
368 b
369 f"
370     WVPASS mkdir $D/g $D/h
371     WVPASS bup index -ux --exclude $D/d --exclude $TOP/$D/g --exclude $D/h \
372         --exclude $TOP/$D/j $D
373     WVPASS bup save -n exclude $D
374     WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
375 b
376 f"
377 ) || exit $?
378
379 WVSTART "exclude-from"
380 (
381     D=exclude-fromdir.tmp
382     EXCLUDE_FILE=exclude-from.tmp
383     WVPASS echo "$D/d 
384  $TOP/$D/g
385 $D/h
386 $D/i" > $EXCLUDE_FILE
387     WVPASS force-delete $D
388     WVPASS mkdir $D
389     export BUP_DIR="$D/.bup"
390     WVPASS bup init
391     WVPASS touch $D/a
392     WVPASS bup random 128k >$D/b
393     WVPASS mkdir $D/d $D/d/e
394     WVPASS bup random 512 >$D/f
395     WVPASS mkdir $D/g $D/h
396     WVPASS bup random 128k > $D/i
397     WVPASS bup index -ux --exclude-from $EXCLUDE_FILE $D
398     WVPASS bup save -n exclude-from $D
399     WVPASSEQ "$(bup ls exclude-from/latest/$TOP/$D/)" "a
400 b
401 f"
402     WVPASS rm $EXCLUDE_FILE
403 ) || exit $?
404
405 WVSTART "save (no index)"
406 (
407     tmp=save-no-index.tmp
408     WVPASS force-delete $tmp
409     WVPASS mkdir $tmp
410     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
411     WVPASS bup init
412     WVFAIL bup save -n nothing /
413     WVPASS rm -r "$tmp"
414 ) || exit $?
415
416 WVSTART "save --strip"
417 (
418     tmp=graft-points.tmp
419     WVPASS force-delete $tmp
420     WVPASS mkdir $tmp
421     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
422     WVPASS bup init
423     WVPASS mkdir -p $tmp/src/x/y/z
424     WVPASS bup random 8k > $tmp/src/x/y/random-1
425     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
426     WVPASS bup index -u $tmp/src
427     WVPASS bup save --strip -n foo $tmp/src/x/y
428     WVPASS bup restore -C $tmp/restore /foo/latest
429     WVPASS t/compare-trees $tmp/src/x/y/ "$tmp/restore/latest/"
430 ) || exit $?
431
432 WVSTART "save --strip-path (relative)"
433 (
434     tmp=graft-points.tmp
435     WVPASS force-delete $tmp
436     WVPASS mkdir $tmp
437     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
438     WVPASS bup init
439     WVPASS mkdir -p $tmp/src/x/y/z
440     WVPASS bup random 8k > $tmp/src/x/y/random-1
441     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
442     WVPASS bup index -u $tmp/src
443     WVPASS bup save --strip-path $tmp/src -n foo $tmp/src/x
444     WVPASS bup restore -C $tmp/restore /foo/latest
445     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/"
446 ) || exit $?
447
448 WVSTART "save --strip-path (absolute)"
449 (
450     tmp=graft-points.tmp
451     WVPASS force-delete $tmp
452     WVPASS mkdir $tmp
453     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
454     WVPASS bup init
455     WVPASS mkdir -p $tmp/src/x/y/z
456     WVPASS bup random 8k > $tmp/src/x/y/random-1
457     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
458     WVPASS bup index -u $tmp/src
459     WVPASS bup save --strip-path "$TOP" -n foo $tmp/src
460     WVPASS bup restore -C $tmp/restore /foo/latest
461     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/$tmp/src/"
462 ) || exit $?
463
464 WVSTART "save --strip-path (no match)"
465 (
466     if test $(WVPASS path-filesystems . | WVPASS sort -u | WVPASS wc -l) -ne 1
467     then
468         # Skip the test because the attempt to restore parent dirs to
469         # the current filesystem may fail -- i.e. running from
470         # /foo/ext4/bar/btrfs will fail when bup tries to restore
471         # linux attrs above btrfs to the restore tree *inside* btrfs.
472         echo "(running from tree with mixed filesystems; skipping test)" 1>&2
473         exit 0
474     fi
475
476     tmp=graft-points.tmp
477     WVPASS force-delete $tmp
478     WVPASS mkdir $tmp
479     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
480     WVPASS bup init
481     WVPASS mkdir -p $tmp/src/x/y/z
482     WVPASS bup random 8k > $tmp/src/x/y/random-1
483     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
484     WVPASS bup index -u $tmp/src
485     WVPASS bup save --strip-path $tmp/foo -n foo $tmp/src/x
486     WVPASS bup restore -C $tmp/restore /foo/latest
487     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/$TOP/$tmp/src/"
488 ) || exit $?
489
490 WVSTART "save --graft (empty graft points disallowed)"
491 (
492     tmp=graft-points.tmp
493     WVPASS force-delete $tmp
494     WVPASS mkdir $tmp
495     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
496     WVPASS bup init
497     WVFAIL bup save --graft =/grafted -n graft-point-absolute $tmp
498     WVFAIL bup save --graft $TOP/$tmp= -n graft-point-absolute $tmp
499 ) || exit $?
500
501 WVSTART "save --graft /x/y=/a/b (relative paths)"
502 (
503     tmp=graft-points.tmp
504     WVPASS force-delete $tmp
505     WVPASS mkdir $tmp
506     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
507     WVPASS bup init
508     WVPASS mkdir -p $tmp/src/x/y/z
509     WVPASS bup random 8k > $tmp/src/x/y/random-1
510     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
511     WVPASS bup index -u $tmp/src
512     WVPASS bup save --graft $tmp/src=x -n foo $tmp/src
513     WVPASS bup restore -C $tmp/restore /foo/latest
514     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/$TOP/x/"
515 ) || exit $?
516
517 WVSTART "save --graft /x/y=/a/b (matching structure)"
518 (
519     tmp=graft-points.tmp
520     WVPASS force-delete $tmp
521     WVPASS mkdir $tmp
522     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
523     WVPASS bup init
524     WVPASS mkdir -p $tmp/src/x/y/z
525     WVPASS bup random 8k > $tmp/src/x/y/random-1
526     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
527     WVPASS bup index -u $tmp/src
528     WVPASS bup save -v --graft "$TOP/$tmp/src/x/y=$TOP/$tmp/src/a/b" \
529         -n foo $tmp/src/x/y
530     WVPASS bup restore -C $tmp/restore /foo/latest
531     WVPASS t/compare-trees $tmp/src/x/y/ \
532         "$tmp/restore/latest/$TOP/$tmp/src/a/b/"
533 ) || exit $?
534
535 WVSTART "save --graft /x/y=/a (shorter target)"
536 (
537     tmp=graft-points.tmp
538     WVPASS force-delete $tmp
539     WVPASS mkdir $tmp
540     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
541     WVPASS bup init
542     WVPASS mkdir -p $tmp/src/x/y/z
543     WVPASS bup random 8k > $tmp/src/x/y/random-1
544     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
545     WVPASS bup index -u $tmp/src
546     WVPASS bup save -v --graft "$TOP/$tmp/src/x/y=/a" -n foo $tmp/src/x/y
547     WVPASS bup restore -C $tmp/restore /foo/latest
548     WVPASS t/compare-trees $tmp/src/x/y/ "$tmp/restore/latest/a/"
549 ) || exit $?
550
551 WVSTART "save --graft /x=/a/b (longer target)"
552 (
553     tmp=graft-points.tmp
554     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
555     WVPASS force-delete $tmp
556     WVPASS mkdir $tmp
557     WVPASS bup init
558     WVPASS mkdir -p $tmp/src/x/y/z
559     WVPASS bup random 8k > $tmp/src/x/y/random-1
560     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
561     WVPASS bup index -u $tmp/src
562     WVPASS bup save -v --graft "$TOP/$tmp/src=$TOP/$tmp/src/a/b/c" \
563         -n foo $tmp/src
564     WVPASS bup restore -C $tmp/restore /foo/latest
565     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/$TOP/$tmp/src/a/b/c/"
566 ) || exit $?
567
568 WVSTART "save --graft /x=/ (root target)"
569 (
570     tmp=graft-points.tmp
571     export BUP_DIR="$(WVPASS pwd)/$tmp/bup" || exit $?
572     WVPASS force-delete $tmp
573     WVPASS mkdir $tmp
574     WVPASS bup init
575     WVPASS mkdir -p $tmp/src/x/y/z
576     WVPASS bup random 8k > $tmp/src/x/y/random-1
577     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
578     WVPASS bup index -u $tmp/src
579     WVPASS bup save -v --graft "$TOP/$tmp/src/x=/" -n foo $tmp/src/x
580     WVPASS bup restore -C $tmp/restore /foo/latest
581     WVPASS t/compare-trees $tmp/src/x/ "$tmp/restore/latest/"
582 ) || exit $?
583
584 #WVSTART "save --graft /=/x/ (root source)"
585 # FIXME: Not tested for now -- will require cleverness, or caution as root.
586
587 WVSTART "indexfile"
588 D=indexfile.tmp
589 INDEXFILE=tmpindexfile.tmp
590 WVPASS rm -f $INDEXFILE
591 WVPASS force-delete $D
592 WVPASS mkdir $D
593 export BUP_DIR="$D/.bup"
594 WVPASS bup init
595 WVPASS touch $D/a
596 WVPASS touch $D/b
597 WVPASS mkdir $D/c
598 WVPASS bup index -ux $D
599 WVPASS bup save --strip -n bupdir $D
600 WVPASSEQ "$(bup ls bupdir/latest/)" "a
601 b
602 c/"
603 WVPASS bup index -f $INDEXFILE --exclude=$D/c -ux $D
604 WVPASS bup save --strip -n indexfile -f $INDEXFILE $D
605 WVPASSEQ "$(bup ls indexfile/latest/)" "a
606 b"
607
608
609 WVSTART "import-rsnapshot"
610 D=rsnapshot.tmp
611 export BUP_DIR="$TOP/$D/.bup"
612 WVPASS force-delete $D
613 WVPASS mkdir $D
614 WVPASS bup init
615 WVPASS mkdir -p $D/hourly.0/buptest/a
616 WVPASS touch $D/hourly.0/buptest/a/b
617 WVPASS mkdir -p $D/hourly.0/buptest/c/d
618 WVPASS touch $D/hourly.0/buptest/c/d/e
619 WVPASS true
620 WVPASS bup import-rsnapshot $D/
621 WVPASSEQ "$(bup ls buptest/latest/)" "a/
622 c/"
623
624
625 if [ "$(type -p rdiff-backup)" != "" ]; then
626     WVSTART "import-rdiff-backup"
627     D=rdiff-backup.tmp
628     export BUP_DIR="$TOP/$D/.bup"
629     WVPASS force-delete $D
630     WVPASS mkdir $D
631     WVPASS bup init
632     WVPASS mkdir $D/rdiff-backup
633     WVPASS rdiff-backup $TOP/cmd $D/rdiff-backup
634     WVPASS bup tick
635     WVPASS rdiff-backup $TOP/Documentation $D/rdiff-backup
636     WVPASS bup import-rdiff-backup $D/rdiff-backup import-rdiff-backup
637     WVPASSEQ $(bup ls import-rdiff-backup/ | wc -l) 3
638     WVPASSEQ "$(bup ls -a import-rdiff-backup/latest/ | sort)" \
639         "$(ls -A $TOP/Documentation | sort)"
640 fi
641
642
643 WVSTART "compression"
644 D=compression0.tmp
645 export BUP_DIR="$TOP/$D/.bup"
646 WVPASS force-delete $D
647 WVPASS mkdir $D
648 WVPASS bup init
649 WVPASS bup index $TOP/Documentation
650 WVPASS bup save -n compression -0 --strip $TOP/Documentation
651 # 'ls' on NetBSD sets -A by default when running as root, so we have to undo
652 # it by grepping out any dotfiles.  (Normal OSes don't auto-set -A, but this
653 # is harmless there.)
654 expected="$(WVPASS ls $TOP/Documentation | grep -v '^\.' | WVPASS sort)" \
655     || exit $?
656 actual="$(WVPASS bup ls compression/latest/ | WVPASS sort)" || exit $?
657 WVPASSEQ "$actual" "$expected"
658 COMPRESSION_0_SIZE=$(WVPASS du -k -s $D | WVPASS cut -f1) || exit $?
659
660 D=compression9.tmp
661 export BUP_DIR="$TOP/$D/.bup"
662 WVPASS force-delete $D
663 WVPASS mkdir $D
664 WVPASS bup init
665 WVPASS bup index $TOP/Documentation
666 WVPASS bup save -n compression -9 --strip $TOP/Documentation
667 WVPASSEQ "$(bup ls compression/latest/ | sort)" \
668          "$(ls $TOP/Documentation | grep -v '^\.' | sort)"
669 COMPRESSION_9_SIZE=$(WVPASS du -k -s $D | WVPASS cut -f1) || exit $?
670
671 WVPASS [ "$COMPRESSION_9_SIZE" -lt "$COMPRESSION_0_SIZE" ]
672
673 WVSTART "save disjoint top-level directories"
674 (
675     # Resolve any symlinks involving the top top-level dirs.
676     real_pwd="$(WVPASS realpath .)" || exit $?
677     real_tmp="$(WVPASS realpath /tmp/.)" || exit $?
678     pwd_top="$(echo $real_pwd | WVPASS awk -F "/" '{print $2}')" || exit $?
679     tmp_top="$(echo $real_tmp | WVPASS awk -F "/" '{print $2}')" || exit $?
680
681     if [ "$pwd_top" = "$tmp_top" ]; then
682         echo "(running from within /$tmp_top; skipping test)" 1>&2
683         exit 0
684     fi
685     D=bupdata.tmp
686     WVPASS force-delete $D
687     WVPASS mkdir -p $D/x
688     WVPASS date > $D/x/1
689     tmpdir="$(WVPASS mktemp -d $real_tmp/bup-test-XXXXXXX)" || exit $?
690     cleanup() { WVPASS rm -r "${tmpdir}"; }
691     WVPASS trap cleanup EXIT
692     WVPASS date > "$tmpdir/2"
693
694     export BUP_DIR="$TOP/buptest.tmp"
695     WVPASS test -d "$BUP_DIR" && WVPASS rm -r "$BUP_DIR"
696
697     WVPASS bup init
698     WVPASS bup index -vu $(pwd)/$D/x "$tmpdir"
699     WVPASS bup save -t -n src $(pwd)/$D/x "$tmpdir"
700
701     # For now, assume that "ls -a" and "sort" use the same order.
702     actual="$(WVPASS bup ls -a src/latest)" || exit $?
703     expected="$(echo -e "$pwd_top/\n$tmp_top/" | WVPASS sort)" || exit $?
704     WVPASSEQ "$actual" "$expected"
705 ) || exit $?
706
707 WVSTART "clear-index"
708 D=clear-index.tmp
709 export BUP_DIR="$TOP/$D/.bup"
710 WVPASS force-delete $TOP/$D
711 WVPASS mkdir $TOP/$D
712 WVPASS bup init
713 WVPASS touch $TOP/$D/foo
714 WVPASS touch $TOP/$D/bar
715 WVPASS bup index -u $D
716 WVPASSEQ "$(bup index -p)" "$D/foo
717 $D/bar
718 $D/
719 ./"
720 WVPASS rm $TOP/$D/foo
721 WVPASS bup index --clear
722 WVPASS bup index -u $TOP/$D
723 expected="$(WVPASS bup index -p)" || exit $?
724 WVPASSEQ "$expected" "$D/bar
725 $D/
726 ./"