4 REM win32-test-imagex-capture_and_apply.bat
\r
6 REM Run some tests on the Windows version of wimlib-imagex.
\r
8 REM This must be run on Windows Vista or later in a clean directory, with
\r
9 REM Administrator privileges. wimlib-imagex and win32-tree-cmp must be
\r
10 REM executable using the paths set below.
\r
12 setlocal EnableDelayedExpansion
\r
13 set WIN32_TREE_CMP=win32-tree-cmp
\r
14 set WIMLIB_IMAGEX=wimlib-imagex
\r
16 if exist in.dir rd /S /Q in.dir
\r
17 if exist out.dir rd /S /Q out.dir
\r
25 call :msg "empty directory"
\r
27 if %errorlevel% neq 0 exit /b %errorlevel%
\r
29 call :msg "single file"
\r
32 if %errorlevel% neq 0 exit /b %errorlevel%
\r
34 call :msg "different files"
\r
36 echo 2 > anotherfile
\r
38 if %errorlevel% neq 0 exit /b %errorlevel%
\r
40 call :msg "identical files"
\r
42 echo 1 > identicalfile
\r
44 if %errorlevel% neq 0 exit /b %errorlevel%
\r
46 call :msg "hard linked file"
\r
48 mklink /h link file > nul
\r
50 if %errorlevel% neq 0 exit /b %errorlevel%
\r
52 call :msg "hard linked file, with other identical files"
\r
54 mklink /h link file > nul
\r
55 echo 1 > identicalfile
\r
57 if %errorlevel% neq 0 exit /b %errorlevel%
\r
59 call :msg "empty file"
\r
60 type nul > emptyfile
\r
62 if %errorlevel% neq 0 exit /b %errorlevel%
\r
64 call :msg "various hard linked, identical, different, and empty files"
\r
67 mklink /h link1 file > nul
\r
68 mklink /h link2 file > nul
\r
69 type nul > emptyfile
\r
70 type nul > emptyfile2
\r
71 mklink /h emptyfilelink emptyfile > nul
\r
72 echo 5 > identicalfile
\r
74 mklink /h 1filelink 1file > nul
\r
76 if %errorlevel% neq 0 exit /b %errorlevel%
\r
78 call :msg "multiple subdirectories, some empty, some not"
\r
84 mklink /h link subdir1\1 > nul
\r
85 md subdir2\subdir2subdir
\r
86 type nul > subdir2\emptyfile
\r
88 if %errorlevel% neq 0 exit /b %errorlevel%
\r
90 call :msg "file with custom security descriptor"
\r
92 icacls file /deny Administrator:F > nul
\r
94 if %errorlevel% neq 0 exit /b %errorlevel%
\r
96 call :msg "directory with custom security descriptor (inheritence enabled)"
\r
98 icacls subdir /inheritance:e > nul
\r
100 if %errorlevel% neq 0 exit /b %errorlevel%
\r
102 call :msg "directory with custom security descriptor (inheritence disabled)"
\r
104 icacls subdir /inheritance:d > nul
\r
106 if %errorlevel% neq 0 exit /b %errorlevel%
\r
108 REM win32-tree-cmp can't handle this case.
\r
110 REM call :msg "file with custom security descriptor (all inherited ACEs removed)"
\r
111 REM echo hello > file
\r
112 REM icacls file /inheritance:r > nul
\r
114 REM if %errorlevel% neq 0 exit /b %errorlevel%
\r
116 call :msg "file with custom integrity level"
\r
118 icacls file /setintegritylevel H > nul
\r
120 if %errorlevel% neq 0 exit /b %errorlevel%
\r
122 call :msg "relative symlink"
\r
123 mklink relink dest > nul
\r
125 if %errorlevel% neq 0 exit /b %errorlevel%
\r
127 call :msg "absolute symlink, with drive letter"
\r
128 mklink abslink C:\absolute\target > nul
\r
130 if %errorlevel% neq 0 exit /b %errorlevel%
\r
132 call :msg "absolute symlink, without drive letter"
\r
133 mklink abslink \absolute\target > nul
\r
135 if %errorlevel% neq 0 exit /b %errorlevel%
\r
137 call :msg "relative symlink, with file target"
\r
139 mklink relink 1 > nul
\r
141 if %errorlevel% neq 0 exit /b %errorlevel%
\r
143 call :msg "relative symlink, with directory target"
\r
145 mklink reldlink subdir > nul
\r
147 if %errorlevel% neq 0 exit /b %errorlevel%
\r
149 call :msg "junction"
\r
151 mklink /j junction subdir > nul
\r
153 if %errorlevel% neq 0 exit /b %errorlevel%
\r
155 call :msg "symlinks, junctions, files, subdirectories, etc."
\r
157 mklink relink 1 > nul
\r
158 mklink rellinklink relink > nul
\r
159 mklink /j junction . > nul
\r
161 mklink /h subdir\hardlink 1 > nul
\r
162 echo "hello world!!!!" > hello
\r
163 mklink subdir\hello hello > nul
\r
164 mklink abslink C:\Users > nul
\r
166 type nul > emptyfile
\r
167 type nul > subdir2\emptyfile
\r
171 echo "hello world!!!!" > subdir2\otherfile
\r
173 if %errorlevel% neq 0 exit /b %errorlevel%
\r
175 call :msg "compressed file"
\r
177 compact /C test > nul
\r
179 if %errorlevel% neq 0 exit /b %errorlevel%
\r
181 call :msg "compressed directory"
\r
183 compact /C subdir > nul
\r
185 if %errorlevel% neq 0 exit /b %errorlevel%
\r
187 call :msg "compressed directory with files in it"
\r
189 compact /C subdir > nul
\r
190 echo 1 > subdir\file1
\r
191 echo 2 > subdir\file2
\r
192 echo 1 > subdir\file1
\r
193 md subdir\subsubdir
\r
194 mklink /h subdir\hardlink subdir\file1 > nul
\r
195 mklink /j subdir\j subdir\subsubdir > nul
\r
197 if %errorlevel% neq 0 exit /b %errorlevel%
\r
199 call :msg "compressed directory with some uncompressed files in it"
\r
201 compact /C subdir > nul
\r
204 compact /U subdir\1 > nul
\r
206 if %errorlevel% neq 0 exit /b %errorlevel%
\r
208 call :msg "file with alternate data stream"
\r
212 if %errorlevel% neq 0 exit /b %errorlevel%
\r
214 call :msg "file with multiple alternate data streams"
\r
218 echo aaa > file:aaa
\r
219 echo aaaa > file:aaaa
\r
221 if %errorlevel% neq 0 exit /b %errorlevel%
\r
223 call :msg "file with multiple alternate data streams, with hard link"
\r
227 echo aaa > file:aaa
\r
228 echo aaaa > file:aaaa
\r
229 mklink /h link file > nul
\r
231 if %errorlevel% neq 0 exit /b %errorlevel%
\r
233 call :msg "files with multiple alternate data streams, some identical, with hard link"
\r
237 echo 1 > file:1again
\r
238 echo aaa > file:aaa
\r
240 mklink /h link file > nul
\r
241 echo aaa > file2:aaa
\r
243 if %errorlevel% neq 0 exit /b %errorlevel%
\r
245 call :msg "file with empty alternate data stream"
\r
247 type nul > file:ads
\r
249 if %errorlevel% neq 0 exit /b %errorlevel%
\r
251 call :msg "directory with empty alternate data stream"
\r
253 type nul > subdir:ads
\r
255 if %errorlevel% neq 0 exit /b %errorlevel%
\r
257 call :msg "root directory with alternate data stream"
\r
258 echo 1 > ..\in.dir:ads
\r
260 if %errorlevel% neq 0 exit /b %errorlevel%
\r
262 call :msg "subdirectory with alternate data streams"
\r
266 echo 2 > subdir:2again
\r
268 if %errorlevel% neq 0 exit /b %errorlevel%
\r
270 call :msg "subdirectories and files with alternate data streams"
\r
273 echo hello > subdir:hello
\r
274 echo hello > subdir:helloagain
\r
275 echo hello > helloagain
\r
276 mklink /h hellolink hello > nul
\r
277 echo 1 > helloagain:1
\r
278 echo 8 > helloagain:8
\r
280 type nul > helloagain:dummy
\r
282 if %errorlevel% neq 0 exit /b %errorlevel%
\r
284 call :msg "symbolic link and hard link, to file with alternate data streams"
\r
286 echo test > .\1:test
\r
287 mklink symlink 1 > nul
\r
288 mklink /h hardlink 1 > nul
\r
290 if %errorlevel% neq 0 exit /b %errorlevel%
\r
292 call :msg "compressed file with alternate data streams"
\r
298 if %errorlevel% neq 0 exit /b %errorlevel%
\r
300 call :msg "hidden file"
\r
304 if %errorlevel% neq 0 exit /b %errorlevel%
\r
306 call :msg "hidden system file"
\r
310 if %errorlevel% neq 0 exit /b %errorlevel%
\r
312 call :msg "hidden, readonly, system file"
\r
314 attrib +h +r +s file
\r
316 if %errorlevel% neq 0 exit /b %errorlevel%
\r
318 call :msg "hidden directory"
\r
322 if %errorlevel% neq 0 exit /b %errorlevel%
\r
324 call :msg "hidden system directory"
\r
326 attrib +h +s subdir
\r
328 if %errorlevel% neq 0 exit /b %errorlevel%
\r
330 call :msg "hidden, readonly, system directory"
\r
332 attrib +h +r +s subdir
\r
334 if %errorlevel% neq 0 exit /b %errorlevel%
\r
336 call :msg "encrypted file"
\r
337 echo "hello" > encrypted
\r
338 cipher /e encrypted > nul
\r
340 if %errorlevel% neq 0 exit /b %errorlevel%
\r
342 call :msg "identical encrypted files"
\r
343 echo "hello" > encrypted1
\r
344 echo "hello" > encrypted2
\r
345 cipher /e encrypted1 > nul
\r
346 cipher /e encrypted2 > nul
\r
348 if %errorlevel% neq 0 exit /b %errorlevel%
\r
350 call :msg "encrypted directory"
\r
352 cipher /e subdir > nul
\r
354 if %errorlevel% neq 0 exit /b %errorlevel%
\r
356 call :msg "encrypted directory with encrypted file in it"
\r
359 cipher /e subdir > nul
\r
360 cipher /e subdir\1 > nul
\r
362 if %errorlevel% neq 0 exit /b %errorlevel%
\r
364 call :msg "encrypted directory with unencrypted file in it"
\r
367 cipher /e subdir > nul
\r
368 cipher /d subdir\1 > nul
\r
370 if %errorlevel% neq 0 exit /b %errorlevel%
\r
372 call :msg "encrypted root directory"
\r
374 cipher /e in.dir > nul
\r
376 echo "hello" > encrypted
\r
378 if %errorlevel% neq 0 exit /b %errorlevel%
\r
380 call :msg "unencrypted file in encrypted directory in compressed directory"
\r
384 cipher /e 1\2 > nul
\r
385 echo hello > 1\2\file
\r
386 cipher /d 1\2\file > nul
\r
388 if %errorlevel% neq 0 exit /b %errorlevel%
\r
390 call :msg "hardlinked, encrypted file with alternate data streams"
\r
392 echo hello > file:ads
\r
393 cipher /e file > nul
\r
394 mklink /h link file > nul
\r
396 if %errorlevel% neq 0 exit /b %errorlevel%
\r
400 echo Testing rpfix junction
\r
402 echo 1 > subdir\file
\r
403 mklink /j junction subdir > nul
\r
405 %WIMLIB_IMAGEX% capture in.dir test.wim > nul
\r
407 %WIMLIB_IMAGEX% apply test.wim out.dir > nul
\r
409 type out.dir\junction\file > tmp2
\r
411 if %errorlevel% neq 0 exit /b %errorlevel%
\r
417 echo Testing rpfix relative
\r
419 mklink relink file > nul
\r
421 %WIMLIB_IMAGEX% capture in.dir test.wim > nul
\r
422 %WIMLIB_IMAGEX% apply test.wim out.dir > nul
\r
423 fc in.dir\file out.dir\relink > nul
\r
424 if %errorlevel% neq 0 exit /b %errorlevel%
\r
425 rd /s /q in.dir out.dir
\r
440 %WIMLIB_IMAGEX% capture in.dir test.wim --norpfix > NUL
\r
441 if %errorlevel% neq 0 exit /b %errorlevel%
\r
442 %WIMLIB_IMAGEX% apply test.wim out.dir > NUL
\r
443 if %errorlevel% neq 0 exit /b %errorlevel%
\r
444 %WIN32_TREE_CMP% in.dir out.dir
\r
445 if %errorlevel% neq 0 (
\r
446 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\r
447 echo TEST FAILED!!!!!!!
\r
448 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\r
449 exit /b %errorlevel%
\r
452 REM Fun fact: There are bugs in Microsoft's imagex.exe that make it fail some
\r
455 REM rd /S /Q out.dir
\r
457 REM imagex /capture in.dir test.wim "test" /norpfix > nul
\r
458 REM if %errorlevel% neq 0 exit /b %errorlevel%
\r
459 REM imagex /apply test.wim 1 out.dir > nul
\r
460 REM if %errorlevel% neq 0 exit /b %errorlevel%
\r
461 REM %WIN32_TREE_CMP% in.dir out.dir
\r
462 REM if %errorlevel% neq 0 (
\r
463 REM echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\r
464 REM echo TEST FAILED!!!!!!! ^(imagex^)
\r
465 REM echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\r
466 REM exit /b %errorlevel%
\r
469 rd /S /Q in.dir out.dir
\r
475 echo Testing capture and apply of %~1
\r