]> arthur.barton.de Git - bup.git/blob - t/test.sh
t/test.sh: skip two "tree SHA1 didn't change" tests on Cygwin for now.
[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 if ! [[ $(uname) =~ CYGWIN ]]; then
130     # On Cygwin, the access time may change.
131     WVPASSEQ "$tree1" "$tree2"
132 fi
133 WVPASSEQ "$(bup index -s / | grep ^D)" ""
134 tree3=$(bup save -t /) || WVFAIL
135 if ! [[ $(uname) =~ CYGWIN ]]; then
136     # On Cygwin, the access time may change.
137     WVPASSEQ "$tree1" "$tree3"
138 fi
139 WVPASS bup save -r :$BUP_DIR -n r-test $D
140 WVFAIL bup save -r :$BUP_DIR/fake/path -n r-test $D
141 WVFAIL bup save -r :$BUP_DIR -n r-test $D/fake/path
142
143 WVSTART "split"
144 echo a >a.tmp
145 echo b >b.tmp
146 WVPASS bup split -b a.tmp >taga.tmp
147 WVPASS bup split -b b.tmp >tagb.tmp
148 cat a.tmp b.tmp | WVPASS bup split -b >tagab.tmp
149 WVPASSEQ $(cat taga.tmp | wc -l) 1
150 WVPASSEQ $(cat tagb.tmp | wc -l) 1
151 WVPASSEQ $(cat tagab.tmp | wc -l) 1
152 WVPASSEQ $(cat tag[ab].tmp | wc -l) 2
153 WVPASSEQ "$(bup split -b a.tmp b.tmp)" "$(cat tagab.tmp)"
154 WVPASSEQ "$(bup split -b --keep-boundaries a.tmp b.tmp)" "$(cat tag[ab].tmp)"
155 WVPASSEQ "$(cat tag[ab].tmp | bup split -b --keep-boundaries --git-ids)" \
156          "$(cat tag[ab].tmp)"
157 WVPASSEQ "$(cat tag[ab].tmp | bup split -b --git-ids)" \
158          "$(cat tagab.tmp)"
159 WVPASS bup split --bench -b <t/testfile1 >tags1.tmp
160 WVPASS bup split -vvvv -b t/testfile2 >tags2.tmp
161 WVPASS bup margin
162 WVPASS bup midx -f
163 WVPASS bup midx --check -a
164 WVPASS bup midx -o $BUP_DIR/objects/pack/test1.midx \
165         $BUP_DIR/objects/pack/*.idx
166 WVPASS bup midx --check -a
167 WVPASS bup midx -o $BUP_DIR/objects/pack/test1.midx \
168         $BUP_DIR/objects/pack/*.idx \
169         $BUP_DIR/objects/pack/*.idx
170 WVPASS bup midx --check -a
171 all=$(echo $BUP_DIR/objects/pack/*.idx $BUP_DIR/objects/pack/*.midx)
172 WVPASS bup midx -o $BUP_DIR/objects/pack/zzz.midx $all
173 bup tick
174 WVPASS bup midx -o $BUP_DIR/objects/pack/yyy.midx $all
175 WVPASS bup midx -a
176 WVPASSEQ "$(echo $BUP_DIR/objects/pack/*.midx)" \
177         "$BUP_DIR/objects/pack/yyy.midx"
178 WVPASS bup margin
179 WVPASS bup split -t t/testfile2 >tags2t.tmp
180 WVPASS bup split -t t/testfile2 --fanout 3 >tags2tf.tmp
181 WVPASS bup split -r "$BUP_DIR" -c t/testfile2 >tags2c.tmp
182 WVPASS bup split -r :$BUP_DIR -c t/testfile2 >tags2c.tmp
183 WVPASS ls -lR \
184    | WVPASS bup split -r :$BUP_DIR -c --fanout 3 --max-pack-objects 3 -n lslr
185 WVPASS bup ls
186 WVFAIL bup ls /does-not-exist
187 WVPASS bup ls /lslr
188 WVPASS bup ls /lslr/latest
189 WVPASS bup ls /lslr/latest/
190 #WVPASS bup ls /lslr/1971-01-01   # all dates always exist
191 WVFAIL diff -u tags1.tmp tags2.tmp
192
193 # fanout must be different from non-fanout
194 WVFAIL diff tags2t.tmp tags2tf.tmp
195 wc -c t/testfile1 t/testfile2
196 wc -l tags1.tmp tags2.tmp
197
198 WVSTART "bloom"
199 WVPASS bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
200 rm $BUP_DIR/objects/pack/bup.bloom
201 WVPASS bup bloom -k 4
202 WVPASS bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
203 WVPASS bup bloom -d buptest.tmp/objects/pack --ruin --force
204 WVFAIL bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
205 WVPASS bup bloom --force -k 5
206 WVPASS bup bloom -c $(ls -1 $BUP_DIR/objects/pack/*.idx|head -n1)
207
208 WVSTART "memtest"
209 WVPASS bup memtest -c1 -n100
210 WVPASS bup memtest -c1 -n100 --existing
211
212 WVSTART "join"
213 WVPASS bup join $(cat tags1.tmp) >out1.tmp
214 WVPASS bup join <tags2.tmp >out2.tmp
215 WVPASS bup join <tags2t.tmp -o out2t.tmp
216 WVPASS bup join -r "$BUP_DIR" <tags2c.tmp >out2c.tmp
217 WVPASS bup join -r ":$BUP_DIR" <tags2c.tmp >out2c.tmp
218 WVPASS diff -u t/testfile1 out1.tmp
219 WVPASS diff -u t/testfile2 out2.tmp
220 WVPASS diff -u t/testfile2 out2t.tmp
221 WVPASS diff -u t/testfile2 out2c.tmp
222
223 WVSTART "save/git-fsck"
224 (
225     set -e
226     cd "$BUP_DIR" || exit 1
227     #git repack -Ad
228     #git prune
229     (cd "$TOP/t/sampledata" && WVPASS bup save -vvn master /) || WVFAIL
230     n=$(git fsck --full --strict 2>&1 | 
231       egrep -v 'dangling (commit|tree|blob)' |
232       tee -a /dev/stderr | 
233       wc -l)
234     WVPASS [ "$n" -eq 0 ]
235 ) || exit 1
236
237 WVSTART "restore"
238 force-delete buprestore.tmp
239 WVFAIL bup restore boink
240 touch $TOP/$D/$D
241 bup index -u $TOP/$D
242 bup save -n master /
243 WVPASS bup restore -C buprestore.tmp "/master/latest/$TOP/$D"
244 WVPASSEQ "$(ls buprestore.tmp)" "bupdata.tmp"
245 force-delete buprestore.tmp
246 WVPASS bup restore -C buprestore.tmp "/master/latest/$TOP/$D/"
247 touch $D/non-existent-file buprestore.tmp/non-existent-file # else diff fails
248 WVPASS diff -ur $D/ buprestore.tmp/
249
250 (
251     tmp=testrestore.tmp
252     force-delete $tmp
253     mkdir $tmp
254     export BUP_DIR="$(pwd)/$tmp/bup"
255     WVPASS bup init
256     mkdir -p $tmp/src/x/y/z
257     WVPASS bup random 8k > $tmp/src/x/y/random-1
258     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
259     WVPASS bup index -u $tmp/src
260     WVPASS bup save --strip -n foo $tmp/src
261
262     WVSTART "restore /foo/latest"
263     WVPASS bup restore -C $tmp/restore /foo/latest
264     WVPASS t/compare-trees $tmp/src/ $tmp/restore/latest/
265
266     WVSTART "restore /foo/latest/"
267     force-delete "$tmp/restore"
268     WVPASS bup restore -C $tmp/restore /foo/latest/
269     for x in $tmp/src/*; do
270         WVPASS t/compare-trees $x/ $tmp/restore/$(basename $x);
271     done
272
273     WVSTART "restore /foo/latest/."
274     force-delete "$tmp/restore"
275     WVPASS bup restore -C $tmp/restore /foo/latest/.
276     WVPASS t/compare-trees $tmp/src/ $tmp/restore/
277
278     WVSTART "restore /foo/latest/x"
279     force-delete "$tmp/restore"
280     WVPASS bup restore -C $tmp/restore /foo/latest/x
281     WVPASS t/compare-trees $tmp/src/x/ $tmp/restore/x/
282
283     WVSTART "restore /foo/latest/x/"
284     force-delete "$tmp/restore"
285     WVPASS bup restore -C $tmp/restore /foo/latest/x/
286     for x in $tmp/src/x/*; do
287         WVPASS t/compare-trees $x/ $tmp/restore/$(basename $x);
288     done
289
290     WVSTART "restore /foo/latest/x/."
291     force-delete "$tmp/restore"
292     WVPASS bup restore -C $tmp/restore /foo/latest/x/.
293     WVPASS t/compare-trees $tmp/src/x/ $tmp/restore/
294 ) || WVFAIL
295
296
297 WVSTART "ftp"
298 WVPASS bup ftp "cat /master/latest/$TOP/$D/b" >$D/b.new
299 WVPASS bup ftp "cat /master/latest/$TOP/$D/f" >$D/f.new
300 WVPASS bup ftp "cat /master/latest/$TOP/$D/f"{,} >$D/f2.new
301 WVPASS bup ftp "cat /master/latest/$TOP/$D/a" >$D/a.new
302 WVPASSEQ "$(sha1sum <$D/b)" "$(sha1sum <$D/b.new)"
303 WVPASSEQ "$(sha1sum <$D/f)" "$(sha1sum <$D/f.new)"
304 WVPASSEQ "$(cat $D/f.new{,} | sha1sum)" "$(sha1sum <$D/f2.new)"
305 WVPASSEQ "$(sha1sum <$D/a)" "$(sha1sum <$D/a.new)"
306
307 WVSTART "tag"
308 WVFAIL bup tag -d v0.n 2>/dev/null
309 WVFAIL bup tag v0.n non-existant 2>/dev/null
310 WVPASSEQ "$(bup tag)" ""
311 WVPASS bup tag v0.1 master
312 WVPASSEQ "$(bup tag)" "v0.1"
313 WVPASS bup tag -d v0.1
314
315 # This section destroys data in the bup repository, so it is done last.
316 WVSTART "fsck"
317 WVPASS bup fsck
318 WVPASS bup fsck --quick
319 if bup fsck --par2-ok; then
320     WVSTART "fsck (par2)"
321 else
322     WVSTART "fsck (PAR2 IS MISSING)"
323 fi
324 WVPASS bup fsck -g
325 WVPASS bup fsck -r
326 WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n10 -s1 -S0
327 WVFAIL bup fsck --quick
328 WVFAIL bup fsck --quick --disable-par2
329 chmod u+w $BUP_DIR/objects/pack/*.idx
330 WVPASS bup damage $BUP_DIR/objects/pack/*.idx -n10 -s1 -S0
331 WVFAIL bup fsck --quick -j4
332 WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n10 -s1024 --percent 0.4 -S0
333 WVFAIL bup fsck --quick
334 WVFAIL bup fsck --quick -rvv -j99   # fails because repairs were needed
335 if bup fsck --par2-ok; then
336     WVPASS bup fsck -r # ok because of repairs from last time
337     WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n202 -s1 --equal -S0
338     WVFAIL bup fsck
339     WVFAIL bup fsck -rvv   # too many errors to be repairable
340     WVFAIL bup fsck -r   # too many errors to be repairable
341 else
342     WVFAIL bup fsck --quick -r # still fails because par2 was missing
343 fi
344
345 WVSTART "exclude-bupdir"
346 D=exclude-bupdir.tmp
347 force-delete $D
348 mkdir $D
349 export BUP_DIR="$D/.bup"
350 WVPASS bup init
351 touch $D/a
352 WVPASS bup random 128k >$D/b
353 mkdir $D/d $D/d/e
354 WVPASS bup random 512 >$D/f
355 WVPASS bup index -ux $D
356 bup save -n exclude-bupdir $D
357 WVPASSEQ "$(bup ls -a exclude-bupdir/latest/$TOP/$D/)" "a
358 b
359 d/
360 f"
361
362 WVSTART "exclude"
363 (
364     set -e -o pipefail
365     D=exclude.tmp
366     force-delete $D
367     mkdir $D
368     export BUP_DIR="$D/.bup"
369     WVPASS bup init
370     touch $D/a
371     WVPASS bup random 128k >$D/b
372     mkdir $D/d $D/d/e
373     WVPASS bup random 512 >$D/f
374     WVPASS bup random 512 >$D/j
375     WVPASS bup index -ux --exclude $D/d --exclude $D/j $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 \
382         --exclude $TOP/$D/j $D
383     bup save -n exclude $D
384     WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
385 b
386 f"
387 ) || WVFAIL
388
389 WVSTART "exclude-from"
390 (
391     set -e -o pipefail
392     D=exclude-fromdir.tmp
393     EXCLUDE_FILE=exclude-from.tmp
394     echo "$D/d 
395  $TOP/$D/g
396 $D/h
397 $D/i" > $EXCLUDE_FILE
398     force-delete $D
399     mkdir $D
400     export BUP_DIR="$D/.bup"
401     WVPASS bup init
402     touch $D/a
403     WVPASS bup random 128k >$D/b
404     mkdir $D/d $D/d/e
405     WVPASS bup random 512 >$D/f
406     mkdir $D/g $D/h
407     WVPASS bup random 128k > $D/i
408     WVPASS bup index -ux --exclude-from $EXCLUDE_FILE $D
409     bup save -n exclude-from $D
410     WVPASSEQ "$(bup ls exclude-from/latest/$TOP/$D/)" "a
411 b
412 f"
413     rm $EXCLUDE_FILE
414 ) || WVFAIL
415
416 WVSTART "save (no index)"
417 (
418     set -e
419     tmp=save-no-index.tmp
420     force-delete $tmp
421     mkdir $tmp
422     export BUP_DIR="$(pwd)/$tmp/bup"
423     WVPASS bup init
424     WVFAIL bup save -n nothing /
425     rm -r "$tmp"
426 ) || WVFAIL
427
428 WVSTART "save --strip"
429 (
430     tmp=graft-points.tmp
431     force-delete $tmp
432     mkdir $tmp
433     export BUP_DIR="$(pwd)/$tmp/bup"
434     WVPASS bup init
435     mkdir -p $tmp/src/x/y/z
436     WVPASS bup random 8k > $tmp/src/x/y/random-1
437     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
438     WVPASS bup index -u $tmp/src
439     WVPASS bup save --strip -n foo $tmp/src/x/y
440     WVPASS bup restore -C $tmp/restore /foo/latest
441     WVPASS t/compare-trees $tmp/src/x/y/ "$tmp/restore/latest/"
442 ) || WVFAIL
443
444 WVSTART "save --strip-path (relative)"
445 (
446     tmp=graft-points.tmp
447     force-delete $tmp
448     mkdir $tmp
449     export BUP_DIR="$(pwd)/$tmp/bup"
450     WVPASS bup init
451     mkdir -p $tmp/src/x/y/z
452     WVPASS bup random 8k > $tmp/src/x/y/random-1
453     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
454     WVPASS bup index -u $tmp/src
455     WVPASS bup save --strip-path $tmp/src -n foo $tmp/src/x
456     WVPASS bup restore -C $tmp/restore /foo/latest
457     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/"
458 ) || WVFAIL
459
460 WVSTART "save --strip-path (absolute)"
461 (
462     tmp=graft-points.tmp
463     force-delete $tmp
464     mkdir $tmp
465     export BUP_DIR="$(pwd)/$tmp/bup"
466     WVPASS bup init
467     mkdir -p $tmp/src/x/y/z
468     WVPASS bup random 8k > $tmp/src/x/y/random-1
469     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
470     WVPASS bup index -u $tmp/src
471     WVPASS bup save --strip-path "$TOP" -n foo $tmp/src
472     WVPASS bup restore -C $tmp/restore /foo/latest
473     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/$tmp/src/"
474 ) || WVFAIL
475
476 WVSTART "save --strip-path (no match)"
477 (
478     tmp=graft-points.tmp
479     force-delete $tmp
480     mkdir $tmp
481     export BUP_DIR="$(pwd)/$tmp/bup"
482     WVPASS bup init
483     mkdir -p $tmp/src/x/y/z
484     WVPASS bup random 8k > $tmp/src/x/y/random-1
485     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
486     WVPASS bup index -u $tmp/src
487     WVPASS bup save --strip-path $tmp/foo -n foo $tmp/src/x
488     WVPASS bup restore -C $tmp/restore /foo/latest
489     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/$TOP/$tmp/src/"
490 ) || WVFAIL
491
492 WVSTART "save --graft (empty graft points disallowed)"
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     WVFAIL bup save --graft =/grafted -n graft-point-absolute $tmp
500     WVFAIL bup save --graft $TOP/$tmp= -n graft-point-absolute $tmp
501 ) || WVFAIL
502
503 WVSTART "save --graft /x/y=/a/b (relative paths)"
504 (
505     tmp=graft-points.tmp
506     force-delete $tmp
507     mkdir $tmp
508     export BUP_DIR="$(pwd)/$tmp/bup"
509     WVPASS bup init
510     mkdir -p $tmp/src/x/y/z
511     WVPASS bup random 8k > $tmp/src/x/y/random-1
512     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
513     WVPASS bup index -u $tmp/src
514     WVPASS bup save --graft $tmp/src=x -n foo $tmp/src
515     WVPASS bup restore -C $tmp/restore /foo/latest
516     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/$TOP/x/"
517 ) || WVFAIL
518
519 WVSTART "save --graft /x/y=/a/b (matching structure)"
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=$TOP/$tmp/src/a/b" \
531         -n foo $tmp/src/x/y
532     WVPASS bup restore -C $tmp/restore /foo/latest
533     WVPASS t/compare-trees $tmp/src/x/y/ \
534         "$tmp/restore/latest/$TOP/$tmp/src/a/b/"
535 ) || WVFAIL
536
537 WVSTART "save --graft /x/y=/a (shorter target)"
538 (
539     tmp=graft-points.tmp
540     force-delete $tmp
541     mkdir $tmp
542     export BUP_DIR="$(pwd)/$tmp/bup"
543     WVPASS bup init
544     mkdir -p $tmp/src/x/y/z
545     WVPASS bup random 8k > $tmp/src/x/y/random-1
546     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
547     WVPASS bup index -u $tmp/src
548     WVPASS bup save -v --graft "$TOP/$tmp/src/x/y=/a" -n foo $tmp/src/x/y
549     WVPASS bup restore -C $tmp/restore /foo/latest
550     WVPASS t/compare-trees $tmp/src/x/y/ "$tmp/restore/latest/a/"
551 ) || WVFAIL
552
553 WVSTART "save --graft /x=/a/b (longer target)"
554 (
555     tmp=graft-points.tmp
556     export BUP_DIR="$(pwd)/$tmp/bup"
557     force-delete $tmp
558     mkdir $tmp
559     WVPASS bup init
560     mkdir -p $tmp/src/x/y/z
561     WVPASS bup random 8k > $tmp/src/x/y/random-1
562     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
563     WVPASS bup index -u $tmp/src
564     WVPASS bup save -v --graft "$TOP/$tmp/src=$TOP/$tmp/src/a/b/c" \
565         -n foo $tmp/src
566     WVPASS bup restore -C $tmp/restore /foo/latest
567     WVPASS t/compare-trees $tmp/src/ "$tmp/restore/latest/$TOP/$tmp/src/a/b/c/"
568 ) || WVFAIL
569
570 WVSTART "save --graft /x=/ (root target)"
571 (
572     tmp=graft-points.tmp
573     export BUP_DIR="$(pwd)/$tmp/bup"
574     force-delete $tmp
575     mkdir $tmp
576     WVPASS bup init
577     mkdir -p $tmp/src/x/y/z
578     WVPASS bup random 8k > $tmp/src/x/y/random-1
579     WVPASS bup random 8k > $tmp/src/x/y/z/random-2
580     WVPASS bup index -u $tmp/src
581     WVPASS bup save -v --graft "$TOP/$tmp/src/x=/" -n foo $tmp/src/x
582     WVPASS bup restore -C $tmp/restore /foo/latest
583     WVPASS t/compare-trees $tmp/src/x/ "$tmp/restore/latest/"
584 ) || WVFAIL
585
586 #WVSTART "save --graft /=/x/ (root source)"
587 # FIXME: Not tested for now -- will require cleverness, or caution as root.
588
589 WVSTART "indexfile"
590 D=indexfile.tmp
591 INDEXFILE=tmpindexfile.tmp
592 rm -f $INDEXFILE
593 force-delete $D
594 mkdir $D
595 export BUP_DIR="$D/.bup"
596 WVPASS bup init
597 touch $D/a
598 touch $D/b
599 mkdir $D/c
600 WVPASS bup index -ux $D
601 bup save --strip -n bupdir $D
602 WVPASSEQ "$(bup ls bupdir/latest/)" "a
603 b
604 c/"
605 WVPASS bup index -f $INDEXFILE --exclude=$D/c -ux $D
606 bup save --strip -n indexfile -f $INDEXFILE $D
607 WVPASSEQ "$(bup ls indexfile/latest/)" "a
608 b"
609
610
611 WVSTART "import-rsnapshot"
612 D=rsnapshot.tmp
613 export BUP_DIR="$TOP/$D/.bup"
614 force-delete $D
615 mkdir $D
616 WVPASS bup init
617 mkdir -p $D/hourly.0/buptest/a
618 touch $D/hourly.0/buptest/a/b
619 mkdir -p $D/hourly.0/buptest/c/d
620 touch $D/hourly.0/buptest/c/d/e
621 WVPASS true
622 WVPASS bup import-rsnapshot $D/
623 WVPASSEQ "$(bup ls buptest/latest/)" "a/
624 c/"
625
626
627 if [ "$(which rdiff-backup)" != "" ]; then
628     WVSTART "import-rdiff-backup"
629     D=rdiff-backup.tmp
630     export BUP_DIR="$TOP/$D/.bup"
631     force-delete $D
632     mkdir $D
633     WVPASS bup init
634     mkdir $D/rdiff-backup
635     rdiff-backup $TOP/cmd $D/rdiff-backup
636     bup tick
637     rdiff-backup $TOP/Documentation $D/rdiff-backup
638     WVPASS bup import-rdiff-backup $D/rdiff-backup import-rdiff-backup
639     WVPASSEQ "$(bup ls import-rdiff-backup/ | wc -l)" "3"
640     WVPASSEQ "$(bup ls import-rdiff-backup/latest/ | sort)" "$(ls $TOP/Documentation | sort)"
641 fi
642
643
644 WVSTART "compression"
645 D=compression0.tmp
646 export BUP_DIR="$TOP/$D/.bup"
647 force-delete $D
648 mkdir $D
649 WVPASS bup init
650 WVPASS bup index $TOP/Documentation
651 WVPASS bup save -n compression -0 --strip $TOP/Documentation
652 # 'ls' on NetBSD sets -A by default when running as root, so we have to undo
653 # it by grepping out any dotfiles.  (Normal OSes don't auto-set -A, but this
654 # is harmless there.)
655 WVPASSEQ "$(bup ls compression/latest/ | sort)" \
656          "$(ls $TOP/Documentation | grep -v '^\.' | sort)"
657 COMPRESSION_0_SIZE=$(du -k -s $D | cut -f1)
658
659 D=compression9.tmp
660 export BUP_DIR="$TOP/$D/.bup"
661 force-delete $D
662 mkdir $D
663 WVPASS bup init
664 WVPASS bup index $TOP/Documentation
665 WVPASS bup save -n compression -9 --strip $TOP/Documentation
666 WVPASSEQ "$(bup ls compression/latest/ | sort)" \
667          "$(ls $TOP/Documentation | grep -v '^\.' | sort)"
668 COMPRESSION_9_SIZE=$(du -k -s $D | cut -f1)
669
670 WVPASS [ "$COMPRESSION_9_SIZE" -lt "$COMPRESSION_0_SIZE" ]
671
672
673 WVSTART "save disjoint top-level directories"
674 (
675     set -e
676     top_dir="$(echo $(pwd) | awk -F "/" '{print $2}')"
677     if [ "$top_dir" == tmp ]; then
678         echo "(running from within /tmp; skipping test)"
679         exit 0
680     fi
681     D=bupdata.tmp
682     force-delete $D
683     mkdir -p $D/x
684     date > $D/x/1
685     tmpdir="$(mktemp -d /tmp/bup-test-XXXXXXX)"
686     cleanup() { set -x; rm -r "${tmpdir}"; set +x; }
687     trap cleanup EXIT
688     date > "$tmpdir/2"
689
690     export BUP_DIR="$TOP/buptest.tmp"
691     test -d "$BUP_DIR" && rm -r "$BUP_DIR"
692
693     WVPASS bup init
694     WVPASS bup index -vu $(pwd)/$D/x "$tmpdir"
695     WVPASS bup save -t -n src $(pwd)/$D/x "$tmpdir"
696     # For now, assume that "ls -a" and "sort" use the same order.
697     WVPASSEQ "$(bup ls -a src/latest)" "$(echo -e "$top_dir/\ntmp/" | sort)"
698 ) || WVFAIL
699
700 WVSTART "clear-index"
701 D=clear-index.tmp
702 export BUP_DIR="$TOP/$D/.bup"
703 force-delete $TOP/$D
704 mkdir $TOP/$D
705 WVPASS bup init
706 touch $TOP/$D/foo
707 touch $TOP/$D/bar
708 bup index -u $D
709 WVPASSEQ "$(bup index -p)" "$D/foo
710 $D/bar
711 $D/
712 ./"
713 rm $TOP/$D/foo
714 WVPASS bup index --clear
715 bup index -u $TOP/$D
716 WVPASSEQ "$(bup index -p)" "$D/bar
717 $D/
718 ./"
719
720 # bup index --exclude-rx ...
721 (
722     set -e
723     export BUP_DIR="$TOP/buptest.tmp"
724     D=bupdata.tmp
725
726     WVSTART "index --exclude-rx '^/foo' (root anchor)"
727     rm -rf "$D" "$BUP_DIR" buprestore.tmp
728     WVPASS bup init
729     mkdir $D
730     touch $D/a
731     touch $D/b
732     mkdir $D/sub1
733     mkdir $D/sub2
734     touch $D/sub1/a
735     touch $D/sub2/b
736     WVPASS bup index -u $D --exclude-rx "^$(pwd)/$D/sub1/"
737     bup save --strip -n bupdir $D
738     bup restore -C buprestore.tmp /bupdir/latest/
739     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
740 ./a
741 ./b
742 ./sub2
743 ./sub2/b"
744
745     WVSTART "index --exclude-rx '/foo$' (non-dir, tail anchor)"
746     rm -rf "$D" "$BUP_DIR" buprestore.tmp
747     WVPASS bup init
748     mkdir $D
749     touch $D/a
750     touch $D/b
751     touch $D/foo
752     mkdir $D/sub
753     mkdir $D/sub/foo
754     touch $D/sub/foo/a
755     WVPASS bup index -u $D --exclude-rx '/foo$'
756     bup save --strip -n bupdir $D
757     bup restore -C buprestore.tmp /bupdir/latest/
758     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
759 ./a
760 ./b
761 ./sub
762 ./sub/foo
763 ./sub/foo/a"
764
765     WVSTART "index --exclude-rx '/foo/$' (dir, tail anchor)"
766     rm -rf "$D" "$BUP_DIR" buprestore.tmp
767     WVPASS bup init
768     mkdir $D
769     touch $D/a
770     touch $D/b
771     touch $D/foo
772     mkdir $D/sub
773     mkdir $D/sub/foo
774     touch $D/sub/foo/a
775     WVPASS bup index -u $D --exclude-rx '/foo/$'
776     bup save --strip -n bupdir $D
777     bup restore -C buprestore.tmp /bupdir/latest/
778     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
779 ./a
780 ./b
781 ./foo
782 ./sub"
783
784     WVSTART "index --exclude-rx '/foo/.' (dir content)"
785     rm -rf "$D" "$BUP_DIR" buprestore.tmp
786     WVPASS bup init
787     mkdir $D
788     touch $D/a
789     touch $D/b
790     touch $D/foo
791     mkdir $D/sub
792     mkdir $D/sub/foo
793     touch $D/sub/foo/a
794     WVPASS bup index -u $D --exclude-rx '/foo/.'
795     bup save --strip -n bupdir $D
796     bup restore -C buprestore.tmp /bupdir/latest/
797     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
798 ./a
799 ./b
800 ./foo
801 ./sub
802 ./sub/foo"
803 ) || WVFAIL
804
805
806 # bup restore --exclude-rx ...
807 (
808     set -e
809     export BUP_DIR="$TOP/buptest.tmp"
810     D=bupdata.tmp
811
812     WVSTART "restore --exclude-rx '^/foo' (root anchor)"
813     rm -rf "$D" "$BUP_DIR" buprestore.tmp
814     WVPASS bup init
815     mkdir $D
816     touch $D/a
817     touch $D/b
818     mkdir $D/sub1
819     mkdir $D/sub2
820     touch $D/sub1/a
821     touch $D/sub2/b
822     WVPASS bup index -u $D
823     bup save --strip -n bupdir $D
824     bup restore -C buprestore.tmp --exclude-rx "^/sub1/" /bupdir/latest/
825     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
826 ./a
827 ./b
828 ./sub2
829 ./sub2/b"
830
831     WVSTART "restore --exclude-rx '/foo$' (non-dir, tail anchor)"
832     rm -rf "$D" "$BUP_DIR" buprestore.tmp
833     WVPASS bup init
834     mkdir $D
835     touch $D/a
836     touch $D/b
837     touch $D/foo
838     mkdir $D/sub
839     mkdir $D/sub/foo
840     touch $D/sub/foo/a
841     WVPASS bup index -u $D
842     bup save --strip -n bupdir $D
843     bup restore -C buprestore.tmp --exclude-rx '/foo$' /bupdir/latest/
844     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
845 ./a
846 ./b
847 ./sub
848 ./sub/foo
849 ./sub/foo/a"
850
851     WVSTART "restore --exclude-rx '/foo/$' (dir, tail anchor)"
852     rm -rf "$D" "$BUP_DIR" buprestore.tmp
853     WVPASS bup init
854     mkdir $D
855     touch $D/a
856     touch $D/b
857     touch $D/foo
858     mkdir $D/sub
859     mkdir $D/sub/foo
860     touch $D/sub/foo/a
861     WVPASS bup index -u $D
862     bup save --strip -n bupdir $D
863     bup restore -C buprestore.tmp --exclude-rx '/foo/$' /bupdir/latest/
864     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
865 ./a
866 ./b
867 ./foo
868 ./sub"
869
870     WVSTART "restore --exclude-rx '/foo/.' (dir content)"
871     rm -rf "$D" "$BUP_DIR" buprestore.tmp
872     WVPASS bup init
873     mkdir $D
874     touch $D/a
875     touch $D/b
876     touch $D/foo
877     mkdir $D/sub
878     mkdir $D/sub/foo
879     touch $D/sub/foo/a
880     WVPASS bup index -u $D
881     bup save --strip -n bupdir $D
882     bup restore -C buprestore.tmp --exclude-rx '/foo/.' /bupdir/latest/
883     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
884 ./a
885 ./b
886 ./foo
887 ./sub
888 ./sub/foo"
889 ) || WVFAIL