]> arthur.barton.de Git - bup.git/blob - t/test.sh
Be more careful when testing that repeated saves can produce the same tree.
[bup.git] / t / test.sh
1 #!/usr/bin/env bash
2 . wvtest.sh
3 . t/lib.sh
4
5 #set -e
6
7 TOP="$(/bin/pwd)"
8 export BUP_DIR="$TOP/buptest.tmp"
9
10 bup()
11 {
12     "$TOP/bup" "$@"
13 }
14
15 WVSTART "init"
16
17 #set -x
18 test -d "$BUP_DIR" && rm -r "$BUP_DIR"
19 WVPASS bup init
20
21 WVSTART "index"
22 D=bupdata.tmp
23 force-delete $D
24 mkdir $D
25 WVFAIL bup index --exclude-from $D/cannot-exist $D
26 WVPASSEQ "$(bup index --check -p)" ""
27 WVPASSEQ "$(bup index --check -p $D)" ""
28 WVFAIL [ -e $D.fake ]
29 WVFAIL bup index --check -u $D.fake
30 WVPASS bup index --check -u $D
31 WVPASSEQ "$(bup index --check -p $D)" "$D/"
32 touch $D/a
33 WVPASS bup random 128k >$D/b
34 mkdir $D/d $D/d/e
35 WVPASS bup random 512 >$D/f
36 WVPASS ln -s non-existent-file $D/g
37 WVPASSEQ "$(bup index -s $D/)" "A $D/"
38 WVPASSEQ "$(bup index -s $D/b)" ""
39 WVPASSEQ "$(bup index --check -us $D/b)" "A $D/b"
40 WVPASSEQ "$(bup index --check -us $D/b $D/d)" \
41 "A $D/d/e/
42 A $D/d/
43 A $D/b"
44 touch $D/d/z
45 bup tick
46 WVPASSEQ "$(bup index --check -usx $D)" \
47 "A $D/g
48 A $D/f
49 A $D/d/z
50 A $D/d/e/
51 A $D/d/
52 A $D/b
53 A $D/a
54 A $D/"
55 WVPASSEQ "$(bup index --check -us $D/a $D/b --fake-valid)" \
56 "  $D/b
57   $D/a"
58 WVPASSEQ "$(bup index --check -us $D/a)" "  $D/a"  # stays unmodified
59 WVPASSEQ "$(bup index --check -us $D/d --fake-valid)" \
60 "  $D/d/z
61   $D/d/e/
62   $D/d/"
63 touch $D/d/z
64 WVPASS bup index -u $D/d/z  # becomes modified
65 WVPASSEQ "$(bup index -s $D/a $D $D/b)" \
66 "A $D/g
67 A $D/f
68 M $D/d/z
69   $D/d/e/
70 M $D/d/
71   $D/b
72   $D/a
73 A $D/"
74
75 WVPASS bup index -u $D/d/e $D/a --fake-invalid
76 WVPASSEQ "$(cd $D && bup index -m .)" \
77 "./g
78 ./f
79 ./d/z
80 ./d/e/
81 ./d/
82 ./a
83 ./"
84 WVPASSEQ "$(cd $D && bup index -m)" \
85 "g
86 f
87 d/z
88 d/e/
89 d/
90 a
91 ./"
92 WVPASSEQ "$(cd $D && bup index -s .)" "$(cd $D && bup index -s .)"
93
94 WVFAIL bup save -t $D/doesnt-exist-filename
95
96 mv $BUP_DIR/bupindex $BUP_DIR/bi.old
97 WVFAIL bup save -t $D/d/e/fifotest
98 mkfifo $D/d/e/fifotest
99 WVPASS bup index -u $D/d/e/fifotest
100 WVPASS bup save -t $D/d/e/fifotest
101 WVPASS bup save -t $D/d/e
102 rm -f $D/d/e/fifotest
103 WVPASS bup index -u $D/d/e
104 WVFAIL bup save -t $D/d/e/fifotest
105 mv $BUP_DIR/bi.old $BUP_DIR/bupindex
106
107 WVPASS bup index -u $D/d/e
108 WVPASS bup save -t $D/d/e
109 WVPASSEQ "$(cd $D && bup index -m)" \
110 "g
111 f
112 d/z
113 d/
114 a
115 ./"
116 WVPASS bup save -t $D/d
117 WVPASS bup index --fake-invalid $D/d/z
118 WVPASS bup save -t $D/d/z
119 WVPASS bup save -t $D/d/z  # test regenerating trees when no files are changed
120 WVPASS bup save -t $D/d
121 WVPASSEQ "$(cd $D && bup index -m)" \
122 "g
123 f
124 a
125 ./"
126 WVPASS bup save -r :$BUP_DIR -n r-test $D
127 WVFAIL bup save -r :$BUP_DIR/fake/path -n r-test $D
128 WVFAIL bup save -r :$BUP_DIR -n r-test $D/fake/path
129
130 WVSTART "split"
131 echo a >a.tmp
132 echo b >b.tmp
133 WVPASS bup split -b a.tmp >taga.tmp
134 WVPASS bup split -b b.tmp >tagb.tmp
135 cat a.tmp b.tmp | WVPASS bup split -b >tagab.tmp
136 WVPASSEQ $(cat taga.tmp | wc -l) 1
137 WVPASSEQ $(cat tagb.tmp | wc -l) 1
138 WVPASSEQ $(cat tagab.tmp | wc -l) 1
139 WVPASSEQ $(cat tag[ab].tmp | wc -l) 2
140 WVPASSEQ "$(bup split -b a.tmp b.tmp)" "$(cat tagab.tmp)"
141 WVPASSEQ "$(bup split -b --keep-boundaries a.tmp b.tmp)" "$(cat tag[ab].tmp)"
142 WVPASSEQ "$(cat tag[ab].tmp | bup split -b --keep-boundaries --git-ids)" \
143          "$(cat tag[ab].tmp)"
144 WVPASSEQ "$(cat tag[ab].tmp | bup split -b --git-ids)" \
145          "$(cat tagab.tmp)"
146 WVPASS bup split --bench -b <t/testfile1 >tags1.tmp
147 WVPASS bup split -vvvv -b t/testfile2 >tags2.tmp
148 WVPASS bup margin
149 WVPASS bup midx -f
150 WVPASS bup midx --check -a
151 WVPASS bup midx -o $BUP_DIR/objects/pack/test1.midx \
152         $BUP_DIR/objects/pack/*.idx
153 WVPASS bup midx --check -a
154 WVPASS bup midx -o $BUP_DIR/objects/pack/test1.midx \
155         $BUP_DIR/objects/pack/*.idx \
156         $BUP_DIR/objects/pack/*.idx
157 WVPASS bup midx --check -a
158 all=$(echo $BUP_DIR/objects/pack/*.idx $BUP_DIR/objects/pack/*.midx)
159 WVPASS bup midx -o $BUP_DIR/objects/pack/zzz.midx $all
160 bup tick
161 WVPASS bup midx -o $BUP_DIR/objects/pack/yyy.midx $all
162 WVPASS bup midx -a
163 WVPASSEQ "$(echo $BUP_DIR/objects/pack/*.midx)" \
164         "$BUP_DIR/objects/pack/yyy.midx"
165 WVPASS bup margin
166 WVPASS bup split -t t/testfile2 >tags2t.tmp
167 WVPASS bup split -t t/testfile2 --fanout 3 >tags2tf.tmp
168 WVPASS bup split -r "$BUP_DIR" -c t/testfile2 >tags2c.tmp
169 WVPASS bup split -r :$BUP_DIR -c t/testfile2 >tags2c.tmp
170 WVPASS ls -lR \
171    | WVPASS bup split -r :$BUP_DIR -c --fanout 3 --max-pack-objects 3 -n lslr
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 wc -c t/testfile1 t/testfile2
183 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 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     set -e
213     cd "$BUP_DIR" || exit 1
214     #git repack -Ad
215     #git prune
216     (cd "$TOP/t/sampledata" && WVPASS bup save -vvn master /) || WVFAIL
217     n=$(git fsck --full --strict 2>&1 | 
218       egrep -v 'dangling (commit|tree|blob)' |
219       tee -a /dev/stderr | 
220       wc -l)
221     WVPASS [ "$n" -eq 0 ]
222 ) || exit 1
223
224 WVSTART "restore"
225 force-delete buprestore.tmp
226 WVFAIL bup restore boink
227 touch $TOP/$D/$D
228 bup index -u $TOP/$D
229 bup save -n master /
230 WVPASS bup restore -C buprestore.tmp "/master/latest/$TOP/$D"
231 WVPASSEQ "$(ls buprestore.tmp)" "bupdata.tmp"
232 force-delete buprestore.tmp
233 WVPASS bup restore -C buprestore.tmp "/master/latest/$TOP/$D/"
234 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     force-delete $tmp
240     mkdir $tmp
241     export BUP_DIR="$(pwd)/$tmp/bup"
242     WVPASS bup init
243     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     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     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     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     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     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 ) || WVFAIL
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 WVPASS bup tag -d v0.1
301
302 # This section destroys data in the bup repository, so it is done last.
303 WVSTART "fsck"
304 WVPASS bup fsck
305 WVPASS bup fsck --quick
306 if bup fsck --par2-ok; then
307     WVSTART "fsck (par2)"
308 else
309     WVSTART "fsck (PAR2 IS MISSING)"
310 fi
311 WVPASS bup fsck -g
312 WVPASS bup fsck -r
313 WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n10 -s1 -S0
314 WVFAIL bup fsck --quick
315 WVFAIL bup fsck --quick --disable-par2
316 chmod u+w $BUP_DIR/objects/pack/*.idx
317 WVPASS bup damage $BUP_DIR/objects/pack/*.idx -n10 -s1 -S0
318 WVFAIL bup fsck --quick -j4
319 WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n10 -s1024 --percent 0.4 -S0
320 WVFAIL bup fsck --quick
321 WVFAIL bup fsck --quick -rvv -j99   # fails because repairs were needed
322 if bup fsck --par2-ok; then
323     WVPASS bup fsck -r # ok because of repairs from last time
324     WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n202 -s1 --equal -S0
325     WVFAIL bup fsck
326     WVFAIL bup fsck -rvv   # too many errors to be repairable
327     WVFAIL bup fsck -r   # too many errors to be repairable
328 else
329     WVFAIL bup fsck --quick -r # still fails because par2 was missing
330 fi
331
332 WVSTART "exclude-bupdir"
333 D=exclude-bupdir.tmp
334 force-delete $D
335 mkdir $D
336 export BUP_DIR="$D/.bup"
337 WVPASS bup init
338 touch $D/a
339 WVPASS bup random 128k >$D/b
340 mkdir $D/d $D/d/e
341 WVPASS bup random 512 >$D/f
342 WVPASS bup index -ux $D
343 bup save -n exclude-bupdir $D
344 WVPASSEQ "$(bup ls -a exclude-bupdir/latest/$TOP/$D/)" "a
345 b
346 d/
347 f"
348
349 WVSTART "exclude"
350 (
351     set -e -o pipefail
352     D=exclude.tmp
353     force-delete $D
354     mkdir $D
355     export BUP_DIR="$D/.bup"
356     WVPASS bup init
357     touch $D/a
358     WVPASS bup random 128k >$D/b
359     mkdir $D/d $D/d/e
360     WVPASS bup random 512 >$D/f
361     WVPASS bup random 512 >$D/j
362     WVPASS bup index -ux --exclude $D/d --exclude $D/j $D
363     bup save -n exclude $D
364     WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
365 b
366 f"
367     mkdir $D/g $D/h
368     WVPASS bup index -ux --exclude $D/d --exclude $TOP/$D/g --exclude $D/h \
369         --exclude $TOP/$D/j $D
370     bup save -n exclude $D
371     WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
372 b
373 f"
374 ) || WVFAIL
375
376 WVSTART "exclude-from"
377 (
378     set -e -o pipefail
379     D=exclude-fromdir.tmp
380     EXCLUDE_FILE=exclude-from.tmp
381     echo "$D/d 
382  $TOP/$D/g
383 $D/h
384 $D/i" > $EXCLUDE_FILE
385     force-delete $D
386     mkdir $D
387     export BUP_DIR="$D/.bup"
388     WVPASS bup init
389     touch $D/a
390     WVPASS bup random 128k >$D/b
391     mkdir $D/d $D/d/e
392     WVPASS bup random 512 >$D/f
393     mkdir $D/g $D/h
394     WVPASS bup random 128k > $D/i
395     WVPASS bup index -ux --exclude-from $EXCLUDE_FILE $D
396     bup save -n exclude-from $D
397     WVPASSEQ "$(bup ls exclude-from/latest/$TOP/$D/)" "a
398 b
399 f"
400     rm $EXCLUDE_FILE
401 ) || WVFAIL
402
403 WVSTART "save (no index)"
404 (
405     set -e
406     tmp=save-no-index.tmp
407     force-delete $tmp
408     mkdir $tmp
409     export BUP_DIR="$(pwd)/$tmp/bup"
410     WVPASS bup init
411     WVFAIL bup save -n nothing /
412     rm -r "$tmp"
413 ) || WVFAIL
414
415 WVSTART "save --strip"
416 (
417     tmp=graft-points.tmp
418     force-delete $tmp
419     mkdir $tmp
420     export BUP_DIR="$(pwd)/$tmp/bup"
421     WVPASS bup init
422     mkdir -p $tmp/src/x/y/z
423     WVPASS bup random 8k > $tmp/src/x/y/random-1
424     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
425     WVPASS bup index -u $tmp/src
426     WVPASS bup save --strip -n foo $tmp/src/x/y
427     WVPASS bup restore -C $tmp/restore /foo/latest
428     WVPASS t/compare-trees $tmp/src/x/y/ "$tmp/restore/latest/"
429 ) || WVFAIL
430
431 WVSTART "save --strip-path (relative)"
432 (
433     tmp=graft-points.tmp
434     force-delete $tmp
435     mkdir $tmp
436     export BUP_DIR="$(pwd)/$tmp/bup"
437     WVPASS bup init
438     mkdir -p $tmp/src/x/y/z
439     WVPASS bup random 8k > $tmp/src/x/y/random-1
440     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
441     WVPASS bup index -u $tmp/src
442     WVPASS bup save --strip-path $tmp/src -n foo $tmp/src/x
443     WVPASS bup restore -C $tmp/restore /foo/latest
444     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/"
445 ) || WVFAIL
446
447 WVSTART "save --strip-path (absolute)"
448 (
449     tmp=graft-points.tmp
450     force-delete $tmp
451     mkdir $tmp
452     export BUP_DIR="$(pwd)/$tmp/bup"
453     WVPASS bup init
454     mkdir -p $tmp/src/x/y/z
455     WVPASS bup random 8k > $tmp/src/x/y/random-1
456     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
457     WVPASS bup index -u $tmp/src
458     WVPASS bup save --strip-path "$TOP" -n foo $tmp/src
459     WVPASS bup restore -C $tmp/restore /foo/latest
460     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/$tmp/src/"
461 ) || WVFAIL
462
463 WVSTART "save --strip-path (no match)"
464 (
465     tmp=graft-points.tmp
466     force-delete $tmp
467     mkdir $tmp
468     export BUP_DIR="$(pwd)/$tmp/bup"
469     WVPASS bup init
470     mkdir -p $tmp/src/x/y/z
471     WVPASS bup random 8k > $tmp/src/x/y/random-1
472     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
473     WVPASS bup index -u $tmp/src
474     WVPASS bup save --strip-path $tmp/foo -n foo $tmp/src/x
475     WVPASS bup restore -C $tmp/restore /foo/latest
476     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/$TOP/$tmp/src/"
477 ) || WVFAIL
478
479 WVSTART "save --graft (empty graft points disallowed)"
480 (
481     tmp=graft-points.tmp
482     force-delete $tmp
483     mkdir $tmp
484     export BUP_DIR="$(pwd)/$tmp/bup"
485     WVPASS bup init
486     WVFAIL bup save --graft =/grafted -n graft-point-absolute $tmp
487     WVFAIL bup save --graft $TOP/$tmp= -n graft-point-absolute $tmp
488 ) || WVFAIL
489
490 WVSTART "save --graft /x/y=/a/b (relative paths)"
491 (
492     tmp=graft-points.tmp
493     force-delete $tmp
494     mkdir $tmp
495     export BUP_DIR="$(pwd)/$tmp/bup"
496     WVPASS bup init
497     mkdir -p $tmp/src/x/y/z
498     WVPASS bup random 8k > $tmp/src/x/y/random-1
499     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
500     WVPASS bup index -u $tmp/src
501     WVPASS bup save --graft $tmp/src=x -n foo $tmp/src
502     WVPASS bup restore -C $tmp/restore /foo/latest
503     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/$TOP/x/"
504 ) || WVFAIL
505
506 WVSTART "save --graft /x/y=/a/b (matching structure)"
507 (
508     tmp=graft-points.tmp
509     force-delete $tmp
510     mkdir $tmp
511     export BUP_DIR="$(pwd)/$tmp/bup"
512     WVPASS bup init
513     mkdir -p $tmp/src/x/y/z
514     WVPASS bup random 8k > $tmp/src/x/y/random-1
515     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
516     WVPASS bup index -u $tmp/src
517     WVPASS bup save -v --graft "$TOP/$tmp/src/x/y=$TOP/$tmp/src/a/b" \
518         -n foo $tmp/src/x/y
519     WVPASS bup restore -C $tmp/restore /foo/latest
520     WVPASS t/compare-trees $tmp/src/x/y/ \
521         "$tmp/restore/latest/$TOP/$tmp/src/a/b/"
522 ) || WVFAIL
523
524 WVSTART "save --graft /x/y=/a (shorter target)"
525 (
526     tmp=graft-points.tmp
527     force-delete $tmp
528     mkdir $tmp
529     export BUP_DIR="$(pwd)/$tmp/bup"
530     WVPASS bup init
531     mkdir -p $tmp/src/x/y/z
532     WVPASS bup random 8k > $tmp/src/x/y/random-1
533     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
534     WVPASS bup index -u $tmp/src
535     WVPASS bup save -v --graft "$TOP/$tmp/src/x/y=/a" -n foo $tmp/src/x/y
536     WVPASS bup restore -C $tmp/restore /foo/latest
537     WVPASS t/compare-trees $tmp/src/x/y/ "$tmp/restore/latest/a/"
538 ) || WVFAIL
539
540 WVSTART "save --graft /x=/a/b (longer target)"
541 (
542     tmp=graft-points.tmp
543     export BUP_DIR="$(pwd)/$tmp/bup"
544     force-delete $tmp
545     mkdir $tmp
546     WVPASS bup init
547     mkdir -p $tmp/src/x/y/z
548     WVPASS bup random 8k > $tmp/src/x/y/random-1
549     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
550     WVPASS bup index -u $tmp/src
551     WVPASS bup save -v --graft "$TOP/$tmp/src=$TOP/$tmp/src/a/b/c" \
552         -n foo $tmp/src
553     WVPASS bup restore -C $tmp/restore /foo/latest
554     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/$TOP/$tmp/src/a/b/c/"
555 ) || WVFAIL
556
557 WVSTART "save --graft /x=/ (root target)"
558 (
559     tmp=graft-points.tmp
560     export BUP_DIR="$(pwd)/$tmp/bup"
561     force-delete $tmp
562     mkdir $tmp
563     WVPASS bup init
564     mkdir -p $tmp/src/x/y/z
565     WVPASS bup random 8k > $tmp/src/x/y/random-1
566     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
567     WVPASS bup index -u $tmp/src
568     WVPASS bup save -v --graft "$TOP/$tmp/src/x=/" -n foo $tmp/src/x
569     WVPASS bup restore -C $tmp/restore /foo/latest
570     WVPASS t/compare-trees $tmp/src/x/ "$tmp/restore/latest/"
571 ) || WVFAIL
572
573 #WVSTART "save --graft /=/x/ (root source)"
574 # FIXME: Not tested for now -- will require cleverness, or caution as root.
575
576 WVSTART "indexfile"
577 D=indexfile.tmp
578 INDEXFILE=tmpindexfile.tmp
579 rm -f $INDEXFILE
580 force-delete $D
581 mkdir $D
582 export BUP_DIR="$D/.bup"
583 WVPASS bup init
584 touch $D/a
585 touch $D/b
586 mkdir $D/c
587 WVPASS bup index -ux $D
588 bup save --strip -n bupdir $D
589 WVPASSEQ "$(bup ls bupdir/latest/)" "a
590 b
591 c/"
592 WVPASS bup index -f $INDEXFILE --exclude=$D/c -ux $D
593 bup save --strip -n indexfile -f $INDEXFILE $D
594 WVPASSEQ "$(bup ls indexfile/latest/)" "a
595 b"
596
597
598 WVSTART "import-rsnapshot"
599 D=rsnapshot.tmp
600 export BUP_DIR="$TOP/$D/.bup"
601 force-delete $D
602 mkdir $D
603 WVPASS bup init
604 mkdir -p $D/hourly.0/buptest/a
605 touch $D/hourly.0/buptest/a/b
606 mkdir -p $D/hourly.0/buptest/c/d
607 touch $D/hourly.0/buptest/c/d/e
608 WVPASS true
609 WVPASS bup import-rsnapshot $D/
610 WVPASSEQ "$(bup ls buptest/latest/)" "a/
611 c/"
612
613
614 if [ "$(which rdiff-backup)" != "" ]; then
615     WVSTART "import-rdiff-backup"
616     D=rdiff-backup.tmp
617     export BUP_DIR="$TOP/$D/.bup"
618     force-delete $D
619     mkdir $D
620     WVPASS bup init
621     mkdir $D/rdiff-backup
622     rdiff-backup $TOP/cmd $D/rdiff-backup
623     bup tick
624     rdiff-backup $TOP/Documentation $D/rdiff-backup
625     WVPASS bup import-rdiff-backup $D/rdiff-backup import-rdiff-backup
626     WVPASSEQ "$(bup ls import-rdiff-backup/ | wc -l)" "3"
627     WVPASSEQ "$(bup ls import-rdiff-backup/latest/ | sort)" "$(ls $TOP/Documentation | sort)"
628 fi
629
630
631 WVSTART "compression"
632 D=compression0.tmp
633 export BUP_DIR="$TOP/$D/.bup"
634 force-delete $D
635 mkdir $D
636 WVPASS bup init
637 WVPASS bup index $TOP/Documentation
638 WVPASS bup save -n compression -0 --strip $TOP/Documentation
639 # 'ls' on NetBSD sets -A by default when running as root, so we have to undo
640 # it by grepping out any dotfiles.  (Normal OSes don't auto-set -A, but this
641 # is harmless there.)
642 WVPASSEQ "$(bup ls compression/latest/ | sort)" \
643          "$(ls $TOP/Documentation | grep -v '^\.' | sort)"
644 COMPRESSION_0_SIZE=$(du -k -s $D | cut -f1)
645
646 D=compression9.tmp
647 export BUP_DIR="$TOP/$D/.bup"
648 force-delete $D
649 mkdir $D
650 WVPASS bup init
651 WVPASS bup index $TOP/Documentation
652 WVPASS bup save -n compression -9 --strip $TOP/Documentation
653 WVPASSEQ "$(bup ls compression/latest/ | sort)" \
654          "$(ls $TOP/Documentation | grep -v '^\.' | sort)"
655 COMPRESSION_9_SIZE=$(du -k -s $D | cut -f1)
656
657 WVPASS [ "$COMPRESSION_9_SIZE" -lt "$COMPRESSION_0_SIZE" ]
658
659
660 WVSTART "save disjoint top-level directories"
661 (
662     set -e
663     # Resolve any symlinks involving the top top-level dirs.
664     real_pwd="$(realpath .)"
665     real_tmp="$(realpath /tmp/.)"
666     pwd_top="$(echo $real_pwd | awk -F "/" '{print $2}')"
667     tmp_top="$(echo $real_tmp | awk -F "/" '{print $2}')"
668     if [ "$pwd_top" = "$tmp_top" ]; then
669         echo "(running from within /$tmp_top; skipping test)"
670         exit 0
671     fi
672     D=bupdata.tmp
673     force-delete $D
674     mkdir -p $D/x
675     date > $D/x/1
676     tmpdir="$(mktemp -d $real_tmp/bup-test-XXXXXXX)"
677     cleanup() { set -x; rm -r "${tmpdir}"; set +x; }
678     trap cleanup EXIT
679     date > "$tmpdir/2"
680
681     export BUP_DIR="$TOP/buptest.tmp"
682     test -d "$BUP_DIR" && rm -r "$BUP_DIR"
683
684     WVPASS bup init
685     WVPASS bup index -vu $(pwd)/$D/x "$tmpdir"
686     WVPASS bup save -t -n src $(pwd)/$D/x "$tmpdir"
687
688     # For now, assume that "ls -a" and "sort" use the same order.
689     WVPASSEQ "$(bup ls -a src/latest)" \
690         "$(echo -e "$pwd_top/\n$tmp_top/" | sort)"
691 ) || WVFAIL
692
693 WVSTART "clear-index"
694 D=clear-index.tmp
695 export BUP_DIR="$TOP/$D/.bup"
696 force-delete $TOP/$D
697 mkdir $TOP/$D
698 WVPASS bup init
699 touch $TOP/$D/foo
700 touch $TOP/$D/bar
701 bup index -u $D
702 WVPASSEQ "$(bup index -p)" "$D/foo
703 $D/bar
704 $D/
705 ./"
706 rm $TOP/$D/foo
707 WVPASS bup index --clear
708 bup index -u $TOP/$D
709 WVPASSEQ "$(bup index -p)" "$D/bar
710 $D/
711 ./"
712
713 # bup index --exclude-rx ...
714 (
715     set -e
716     export BUP_DIR="$TOP/buptest.tmp"
717     D=bupdata.tmp
718
719     WVSTART "index --exclude-rx '^/foo' (root anchor)"
720     rm -rf "$D" "$BUP_DIR" buprestore.tmp
721     WVPASS bup init
722     mkdir $D
723     touch $D/a
724     touch $D/b
725     mkdir $D/sub1
726     mkdir $D/sub2
727     touch $D/sub1/a
728     touch $D/sub2/b
729     WVPASS bup index -u $D --exclude-rx "^$(pwd)/$D/sub1/"
730     bup save --strip -n bupdir $D
731     bup restore -C buprestore.tmp /bupdir/latest/
732     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
733 ./a
734 ./b
735 ./sub2
736 ./sub2/b"
737
738     WVSTART "index --exclude-rx '/foo$' (non-dir, tail anchor)"
739     rm -rf "$D" "$BUP_DIR" buprestore.tmp
740     WVPASS bup init
741     mkdir $D
742     touch $D/a
743     touch $D/b
744     touch $D/foo
745     mkdir $D/sub
746     mkdir $D/sub/foo
747     touch $D/sub/foo/a
748     WVPASS bup index -u $D --exclude-rx '/foo$'
749     bup save --strip -n bupdir $D
750     bup restore -C buprestore.tmp /bupdir/latest/
751     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
752 ./a
753 ./b
754 ./sub
755 ./sub/foo
756 ./sub/foo/a"
757
758     WVSTART "index --exclude-rx '/foo/$' (dir, tail anchor)"
759     rm -rf "$D" "$BUP_DIR" buprestore.tmp
760     WVPASS bup init
761     mkdir $D
762     touch $D/a
763     touch $D/b
764     touch $D/foo
765     mkdir $D/sub
766     mkdir $D/sub/foo
767     touch $D/sub/foo/a
768     WVPASS bup index -u $D --exclude-rx '/foo/$'
769     bup save --strip -n bupdir $D
770     bup restore -C buprestore.tmp /bupdir/latest/
771     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
772 ./a
773 ./b
774 ./foo
775 ./sub"
776
777     WVSTART "index --exclude-rx '/foo/.' (dir content)"
778     rm -rf "$D" "$BUP_DIR" buprestore.tmp
779     WVPASS bup init
780     mkdir $D
781     touch $D/a
782     touch $D/b
783     touch $D/foo
784     mkdir $D/sub
785     mkdir $D/sub/foo
786     touch $D/sub/foo/a
787     WVPASS bup index -u $D --exclude-rx '/foo/.'
788     bup save --strip -n bupdir $D
789     bup restore -C buprestore.tmp /bupdir/latest/
790     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
791 ./a
792 ./b
793 ./foo
794 ./sub
795 ./sub/foo"
796 ) || WVFAIL
797
798
799 # bup restore --exclude-rx ...
800 (
801     set -e
802     export BUP_DIR="$TOP/buptest.tmp"
803     D=bupdata.tmp
804
805     WVSTART "restore --exclude-rx '^/foo' (root anchor)"
806     rm -rf "$D" "$BUP_DIR" buprestore.tmp
807     WVPASS bup init
808     mkdir $D
809     touch $D/a
810     touch $D/b
811     mkdir $D/sub1
812     mkdir $D/sub2
813     touch $D/sub1/a
814     touch $D/sub2/b
815     WVPASS bup index -u $D
816     bup save --strip -n bupdir $D
817     bup restore -C buprestore.tmp --exclude-rx "^/sub1/" /bupdir/latest/
818     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
819 ./a
820 ./b
821 ./sub2
822 ./sub2/b"
823
824     WVSTART "restore --exclude-rx '/foo$' (non-dir, tail anchor)"
825     rm -rf "$D" "$BUP_DIR" buprestore.tmp
826     WVPASS bup init
827     mkdir $D
828     touch $D/a
829     touch $D/b
830     touch $D/foo
831     mkdir $D/sub
832     mkdir $D/sub/foo
833     touch $D/sub/foo/a
834     WVPASS bup index -u $D
835     bup save --strip -n bupdir $D
836     bup restore -C buprestore.tmp --exclude-rx '/foo$' /bupdir/latest/
837     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
838 ./a
839 ./b
840 ./sub
841 ./sub/foo
842 ./sub/foo/a"
843
844     WVSTART "restore --exclude-rx '/foo/$' (dir, tail anchor)"
845     rm -rf "$D" "$BUP_DIR" buprestore.tmp
846     WVPASS bup init
847     mkdir $D
848     touch $D/a
849     touch $D/b
850     touch $D/foo
851     mkdir $D/sub
852     mkdir $D/sub/foo
853     touch $D/sub/foo/a
854     WVPASS bup index -u $D
855     bup save --strip -n bupdir $D
856     bup restore -C buprestore.tmp --exclude-rx '/foo/$' /bupdir/latest/
857     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
858 ./a
859 ./b
860 ./foo
861 ./sub"
862
863     WVSTART "restore --exclude-rx '/foo/.' (dir content)"
864     rm -rf "$D" "$BUP_DIR" buprestore.tmp
865     WVPASS bup init
866     mkdir $D
867     touch $D/a
868     touch $D/b
869     touch $D/foo
870     mkdir $D/sub
871     mkdir $D/sub/foo
872     touch $D/sub/foo/a
873     WVPASS bup index -u $D
874     bup save --strip -n bupdir $D
875     bup restore -C buprestore.tmp --exclude-rx '/foo/.' /bupdir/latest/
876     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
877 ./a
878 ./b
879 ./foo
880 ./sub
881 ./sub/foo"
882 ) || WVFAIL