]> arthur.barton.de Git - bup.git/blob - t/test.sh
save-cmd.py: don't write an irrelevant and incomplete .bupm fragment.
[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     # Resolve any symlinks involving the top top-level dirs.
677     real_pwd="$(realpath .)"
678     real_tmp="$(realpath /tmp/.)"
679     pwd_top="$(echo $real_pwd | awk -F "/" '{print $2}')"
680     tmp_top="$(echo $real_tmp | awk -F "/" '{print $2}')"
681     if [ "$pwd_top" = "$tmp_top" ]; then
682         echo "(running from within /$tmp_top; skipping test)"
683         exit 0
684     fi
685     D=bupdata.tmp
686     force-delete $D
687     mkdir -p $D/x
688     date > $D/x/1
689     tmpdir="$(mktemp -d $real_tmp/bup-test-XXXXXXX)"
690     cleanup() { set -x; rm -r "${tmpdir}"; set +x; }
691     trap cleanup EXIT
692     date > "$tmpdir/2"
693
694     export BUP_DIR="$TOP/buptest.tmp"
695     test -d "$BUP_DIR" && rm -r "$BUP_DIR"
696
697     WVPASS bup init
698     WVPASS bup index -vu $(pwd)/$D/x "$tmpdir"
699     WVPASS bup save -t -n src $(pwd)/$D/x "$tmpdir"
700
701     # For now, assume that "ls -a" and "sort" use the same order.
702     WVPASSEQ "$(bup ls -a src/latest)" \
703         "$(echo -e "$pwd_top/\n$tmp_top/" | sort)"
704 ) || WVFAIL
705
706 WVSTART "clear-index"
707 D=clear-index.tmp
708 export BUP_DIR="$TOP/$D/.bup"
709 force-delete $TOP/$D
710 mkdir $TOP/$D
711 WVPASS bup init
712 touch $TOP/$D/foo
713 touch $TOP/$D/bar
714 bup index -u $D
715 WVPASSEQ "$(bup index -p)" "$D/foo
716 $D/bar
717 $D/
718 ./"
719 rm $TOP/$D/foo
720 WVPASS bup index --clear
721 bup index -u $TOP/$D
722 WVPASSEQ "$(bup index -p)" "$D/bar
723 $D/
724 ./"
725
726 # bup index --exclude-rx ...
727 (
728     set -e
729     export BUP_DIR="$TOP/buptest.tmp"
730     D=bupdata.tmp
731
732     WVSTART "index --exclude-rx '^/foo' (root anchor)"
733     rm -rf "$D" "$BUP_DIR" buprestore.tmp
734     WVPASS bup init
735     mkdir $D
736     touch $D/a
737     touch $D/b
738     mkdir $D/sub1
739     mkdir $D/sub2
740     touch $D/sub1/a
741     touch $D/sub2/b
742     WVPASS bup index -u $D --exclude-rx "^$(pwd)/$D/sub1/"
743     bup save --strip -n bupdir $D
744     bup restore -C buprestore.tmp /bupdir/latest/
745     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
746 ./a
747 ./b
748 ./sub2
749 ./sub2/b"
750
751     WVSTART "index --exclude-rx '/foo$' (non-dir, tail anchor)"
752     rm -rf "$D" "$BUP_DIR" buprestore.tmp
753     WVPASS bup init
754     mkdir $D
755     touch $D/a
756     touch $D/b
757     touch $D/foo
758     mkdir $D/sub
759     mkdir $D/sub/foo
760     touch $D/sub/foo/a
761     WVPASS bup index -u $D --exclude-rx '/foo$'
762     bup save --strip -n bupdir $D
763     bup restore -C buprestore.tmp /bupdir/latest/
764     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
765 ./a
766 ./b
767 ./sub
768 ./sub/foo
769 ./sub/foo/a"
770
771     WVSTART "index --exclude-rx '/foo/$' (dir, tail anchor)"
772     rm -rf "$D" "$BUP_DIR" buprestore.tmp
773     WVPASS bup init
774     mkdir $D
775     touch $D/a
776     touch $D/b
777     touch $D/foo
778     mkdir $D/sub
779     mkdir $D/sub/foo
780     touch $D/sub/foo/a
781     WVPASS bup index -u $D --exclude-rx '/foo/$'
782     bup save --strip -n bupdir $D
783     bup restore -C buprestore.tmp /bupdir/latest/
784     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
785 ./a
786 ./b
787 ./foo
788 ./sub"
789
790     WVSTART "index --exclude-rx '/foo/.' (dir content)"
791     rm -rf "$D" "$BUP_DIR" buprestore.tmp
792     WVPASS bup init
793     mkdir $D
794     touch $D/a
795     touch $D/b
796     touch $D/foo
797     mkdir $D/sub
798     mkdir $D/sub/foo
799     touch $D/sub/foo/a
800     WVPASS bup index -u $D --exclude-rx '/foo/.'
801     bup save --strip -n bupdir $D
802     bup restore -C buprestore.tmp /bupdir/latest/
803     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
804 ./a
805 ./b
806 ./foo
807 ./sub
808 ./sub/foo"
809 ) || WVFAIL
810
811
812 # bup restore --exclude-rx ...
813 (
814     set -e
815     export BUP_DIR="$TOP/buptest.tmp"
816     D=bupdata.tmp
817
818     WVSTART "restore --exclude-rx '^/foo' (root anchor)"
819     rm -rf "$D" "$BUP_DIR" buprestore.tmp
820     WVPASS bup init
821     mkdir $D
822     touch $D/a
823     touch $D/b
824     mkdir $D/sub1
825     mkdir $D/sub2
826     touch $D/sub1/a
827     touch $D/sub2/b
828     WVPASS bup index -u $D
829     bup save --strip -n bupdir $D
830     bup restore -C buprestore.tmp --exclude-rx "^/sub1/" /bupdir/latest/
831     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
832 ./a
833 ./b
834 ./sub2
835 ./sub2/b"
836
837     WVSTART "restore --exclude-rx '/foo$' (non-dir, tail anchor)"
838     rm -rf "$D" "$BUP_DIR" buprestore.tmp
839     WVPASS bup init
840     mkdir $D
841     touch $D/a
842     touch $D/b
843     touch $D/foo
844     mkdir $D/sub
845     mkdir $D/sub/foo
846     touch $D/sub/foo/a
847     WVPASS bup index -u $D
848     bup save --strip -n bupdir $D
849     bup restore -C buprestore.tmp --exclude-rx '/foo$' /bupdir/latest/
850     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
851 ./a
852 ./b
853 ./sub
854 ./sub/foo
855 ./sub/foo/a"
856
857     WVSTART "restore --exclude-rx '/foo/$' (dir, tail anchor)"
858     rm -rf "$D" "$BUP_DIR" buprestore.tmp
859     WVPASS bup init
860     mkdir $D
861     touch $D/a
862     touch $D/b
863     touch $D/foo
864     mkdir $D/sub
865     mkdir $D/sub/foo
866     touch $D/sub/foo/a
867     WVPASS bup index -u $D
868     bup save --strip -n bupdir $D
869     bup restore -C buprestore.tmp --exclude-rx '/foo/$' /bupdir/latest/
870     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
871 ./a
872 ./b
873 ./foo
874 ./sub"
875
876     WVSTART "restore --exclude-rx '/foo/.' (dir content)"
877     rm -rf "$D" "$BUP_DIR" buprestore.tmp
878     WVPASS bup init
879     mkdir $D
880     touch $D/a
881     touch $D/b
882     touch $D/foo
883     mkdir $D/sub
884     mkdir $D/sub/foo
885     touch $D/sub/foo/a
886     WVPASS bup index -u $D
887     bup save --strip -n bupdir $D
888     bup restore -C buprestore.tmp --exclude-rx '/foo/.' /bupdir/latest/
889     WVPASSEQ "$(cd buprestore.tmp && find . | sort)" ".
890 ./a
891 ./b
892 ./foo
893 ./sub
894 ./sub/foo"
895 ) || WVFAIL