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