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