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