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