]> wimlib.net Git - wimlib/blob - tests/test-imagex-update_and_extract
202371b1027de6d14121b293997b16f2d4e1dddf
[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 adding, then renaming file in WIM image in one command"
124 wimupdate test.wim << EOF
125 add file /file
126 rename /file /newname
127 EOF
128 do_apply
129 ../tree-cmp file out.dir/newname
130 [ ! -e out.dir/file ]
131
132 msg "Testing adding additional file to WIM image"
133 prepare_empty_wim
134 wimupdate test.wim << EOF
135 add 1 /1
136 EOF
137 wimupdate test.wim << EOF
138 add file /file
139 EOF
140 do_apply
141 [ -e out.dir/1 ]
142 [ -e out.dir/file ]
143
144 msg "Testing extracting file from WIM image"
145 rm -rf out.dir
146 mkdir out.dir
147 wimextract test.wim 1 /file --dest-dir=out.dir
148 ../tree-cmp file out.dir/file
149 [ ! -e out.dir/1 ]
150
151 msg "Testing extracting file from WIM image to stdout"
152 rm -rf out.dir
153 mkdir out.dir
154 wimlib_imagex extract test.wim 1 /file --to-stdout > out.dir/file
155 cmp file out.dir/file
156 [ ! -e out.dir/1 ]
157
158 msg "Testing adding directories and files to WIM image"
159 rm -rf dir1
160 mkdir dir1
161 rm -rf dir2
162 mkdir dir2
163 echo 5 > dir1/5
164 echo 6 > dir2/6.1
165 echo 6 > dir2/6
166 echo 6 > dir2/6.2
167 ln -s 5 dir1/relink
168 mkdir dir1/subdir
169 ln dir1/5 dir1/5link
170 ln dir2/6 dir2/6link
171 prepare_empty_wim
172 wimupdate test.wim 1 << EOF
173 add dir1 /dir1
174 add dir2 /prefix/dir2
175 EOF
176 rm -rf out.dir
177 mkdir out.dir
178 wimextract test.wim 1 dir1 --dest-dir=out.dir
179 wimextract test.wim 1 prefix/dir2 --dest-dir=out.dir
180 ../tree-cmp dir1 out.dir/dir1
181 ../tree-cmp dir2 out.dir/dir2
182
183 msg "Testing adding files to WIM image"
184 rm -rf in.dir
185 mkdir in.dir
186 wimappend in.dir test.wim "2"
187 cp $srcdir/src/*.c in.dir
188 wimupdate test.wim 2 << EOF
189 add in.dir /
190 add file /file
191 EOF
192 cp -a file in.dir/file
193 rm -rf out.dir
194 wimapply test.wim 2 out.dir
195 touch -r in.dir out.dir
196 ../tree-cmp in.dir out.dir
197
198 msg "Testing adding file with space in it"
199 echo hello > "Some File"
200 prepare_empty_wim
201 wimupdate test.wim 1 << EOF
202         add     "Some File"     'Some Destination'
203 EOF
204 rm -rf out.dir
205 wimapply test.wim 1 out.dir
206 ../tree-cmp "Some File" out.dir/"Some Destination"
207
208 msg "Testing path list extract"
209 echo hello1 > hello1
210 echo hello2 > hello2
211 echo otherfile > otherfile
212 prepare_empty_wim
213 wimupdate test.wim 1 << EOF
214         add hello1 /hello1
215         add hello2 /hello2
216         add otherfile /otherfile
217 EOF
218 cat > pathlist << EOF
219 hello1
220 hello2
221 EOF
222 rm -rf out.dir
223 wimextract test.wim 1 @pathlist --dest-dir=out.dir
224 ../tree-cmp hello1 out.dir/hello1
225 ../tree-cmp hello2 out.dir/hello2
226 [ ! -e out.dir/otherfile ]
227
228 msg "Testing path list extract (w/ wildcard)"
229 cat > pathlist << EOF
230 hello*
231 EOF
232 rm -rf out.dir
233 wimextract test.wim 1 @pathlist --dest-dir=out.dir
234 ../tree-cmp hello1 out.dir/hello1
235 ../tree-cmp hello2 out.dir/hello2
236 [ ! -e out.dir/otherfile ]
237
238 cat > pathlist << EOF
239 hello*
240 EOF
241 rm -rf out.dir
242 msg "Testing path list extract (no wildcard, no match; error expected)"
243 ! wimextract test.wim 1 @pathlist --dest-dir=out.dir --no-wildcards
244
245 cat > pathlist << EOF
246 foobar*
247 EOF
248 rm -rf out.dir
249 msg "Testing path list extract (wildcard, no match; error expected)"
250 ! wimextract test.wim 1 @pathlist --dest-dir=out.dir
251 msg "Testing path list extract (wildcard, no match, nullglob; no error expected)"
252 wimextract test.wim 1 @pathlist --dest-dir=out.dir --nullglob
253
254 msg "Testing path list extract (w/ wildcard)"
255 cat > pathlist << EOF
256 *
257 EOF
258 rm -rf out.dir
259 wimextract test.wim 1 @pathlist --dest-dir=out.dir
260 ../tree-cmp hello1 out.dir/hello1
261 ../tree-cmp hello2 out.dir/hello2
262 ../tree-cmp otherfile out.dir/otherfile
263
264 msg "Testing path list extract (subdir files)"
265 prepare_empty_wim
266 wimupdate test.wim 1 << EOF
267         add hello1 /topdir/subdir1/hello1
268         add hello2 /topdir/subdir2/hello2
269         add hello1 /topdir/hello1
270 EOF
271 cat > pathlist << EOF
272 /topdir/subdir?/hello*
273 EOF
274 rm -rf out.dir
275 wimextract test.wim 1 @pathlist --dest-dir=out.dir
276 ../tree-cmp hello1 out.dir/topdir/subdir1/hello1
277 ../tree-cmp hello2 out.dir/topdir/subdir2/hello2
278 [ ! -e out.dir/topdir/hello1 ]
279
280 msg "Testing case insensitivity"
281 prepare_empty_wim
282 wimupdate test.wim 1 << EOF
283         add hello1 /HELLO1
284 EOF
285 cat > pathlist << EOF
286 hello1
287 EOF
288 rm -rf out.dir
289 ! WIMLIB_IMAGEX_IGNORE_CASE=0 wimextract test.wim 1 @pathlist --dest-dir=out.dir
290 ! WIMLIB_IMAGEX_IGNORE_CASE=0 wimextract test.wim 1 @pathlist --dest-dir=out.dir --no-wildcards
291 WIMLIB_IMAGEX_IGNORE_CASE=1 wimextract test.wim 1 @pathlist --dest-dir=out.dir
292 WIMLIB_IMAGEX_IGNORE_CASE=1 wimextract test.wim 1 @pathlist --dest-dir=out.dir --no-wildcards
293 ../tree-cmp hello1 out.dir/HELLO1
294 [ ! -e out.dir/topdir/hello1 ]
295
296
297 echo "**********************************************************"
298 echo "          wimupdate/extract tests passed              "
299 echo "**********************************************************"
300 trap EXIT
301
302 cd ..
303 default_cleanup