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