]> arthur.barton.de Git - bup.git/blob - t/test.sh
Disallow empty graft points.
[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 WVSTART "ftp"
242 WVPASS bup ftp "cat /master/latest/$TOP/$D/b" >$D/b.new
243 WVPASS bup ftp "cat /master/latest/$TOP/$D/f" >$D/f.new
244 WVPASS bup ftp "cat /master/latest/$TOP/$D/f"{,} >$D/f2.new
245 WVPASS bup ftp "cat /master/latest/$TOP/$D/a" >$D/a.new
246 WVPASSEQ "$(sha1sum <$D/b)" "$(sha1sum <$D/b.new)"
247 WVPASSEQ "$(sha1sum <$D/f)" "$(sha1sum <$D/f.new)"
248 WVPASSEQ "$(cat $D/f.new{,} | sha1sum)" "$(sha1sum <$D/f2.new)"
249 WVPASSEQ "$(sha1sum <$D/a)" "$(sha1sum <$D/a.new)"
250
251 WVSTART "tag"
252 WVFAIL bup tag -d v0.n 2>/dev/null
253 WVFAIL bup tag v0.n non-existant 2>/dev/null
254 WVPASSEQ "$(bup tag)" ""
255 WVPASS bup tag v0.1 master
256 WVPASSEQ "$(bup tag)" "v0.1"
257 WVPASS bup tag -d v0.1
258
259 # This section destroys data in the bup repository, so it is done last.
260 WVSTART "fsck"
261 WVPASS bup fsck
262 WVPASS bup fsck --quick
263 if bup fsck --par2-ok; then
264     WVSTART "fsck (par2)"
265 else
266     WVSTART "fsck (PAR2 IS MISSING)"
267 fi
268 WVPASS bup fsck -g
269 WVPASS bup fsck -r
270 WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n10 -s1 -S0
271 WVFAIL bup fsck --quick
272 WVFAIL bup fsck --quick --disable-par2
273 chmod u+w $BUP_DIR/objects/pack/*.idx
274 WVPASS bup damage $BUP_DIR/objects/pack/*.idx -n10 -s1 -S0
275 WVFAIL bup fsck --quick -j4
276 WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n10 -s1024 --percent 0.4 -S0
277 WVFAIL bup fsck --quick
278 WVFAIL bup fsck --quick -rvv -j99   # fails because repairs were needed
279 if bup fsck --par2-ok; then
280     WVPASS bup fsck -r # ok because of repairs from last time
281     WVPASS bup damage $BUP_DIR/objects/pack/*.pack -n202 -s1 --equal -S0
282     WVFAIL bup fsck
283     WVFAIL bup fsck -rvv   # too many errors to be repairable
284     WVFAIL bup fsck -r   # too many errors to be repairable
285 else
286     WVFAIL bup fsck --quick -r # still fails because par2 was missing
287 fi
288
289 WVSTART "exclude-bupdir"
290 D=exclude-bupdir.tmp
291 rm -rf $D
292 mkdir $D
293 export BUP_DIR="$D/.bup"
294 WVPASS bup init
295 touch $D/a
296 WVPASS bup random 128k >$D/b
297 mkdir $D/d $D/d/e
298 WVPASS bup random 512 >$D/f
299 WVPASS bup index -ux $D
300 bup save -n exclude-bupdir $D
301 WVPASSEQ "$(bup ls -a exclude-bupdir/latest/$TOP/$D/)" "a
302 b
303 d/
304 f"
305
306 WVSTART "exclude"
307 D=exclude.tmp
308 rm -rf $D
309 mkdir $D
310 export BUP_DIR="$D/.bup"
311 WVPASS bup init
312 touch $D/a
313 WVPASS bup random 128k >$D/b
314 mkdir $D/d $D/d/e
315 WVPASS bup random 512 >$D/f
316 WVPASS bup index -ux --exclude $D/d $D
317 bup save -n exclude $D
318 WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
319 b
320 f"
321 mkdir $D/g $D/h
322 WVPASS bup index -ux --exclude $D/d --exclude $TOP/$D/g --exclude $D/h $D
323 bup save -n exclude $D
324 WVPASSEQ "$(bup ls exclude/latest/$TOP/$D/)" "a
325 b
326 f"
327
328 WVSTART "exclude-from"
329 D=exclude-fromdir.tmp
330 EXCLUDE_FILE=exclude-from.tmp
331 echo "$D/d 
332  $TOP/$D/g
333 $D/h" > $EXCLUDE_FILE
334 rm -rf $D
335 mkdir $D
336 export BUP_DIR="$D/.bup"
337 WVPASS bup init
338 touch $D/a
339 WVPASS bup random 128k >$D/b
340 mkdir $D/d $D/d/e
341 WVPASS bup random 512 >$D/f
342 mkdir $D/g $D/h
343 WVPASS bup index -ux --exclude-from $EXCLUDE_FILE $D
344 bup save -n exclude-from $D
345 WVPASSEQ "$(bup ls exclude-from/latest/$TOP/$D/)" "a
346 b
347 f"
348 rm $EXCLUDE_FILE
349
350 WVSTART "strip"
351 D=strip.tmp
352 rm -rf $D
353 mkdir $D
354 export BUP_DIR="$D/.bup"
355 WVPASS bup init
356 touch $D/a
357 WVPASS bup random 128k >$D/b
358 mkdir $D/d $D/d/e
359 WVPASS bup random 512 >$D/f
360 WVPASS bup index -ux $D
361 bup save --strip -n strip $D
362 WVPASSEQ "$(bup ls strip/latest/)" "a
363 b
364 d/
365 f"
366
367 WVSTART "strip-path"
368 D=strip-path.tmp
369 rm -rf $D
370 mkdir $D
371 export BUP_DIR="$D/.bup"
372 WVPASS bup init
373 touch $D/a
374 WVPASS bup random 128k >$D/b
375 mkdir $D/d $D/d/e
376 WVPASS bup random 512 >$D/f
377 WVPASS bup index -ux $D
378 bup save --strip-path $TOP -n strip-path $D
379 WVPASSEQ "$(bup ls strip-path/latest/$D/)" "a
380 b
381 d/
382 f"
383
384 WVSTART "graft_points"
385 D=graft-points.tmp
386 rm -rf $D
387 mkdir $D
388 export BUP_DIR="$D/.bup"
389 WVPASS bup init
390 touch $D/a
391 WVPASS bup random 128k >$D/b
392 mkdir $D/d $D/d/e
393 WVPASS bup random 512 >$D/f
394 WVPASS bup index -ux $D
395 WVFAIL bup save --graft =/grafted -n graft-point-absolute $D
396 WVFAIL bup save --graft $TOP/$D= -n graft-point-absolute $D
397 bup save --graft $TOP/$D=/grafted -n graft-point-absolute $D
398 WVPASSEQ "$(bup ls graft-point-absolute/latest/grafted/)" "a
399 b
400 d/
401 f"
402 bup save --graft $D=grafted -n graft-point-relative $D
403 WVPASSEQ "$(bup ls graft-point-relative/latest/$TOP/grafted/)" "a
404 b
405 d/
406 f"
407
408 WVSTART "indexfile"
409 D=indexfile.tmp
410 INDEXFILE=tmpindexfile.tmp
411 rm -f $INDEXFILE
412 rm -rf $D
413 mkdir $D
414 export BUP_DIR="$D/.bup"
415 WVPASS bup init
416 touch $D/a
417 touch $D/b
418 mkdir $D/c
419 WVPASS bup index -ux $D
420 bup save --strip -n bupdir $D
421 WVPASSEQ "$(bup ls bupdir/latest/)" "a
422 b
423 c/"
424 WVPASS bup index -f $INDEXFILE --exclude=$D/c -ux $D
425 bup save --strip -n indexfile -f $INDEXFILE $D
426 WVPASSEQ "$(bup ls indexfile/latest/)" "a
427 b"
428
429
430 WVSTART "import-rsnapshot"
431 D=rsnapshot.tmp
432 export BUP_DIR="$TOP/$D/.bup"
433 rm -rf $D
434 mkdir $D
435 WVPASS bup init
436 mkdir -p $D/hourly.0/buptest/a
437 touch $D/hourly.0/buptest/a/b
438 mkdir -p $D/hourly.0/buptest/c/d
439 touch $D/hourly.0/buptest/c/d/e
440 WVPASS true
441 WVPASS bup import-rsnapshot $D/
442 WVPASSEQ "$(bup ls buptest/latest/)" "a/
443 c/"
444
445
446 if [ "$(which rdiff-backup)" != "" ]; then
447     WVSTART "import-rdiff-backup"
448     D=rdiff-backup.tmp
449     export BUP_DIR="$TOP/$D/.bup"
450     rm -rf $D
451     mkdir $D
452     WVPASS bup init
453     mkdir $D/rdiff-backup
454     rdiff-backup $TOP/cmd $D/rdiff-backup
455     bup tick
456     rdiff-backup $TOP/Documentation $D/rdiff-backup
457     WVPASS bup import-rdiff-backup $D/rdiff-backup import-rdiff-backup
458     WVPASSEQ "$(bup ls import-rdiff-backup/ | wc -l)" "3"
459     WVPASSEQ "$(bup ls import-rdiff-backup/latest/ | sort)" "$(ls $TOP/Documentation | sort)"
460 fi
461
462
463 WVSTART "compression"
464 D=compression0.tmp
465 export BUP_DIR="$TOP/$D/.bup"
466 rm -rf $D
467 mkdir $D
468 WVPASS bup init
469 WVPASS bup index $TOP/Documentation
470 WVPASS bup save -n compression -0 --strip $TOP/Documentation
471 # 'ls' on NetBSD sets -A by default when running as root, so we have to undo
472 # it by grepping out any dotfiles.  (Normal OSes don't auto-set -A, but this
473 # is harmless there.)
474 WVPASSEQ "$(bup ls compression/latest/ | sort)" \
475          "$(ls $TOP/Documentation | grep -v '^\.' | sort)"
476 COMPRESSION_0_SIZE=$(du -s $D | cut -f1)
477
478 D=compression9.tmp
479 export BUP_DIR="$TOP/$D/.bup"
480 rm -rf $D
481 mkdir $D
482 WVPASS bup init
483 WVPASS bup index $TOP/Documentation
484 WVPASS bup save -n compression -9 --strip $TOP/Documentation
485 WVPASSEQ "$(bup ls compression/latest/ | sort)" "$(ls $TOP/Documentation | sort)"
486 COMPRESSION_9_SIZE=$(du -s $D | cut -f1)
487
488 WVPASS [ "$COMPRESSION_9_SIZE" -lt "$COMPRESSION_0_SIZE" ]
489
490
491 WVSTART "save disjoint top-level directories"
492 (
493     set -e
494     top_dir="$(echo $(pwd) | awk -F "/" '{print $2}')"
495     if [ "$top_dir" == tmp ]; then
496         echo "(running from within /tmp; skipping test)"
497         exit 0
498     fi
499     D=bupdata.tmp
500     rm -rf $D
501     mkdir -p $D/x
502     date > $D/x/1
503     tmpdir="$(mktemp --tmpdir=/tmp -d bup-test-XXXXXXX)"
504     cleanup() { set -x; rm -rf "${tmpdir}"; set +x; }
505     trap cleanup EXIT
506     date > "$tmpdir/2"
507
508     export BUP_DIR="$TOP/buptest.tmp"
509     rm -rf "$BUP_DIR"
510
511     WVPASS bup init
512     WVPASS bup index -vu $(pwd)/$D/x "$tmpdir"
513     WVPASS bup save -t -n src $(pwd)/$D/x "$tmpdir"
514     WVPASSEQ "$(bup ls -a src/latest)" \
515 "$top_dir/
516 tmp/"
517 ) || WVFAIL