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