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