]> wimlib.net Git - wimlib/blob - tests/test-imagex-update_and_extract
mount_image.c: add fallback definitions of RENAME_* constants
[wimlib] / tests / test-imagex-update_and_extract
1 #!/usr/bin/env bash
2
3 # Test `wimupdate' and `wimextract'.
4
5 set -e
6 cd tests
7 srcdir="${srcdir:-.}/.."
8 srcdir="$(cd $srcdir; pwd)"
9 . "$srcdir/tests/test_utils.sh"
10
11 TEST_SUBDIR=tmpdir_test-imagex-update_and_extract
12
13 default_cleanup
14 mkdir $TEST_SUBDIR
15 cd $TEST_SUBDIR
16
17 msg() {
18         echo "--------------------------------------------------------------------"
19         echo $1
20         echo "--------------------------------------------------------------------"
21 }
22
23 fail() {
24         msg "TEST FAILED (See above)"
25 }
26
27 trap fail EXIT
28
29 prepare_empty_wim() {
30         rm -rf in.dir
31         mkdir in.dir
32         wimcapture in.dir test.wim --compress=none
33 }
34
35 do_apply() {
36         rm -rf out.dir
37         wimapply test.wim out.dir
38 }
39
40 prepare_empty_wim
41 cp $srcdir/src/add_image.c file
42 echo 1 > 1
43 echo 2 > 2
44
45 msg "Testing deleting nonexisting file from WIM image, without --force (errors expected)"
46 ! wimupdate test.wim << EOF
47 delete /nonexistent
48 EOF
49
50 msg "Testing deleting nonexisting file from WIM image, with --force"
51 ! wimupdate test.wim << EOF
52 delete --force /nonexistent
53 EOF
54
55 msg "Testing deleting root directory from WIM image, without --recursive (errors expected)"
56 ! wimupdate test.wim << EOF
57 delete /
58 EOF
59
60 msg "Testing deleting root directory from WIM image, with --recursive"
61 wimupdate test.wim << EOF
62 delete --recursive /
63 EOF
64
65 msg "Testing update command with invalid option (errors expected)"
66 ! wimupdate test.wim << EOF
67 delete --invalid-option --recursive /
68 EOF
69
70 msg "Testing update command with too many arguments (errors expected)"
71 ! wimupdate test.wim << EOF
72 delete --recursive --force / /anotherdir
73 EOF
74
75 msg "Testing invalid update command (errors expected)"
76 ! wimupdate test.wim << EOF
77 invalid /
78 EOF
79
80 msg "Testing update command file with comments and empty lines"
81 wimupdate test.wim << EOF
82 # this is a comment
83         # comment
84                         
85            
86 # add
87 # delete
88 # rename
89
90 EOF
91
92 msg "Testing update with --rebuild"
93 wimupdate --rebuild test.wim < /dev/null
94
95 for flag in "" "--rebuild"; do
96         msg "Testing adding file to WIM image with flag \"$flag\""
97         wimupdate test.wim $flag << EOF
98 add file /file
99 EOF
100         do_apply
101         ../tree-cmp file out.dir/file
102
103         msg "Testing deleting file from WIM image"
104         wimupdate test.wim << EOF
105 delete /file
106 EOF
107         do_apply
108         [ ! -e out.dir/file ]
109 done
110
111 msg "Testing renaming file in WIM image"
112 wimupdate test.wim << EOF
113 add file /file
114 EOF
115 wimupdate test.wim << EOF
116 rename file newname
117 EOF
118 do_apply
119 ../tree-cmp file out.dir/newname
120 [ ! -e out.dir/file ]
121
122 prepare_empty_wim
123 msg "Testing UTF-16LE-NOBOM command update file"
124 echo -ne 'a\0d\0d\0 \0f\0i\0l\0e\0 \0/\0f\0i\0l\0e\0\n\0' \
125         | wimupdate test.wim
126 do_apply
127 ../tree-cmp file out.dir/file
128
129 prepare_empty_wim
130 msg "Testing UTF-16LE-BOM command update file"
131 echo -ne '\xff\xfea\0d\0d\0 \0f\0i\0l\0e\0 \0/\0f\0i\0l\0e\0\n\0' \
132         | wimupdate test.wim
133 do_apply
134 ../tree-cmp file out.dir/file
135
136 prepare_empty_wim
137 msg "Testing UTF-8-BOM command update file"
138 echo -ne '\xef\xbb\xbfadd file /file' | wimupdate test.wim
139 do_apply
140 ../tree-cmp file out.dir/file
141
142 prepare_empty_wim
143 msg "Testing adding, then renaming file in WIM image in one command"
144 wimupdate test.wim << EOF
145 add file /file
146 rename /file /newname
147 EOF
148 do_apply
149 ../tree-cmp file out.dir/newname
150 [ ! -e out.dir/file ]
151
152 msg "Testing adding additional file to WIM image"
153 prepare_empty_wim
154 wimupdate test.wim << EOF
155 add 1 /1
156 EOF
157 wimupdate test.wim << EOF
158 add file /file
159 EOF
160 do_apply
161 [ -e out.dir/1 ]
162 [ -e out.dir/file ]
163
164 msg "Testing extracting file from WIM image"
165 rm -rf out.dir
166 mkdir out.dir
167 wimextract test.wim 1 /file --dest-dir=out.dir
168 ../tree-cmp file out.dir/file
169 [ ! -e out.dir/1 ]
170
171 msg "Testing extracting file from WIM image to stdout"
172 rm -rf out.dir
173 mkdir out.dir
174 wimlib_imagex extract test.wim 1 /file --to-stdout > out.dir/file
175 cmp file out.dir/file
176 [ ! -e out.dir/1 ]
177
178 msg "Testing adding directories and files to WIM image"
179 rm -rf dir1
180 mkdir dir1
181 rm -rf dir2
182 mkdir dir2
183 echo 5 > dir1/5
184 echo 6 > dir2/6.1
185 echo 6 > dir2/6
186 echo 6 > dir2/6.2
187 ln -s 5 dir1/relink
188 mkdir dir1/subdir
189 ln dir1/5 dir1/5link
190 ln dir2/6 dir2/6link
191 prepare_empty_wim
192 wimupdate test.wim 1 << EOF
193 add dir1 /dir1
194 add dir2 /prefix/dir2
195 EOF
196 rm -rf out.dir
197 mkdir out.dir
198 wimextract test.wim 1 dir1 --dest-dir=out.dir
199 wimextract test.wim 1 prefix/dir2 --dest-dir=out.dir
200 ../tree-cmp dir1 out.dir/dir1
201 ../tree-cmp dir2 out.dir/dir2
202
203 msg "Testing adding files to WIM image"
204 rm -rf in.dir
205 mkdir in.dir
206 wimappend in.dir test.wim "2"
207 cp $srcdir/src/*.c in.dir
208 wimupdate test.wim 2 << EOF
209 add in.dir /
210 add file /file
211 EOF
212 cp -a file in.dir/file
213 rm -rf out.dir
214 wimapply test.wim 2 out.dir
215 touch -r in.dir out.dir
216 ../tree-cmp in.dir out.dir
217
218 msg "Testing adding file with space in it"
219 echo hello > "Some File"
220 prepare_empty_wim
221 wimupdate test.wim 1 << EOF
222         add     "Some File"     'Some Destination'
223 EOF
224 rm -rf out.dir
225 wimapply test.wim 1 out.dir
226 ../tree-cmp "Some File" out.dir/"Some Destination"
227
228 msg "Testing path list extract"
229 echo hello1 > hello1
230 echo hello2 > hello2
231 echo otherfile > otherfile
232 prepare_empty_wim
233 wimupdate test.wim 1 << EOF
234         add hello1 /hello1
235         add hello2 /hello2
236         add otherfile /otherfile
237 EOF
238 cat > pathlist << EOF
239 hello1
240 hello2
241 EOF
242 rm -rf out.dir
243 wimextract test.wim 1 @pathlist --dest-dir=out.dir
244 ../tree-cmp hello1 out.dir/hello1
245 ../tree-cmp hello2 out.dir/hello2
246 [ ! -e out.dir/otherfile ]
247
248 msg "Testing path list extract (stdin)"
249 rm -rf out.dir
250 wimextract test.wim 1 @- --dest-dir=out.dir << EOF
251 hello1
252 hello2
253 EOF
254 ../tree-cmp hello1 out.dir/hello1
255 ../tree-cmp hello2 out.dir/hello2
256 [ ! -e out.dir/otherfile ]
257
258 msg "Testing path list extract (w/ wildcard)"
259 cat > pathlist << EOF
260 hello*
261 EOF
262 rm -rf out.dir
263 wimextract test.wim 1 @pathlist --dest-dir=out.dir
264 ../tree-cmp hello1 out.dir/hello1
265 ../tree-cmp hello2 out.dir/hello2
266 [ ! -e out.dir/otherfile ]
267
268 cat > pathlist << EOF
269 hello*
270 EOF
271 rm -rf out.dir
272 msg "Testing path list extract (no wildcard, no match; error expected)"
273 ! wimextract test.wim 1 @pathlist --dest-dir=out.dir --no-wildcards
274
275 cat > pathlist << EOF
276 foobar*
277 EOF
278 rm -rf out.dir
279 msg "Testing path list extract (wildcard, no match; error expected)"
280 ! wimextract test.wim 1 @pathlist --dest-dir=out.dir
281 msg "Testing path list extract (wildcard, no match, nullglob; no error expected)"
282 wimextract test.wim 1 @pathlist --dest-dir=out.dir --nullglob
283
284 msg "Testing path list extract (w/ wildcard)"
285 cat > pathlist << EOF
286 *
287 EOF
288 rm -rf out.dir
289 wimextract test.wim 1 @pathlist --dest-dir=out.dir
290 ../tree-cmp hello1 out.dir/hello1
291 ../tree-cmp hello2 out.dir/hello2
292 ../tree-cmp otherfile out.dir/otherfile
293
294 msg "Testing path list extract (subdir files)"
295 prepare_empty_wim
296 wimupdate test.wim 1 << EOF
297         add hello1 /topdir/subdir1/hello1
298         add hello2 /topdir/subdir2/hello2
299         add hello1 /topdir/hello1
300 EOF
301 cat > pathlist << EOF
302 /topdir/subdir?/hello*
303 EOF
304 rm -rf out.dir
305 wimextract test.wim 1 @pathlist --dest-dir=out.dir
306 ../tree-cmp hello1 out.dir/topdir/subdir1/hello1
307 ../tree-cmp hello2 out.dir/topdir/subdir2/hello2
308 [ ! -e out.dir/topdir/hello1 ]
309
310 msg "Testing case insensitivity"
311 prepare_empty_wim
312 wimupdate test.wim 1 << EOF
313         add hello1 /HELLO1
314 EOF
315 cat > pathlist << EOF
316 hello1
317 EOF
318 rm -rf out.dir
319 ! WIMLIB_IMAGEX_IGNORE_CASE=0 wimextract test.wim 1 @pathlist --dest-dir=out.dir
320 ! WIMLIB_IMAGEX_IGNORE_CASE=0 wimextract test.wim 1 @pathlist --dest-dir=out.dir --no-wildcards
321 WIMLIB_IMAGEX_IGNORE_CASE=1 wimextract test.wim 1 @pathlist --dest-dir=out.dir
322 WIMLIB_IMAGEX_IGNORE_CASE=1 wimextract test.wim 1 @pathlist --dest-dir=out.dir --no-wildcards
323 ../tree-cmp hello1 out.dir/HELLO1
324 [ ! -e out.dir/topdir/hello1 ]
325
326
327 echo "**********************************************************"
328 echo "          wimupdate/extract tests passed              "
329 echo "**********************************************************"
330 trap EXIT
331
332 cd ..
333 default_cleanup