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