]> arthur.barton.de Git - bup.git/blob - t/test-xdev.sh
Never omit explicitly named mounts during index -x
[bup.git] / t / test-xdev.sh
1 #!/usr/bin/env bash
2 . ./wvtest-bup.sh || exit $?
3
4 set -o pipefail
5
6 if [ $(t/root-status) != root ]; then
7     WVSTART 'not root: skipping tests'
8     exit 0 # FIXME: add WVSKIP.
9 fi
10
11 if ! modprobe loop; then
12     WVSTART 'unable to load loopback module; skipping tests' 1>&2
13     exit 0
14 fi
15
16 # These tests are only likely to work under Linux for now
17 # (patches welcome).
18 if ! [[ $(uname) =~ Linux ]]; then
19     WVSTART 'not Linux: skipping tests'
20     exit 0 # FIXME: add WVSKIP.
21 fi
22
23 top="$(WVPASS pwd)" || exit $?
24 tmpdir="$(WVPASS wvmktempdir)" || exit $?
25
26 export BUP_DIR="$tmpdir/bup"
27 export GIT_DIR="$tmpdir/bup"
28
29 bup() { "$top/bup" "$@"; }
30
31 WVPASS bup init
32 WVPASS pushd "$tmpdir"
33
34 WVSTART 'drecurse'
35
36 WVPASS dd if=/dev/zero of=testfs-1.img bs=1M count=32
37 WVPASS dd if=/dev/zero of=testfs-2.img bs=1M count=32
38 WVPASS mkfs -F testfs-1.img # Don't care what type (though must have symlinks)
39 WVPASS mkfs -F testfs-2.img # Don't care what type (though must have symlinks)
40 WVPASS mkdir -p src/mnt-1/hidden-1 src/mnt-2/hidden-2
41 WVPASS mount -o loop testfs-1.img src/mnt-1
42 WVPASS mount -o loop testfs-1.img src/mnt-2
43
44 WVPASS touch src/1
45
46 WVPASS mkdir -p src/mnt-1/x
47 WVPASS touch src/mnt-1/2 src/mnt-1/x/3
48
49 WVPASS touch src/mnt-2/4
50
51 (WVPASS cd src && WVPASS ln -s mnt-2 mnt-link)
52 (WVPASS cd src && WVPASS ln -s . top)
53
54 WVPASSEQ "$(bup drecurse src | grep -vF lost+found)" "src/top
55 src/mnt-link
56 src/mnt-2/4
57 src/mnt-2/
58 src/mnt-1/x/3
59 src/mnt-1/x/
60 src/mnt-1/2
61 src/mnt-1/
62 src/1
63 src/"
64
65 WVPASSEQ "$(bup drecurse -x src)" "src/top
66 src/mnt-link
67 src/mnt-2/
68 src/mnt-1/
69 src/1
70 src/"
71
72 WVSTART 'index/save/restore'
73
74 WVPASS bup index src
75 WVPASS bup save -n src src
76 WVPASS mkdir src-restore
77 WVPASS bup restore -C src-restore "/src/latest$(pwd)/"
78 WVPASS test -d src-restore/src
79 WVPASS "$top/t/compare-trees" -c src/ src-restore/src/
80
81 # Test -x when none of the mount points are explicitly indexed
82 WVPASS rm -r "$BUP_DIR" src-restore
83 WVPASS bup init
84 WVPASS bup index -x src
85 WVPASS bup save -n src src
86 WVPASS mkdir src-restore
87 WVPASS bup restore -C src-restore "/src/latest$(pwd)/"
88 WVPASS test -d src-restore/src
89 WVPASSEQ "$(cd src-restore/src && find . -not -name lost+found | LC_ALL=C sort)" \
90 ".
91 ./1
92 ./mnt-1
93 ./mnt-2
94 ./mnt-link
95 ./top"
96
97 # Test -x when a mount point is explicitly indexed.  This should
98 # include the mount.
99 WVPASS rm -r "$BUP_DIR" src-restore
100 WVPASS bup init
101 WVPASS bup index -x src src/mnt-2
102 WVPASS bup save -n src src
103 WVPASS mkdir src-restore
104 WVPASS bup restore -C src-restore "/src/latest$(pwd)/"
105 WVPASS test -d src-restore/src
106 WVPASSEQ "$(cd src-restore/src && find . -not -name lost+found | LC_ALL=C sort)" \
107 ".
108 ./1
109 ./mnt-1
110 ./mnt-2
111 ./mnt-2/4
112 ./mnt-link
113 ./top"
114
115 # Test -x when a direct link to a mount point is explicitly indexed.
116 # This should *not* include the mount.
117 WVPASS rm -r "$BUP_DIR" src-restore
118 WVPASS bup init
119 WVPASS bup index -x src src/mnt-link
120 WVPASS bup save -n src src
121 WVPASS mkdir src-restore
122 WVPASS bup restore -C src-restore "/src/latest$(pwd)/"
123 WVPASS test -d src-restore/src
124 WVPASSEQ "$(cd src-restore/src && find . -not -name lost+found | LC_ALL=C sort)" \
125 ".
126 ./1
127 ./mnt-1
128 ./mnt-2
129 ./mnt-link
130 ./top"
131
132 # Test -x when a path that resolves to a mount point is explicitly
133 # indexed (i.e. dir symlnks that redirect the leaf to a mount point).
134 # This should include the mount.
135 WVPASS rm -r "$BUP_DIR" src-restore
136 WVPASS bup init
137 WVPASS bup index -x src src/top/top/mnt-2
138 WVPASS bup save -n src src
139 WVPASS mkdir src-restore
140 WVPASS bup restore -C src-restore "/src/latest$(pwd)/"
141 WVPASS test -d src-restore/src
142 WVPASSEQ "$(cd src-restore/src && find . -not -name lost+found | LC_ALL=C sort)" \
143 ".
144 ./1
145 ./mnt-1
146 ./mnt-2
147 ./mnt-2/4
148 ./mnt-link
149 ./top"
150
151 WVPASS cd "$top"
152 WVPASS umount "$tmpdir/src/mnt-1"
153 WVPASS umount "$tmpdir/src/mnt-2"
154 WVPASS rm -r "$tmpdir"