]> wimlib.net Git - wimlib/blob - tests/test-imagex-mount
Do not capture directory hard links
[wimlib] / tests / test-imagex-mount
1 #!/usr/bin/env bash
2
3 # Test WIM mounting
4
5 set -e
6 cd tests
7 srcdir="${srcdir:-.}/.."
8 srcdir="$(cd $srcdir; pwd)"
9 . "$srcdir/tests/tests-common.sh"
10
11 TEST_SUBDIR=tmpdir_test-imagex-mount
12
13 if [ ! -r /dev/fuse ]; then
14         echo "WARNING: /dev/fuse is not readable."
15         echo "Skipping WIM mounting checks"
16         exit 0
17 fi
18
19 cleanup() {
20         fusermount -u $TEST_SUBDIR/tmp &> /dev/null || true
21         fusermount -u $TEST_SUBDIR/tmp.mnt &> /dev/null || true
22         rm -rf $TEST_SUBDIR
23 }
24
25 init() {
26         mkdir dir
27         cp $srcdir/src/*.c $srcdir/src/*.h dir
28         mkdir dir/subdir
29         echo 'hello' > dir/subdir/hello
30         echo 'hello' > dir/subdir/hello2
31         ln dir/subdir/hello dir/subdir/hellolink
32         echo -n > dir/subdir/empty_file
33         ln -s hello dir/subdir/rel_symlink
34
35         mkdir dir2
36         echo 'testing' > dir2/file
37         dd if=/dev/zero of=dir2/zeroes bs=4096 count=5
38         mkdir tmp.empty tmp.mnt tmp.apply tmp.orig
39         imagex capture tmp.empty empty.wim
40 }
41
42 cleanup
43 mkdir $TEST_SUBDIR
44 cd $TEST_SUBDIR
45 init
46
47 # imagex mount
48
49 for flag in "--compress=none" "--compress=maximum" "--compress=fast"; do
50         echo "Using flag $flag"
51         echo "Testing mounting WIM read-only"
52         if ! imagex capture dir dir.wim $flag; then
53                 error "Failed to capture WIM"
54         fi
55         mkdir tmp
56         if ! imagex mount dir.wim dir tmp; then
57                 error "Failed to mount test WIM read-only. " \
58                       "Please read any error messages above before reporting this test failure. "\
59                       "Perhaps you don't have FUSE installed, or the FUSE kernel module isn't" \
60                       "loaded, or you aren't a member of the FUSE group?"
61         fi
62         echo "Testing extracting file from mounted read-only WIM"
63         if ! cp tmp/lz77.c lz77.c; then
64                 error "Failed to extract file from read-only mounted WIM"
65         fi
66         if ! diff -q dir/lz77.c lz77.c; then
67                 error "Extracted file does not match copy in mounted WIM"
68         fi
69         if ! diff -q tmp/lz77.c dir/lz77.c; then
70                 error "Extractef file does not match original"
71         fi
72         rm -f lz77.c
73         echo "Testing modifying mounted read-only WIM (should fail)"
74         if rm tmp/lz77.c; then
75                 error "Removing file from read-only mounted WIM didn't fail"
76         fi
77         if touch tmp/newfile; then
78                 error "Creating file on read-only mounted WIM didn't fail"
79         fi
80         if echo 3 > tmp/lz77.c; then
81                 error "Writing to file on read-only mounted WIM didn't fail"
82         fi
83         echo "Testing diff of mounted read-only WIM with original directory"
84         if ! diff -q -r tmp dir; then
85                 error "Recursive diff of read-only mounted WIM with original directory failed"
86         fi
87         echo "Testing unmount of read-only filesystem"
88         if ! imagex unmount tmp; then
89                 error "Unmounting read-only WIM failed"
90         fi
91         echo "Testing unmount of read-only filesystem with --commit given"
92         if ! imagex mount dir.wim dir tmp; then
93                 error "Failed to re-mount WIM read-only"
94         fi
95         if ! imagex unmount tmp --commit; then
96                 error "Failed to unmount read-only WIM with --commit flag (should be ignored)"
97         fi
98         rm -rf tmp dir.wim
99 done
100
101 # imagex mountrw
102 echo "Testing mounting WIM read-write"
103 if ! imagex capture dir dir.wim; then
104         error "Failed to capture WIM"
105 fi
106 mkdir tmp
107 if ! imagex mountrw dir.wim dir tmp; then
108         error "Failed to mount test WIM read-write"
109 fi
110 echo "Testing unmounting WIM unmodified"
111 if ! imagex unmount tmp; then
112         error "Failed to unmount test WIM unmodified"
113 fi
114 echo "Testing unmounting WIM unmodified with --commit and --check"
115 if ! imagex mountrw dir.wim dir tmp; then
116         error "Failed to re-mount test WIM read-write"
117 fi
118 if ! imagex unmount tmp --commit --check; then
119         error "Failed to unmount read-write mounted WIM with changes commited (no changes made)"
120 fi
121 echo "Testing removing file from mounted WIM"
122 if ! imagex mountrw dir.wim dir tmp; then
123         error "Failed to re-mount test WIM read-write"
124 fi
125 if ! rm tmp/lz77.c; then
126         error "Failed to remove file from read-write mounted WIM"
127 fi
128 if test -f tmp/lz77.c; then
129         error "Removing file from read-write mounted WIM failed"
130 fi
131 echo "Testing making directory in mounted WIM"
132 if ! mkdir tmp/newdir; then
133         error "Failed to make directory in read-write mounted WIM"
134 fi
135 if ! test -d tmp/newdir; then
136         error "Making directory in read-write mounted WIM failed"
137 fi
138 echo "Testing making new empty file in mounted WIM"
139 if ! touch tmp/newdir/empty_file; then
140         error "Could not create new empty file in read-write mounted WIM"
141 fi
142 if ! test -f tmp/newdir/empty_file; then
143         error "New empty file not created correctly in read-write mounted WIM"
144 fi
145 if ! test "`get_file_size tmp/newdir/empty_file`" = 0; then
146         error "New empty file in read-write mounted WIM is not empty"
147 fi
148 echo "Testing making new non-empty file in mounted WIM"
149 if ! dd if=/dev/zero of=tmp/newdir/zeroes1 bs=1 count=4096; then
150         error "Failed to make new non-empty file in mounted WIM"
151 fi
152 if ! dd if=/dev/zero of=tmp/newdir/zeroes2 bs=4096 count=1; then
153         error "Failed to make new non-empty file in mounted WIM"
154 fi
155 if ! diff -q tmp/newdir/zeroes1 tmp/newdir/zeroes2; then
156         error "New files in mounted WIM not made correctly"
157 fi
158 echo "Unmounting WIM with changes committed and --check"
159 if ! imagex unmount tmp --commit --check; then
160         error "Failed to unmount read-write mounted WIM"
161 fi
162 if test "`imagex info dir.wim | grep Integrity | awk '{print $3}'`" != "yes"; then
163         error "Integrity information was not included"
164 fi
165 rm -rf tmp
166 if ! imagex apply dir.wim tmp; then
167         error "Failed to apply WIM we had previously mounted read-write"
168 fi
169 if ! diff -q tmp/newdir/zeroes1 tmp/newdir/zeroes2; then
170         error "The new non-empty files we made in the read-write mounted WIM were not extracted correctly"
171 fi
172 if test `get_file_size tmp/newdir/empty_file` != 0; then
173         error "The new empty file we made in the read-write mounted WIM was not extracted correctly"
174 fi
175 if test `get_file_size tmp/newdir/zeroes1` != 4096; then
176         error "The new non-empty files we made in the read-write mounted WIM were not extracted correctly"
177 fi
178
179 # Now do some tests using tar.
180 do_tree_cmp() {
181         if ! ../tree-cmp $1 $2; then
182                 if [ -x /usr/bin/tree ]; then
183                         echo "Dumping tree of applied image"
184                         tree $2 --inodes -F -s --noreport
185                         error 'Information was lost or corrupted while capturing
186                                 and then applying a directory tree'
187                 fi
188         fi
189 }
190
191 msg() {
192         echo "--------------------------------------------------------------------"
193         echo "Testing making $1 on read-write mounted WIM"
194         echo "--------------------------------------------------------------------"
195 }
196
197 do_test() {
198
199         # Create tree, tar it up, and untar it on an empty WIM image mounted
200         # read-write
201
202         cp empty.wim test.wim
203
204         cd tmp.orig
205         eval "$1"
206         if [ -x /usr/bin/tree ]; then
207                 tree . --inodes -F -s --noreport
208         fi
209         tar cf ../test.tar .
210         cd ..
211
212         if ! imagex mountrw test.wim tmp.mnt --unix-data; then
213                 error "Failed to mount WIM read-write"
214         fi
215
216         cd tmp.mnt
217         if ! tar xf ../test.tar; then
218                 error "Failed to untar archive on read-write mounted WIM"
219         fi
220         cd ..
221
222         # Diff the original tree with the mounted WIM
223         do_tree_cmp tmp.orig tmp.mnt
224
225         # Clear the mounted WIM and do it again!  (We need to test deleting
226         # stuff as well as creating stuff.)
227         if ! rm -rf tmp.mnt/*; then
228                 error "Failed to clear mounted WIM"
229         fi
230
231         cd tmp.mnt
232         if ! tar xf ../test.tar; then
233                 error "Failed to untar archive on read-write mounted WIM"
234         fi
235         cd ..
236
237         # Diff the original tree with the mounted WIM
238         do_tree_cmp tmp.orig tmp.mnt
239
240         # Unmount the WIM, apply it, and diff the original tree with the applied
241         # tree
242         if ! imagex unmount tmp.mnt --commit; then
243                 error "Failed to unmount WIM mounted read-write"
244         fi
245         if ! imagex apply test.wim tmp.apply; then
246                 error "Failed to apply WIM we previously had mounted read-write"
247         fi
248         do_tree_cmp tmp.orig tmp.apply
249         rm -rf tmp.orig/* tmp.apply/*
250 }
251
252 . $srcdir/tests/common_tests.sh
253
254
255 echo "**********************************************************"
256 echo "                 WIM mount tests passed                   "
257 echo "**********************************************************"
258
259 cd ..
260 cleanup