]> arthur.barton.de Git - bup.git/blob - t/test-index-check-device.sh
Remove all of the remaining test-related "set -e" usage.
[bup.git] / t / test-index-check-device.sh
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh
3 . ./t/lib.sh
4
5 if [ $(t/root-status) != root ]; then
6     echo 'Not root: skipping --check-device tests.'
7     exit 0 # FIXME: add WVSKIP.
8 fi
9
10 if test -z "$(type -p losetup)"; then
11     echo 'Unable to find losetup: skipping --check-device tests.'
12     exit 0 # FIXME: add WVSKIP.
13 fi
14
15 if test -z "$(type -p mke2fs)"; then
16     echo 'Unable to find mke2fs: skipping --check-device tests.'
17     exit 0 # FIXME: add WVSKIP.
18 fi
19
20 WVSTART '--check-device'
21
22 top="$(pwd)"
23 tmpdir="$(WVPASS wvmktempdir)" || exit $?
24
25 export BUP_DIR="$tmpdir/bup"
26
27 bup() { "$top/bup" "$@"; }
28
29 srcmnt="$(WVPASS wvmkmountpt)" || exit $?
30 tmpmnt1="$(WVPASS wvmkmountpt)" || exit $?
31 tmpmnt2="$(WVPASS wvmkmountpt)" || exit $?
32
33 WVPASS cd "$tmpdir"
34
35 WVPASS dd if=/dev/zero of=testfs.img bs=1M count=32
36 WVPASS mke2fs -F -j -m 0 testfs.img
37 WVPASS mount -o loop testfs.img "$tmpmnt1"
38 # Hide, so that tests can't create risks.
39 WVPASS chown root:root "$tmpmnt1"
40 WVPASS chmod 0700 "$tmpmnt1"
41
42 # Create trivial content.
43 WVPASS date > "$tmpmnt1/foo"
44 WVPASS umount "$tmpmnt1"
45
46 # Mount twice, so we'll have the same content with different devices.
47 WVPASS mount -oro,loop testfs.img "$tmpmnt1"
48 WVPASS mount -oro,loop testfs.img "$tmpmnt2"
49
50 # Test default behavior: --check-device.
51 WVPASS mount -oro --bind "$tmpmnt1" "$srcmnt"
52 WVPASS bup init
53 WVPASS bup index --fake-valid "$srcmnt"
54 WVPASS umount "$srcmnt"
55 WVPASS mount -oro --bind "$tmpmnt2" "$srcmnt"
56 WVPASS bup index "$srcmnt"
57 WVPASSEQ "$(bup index --status "$srcmnt")" \
58 "M $srcmnt/lost+found/
59 M $srcmnt/foo
60 M $srcmnt/"
61 WVPASS umount "$srcmnt"
62
63 WVSTART '--no-check-device'
64 WVPASS mount -oro --bind "$tmpmnt1" "$srcmnt"
65 WVPASS bup index --clear
66 WVPASS bup index --fake-valid "$srcmnt"
67 WVPASS umount "$srcmnt"
68 WVPASS mount -oro --bind "$tmpmnt2" "$srcmnt"
69 WVPASS bup index --no-check-device "$srcmnt"
70 WVPASS bup index --status "$srcmnt"
71 WVPASSEQ "$(bup index --status "$srcmnt")" \
72 "  $srcmnt/lost+found/
73   $srcmnt/foo
74   $srcmnt/"
75
76 WVPASS umount "$srcmnt"
77 WVPASS umount "$tmpmnt1"
78 WVPASS umount "$tmpmnt2"
79 WVPASS rm -r "$tmpmnt1" "$tmpmnt2" "$tmpdir"