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 WIMLIB_IMAGEX=wimlib-imagex
\r
14 set WIN32_TREE_CMP=win32-tree-cmp
\r
15 set SET_REPARSE_POINT=set_reparse_point
\r
17 if exist in.dir rd /S /Q in.dir
\r
18 if exist out.dir rd /S /Q out.dir
\r
26 call :msg "empty directory"
\r
28 if %errorlevel% neq 0 goto :fail
\r
30 call :msg "single file"
\r
33 if %errorlevel% neq 0 goto :fail
\r
35 call :msg "different files"
\r
37 echo 2 > anotherfile
\r
39 if %errorlevel% neq 0 goto :fail
\r
41 call :msg "identical files"
\r
43 echo 1 > identicalfile
\r
45 if %errorlevel% neq 0 goto :fail
\r
47 call :msg "hard linked file"
\r
49 mklink /h link file > nul
\r
51 if %errorlevel% neq 0 goto :fail
\r
53 call :msg "hard linked file, with other identical files"
\r
55 mklink /h link file > nul
\r
56 echo 1 > identicalfile
\r
58 if %errorlevel% neq 0 goto :fail
\r
60 call :msg "empty file"
\r
61 type nul > emptyfile
\r
63 if %errorlevel% neq 0 goto :fail
\r
65 call :msg "hard linked empty file"
\r
67 mklink /h link file > nul
\r
69 if %errorlevel% neq 0 goto :fail
\r
71 call :msg "various hard linked, identical, different, and empty files"
\r
74 mklink /h link1 file > nul
\r
75 mklink /h link2 file > nul
\r
76 type nul > emptyfile
\r
77 type nul > emptyfile2
\r
78 mklink /h emptyfilelink emptyfile > nul
\r
79 echo 5 > identicalfile
\r
81 mklink /h 1filelink 1file > nul
\r
83 if %errorlevel% neq 0 goto :fail
\r
85 call :msg "multiple subdirectories, some empty, some not"
\r
91 mklink /h link subdir1\1 > nul
\r
92 md subdir2\subdir2subdir
\r
93 type nul > subdir2\emptyfile
\r
95 if %errorlevel% neq 0 goto :fail
\r
97 call :msg "file with custom security descriptor"
\r
99 icacls file /deny Administrator:F > nul
\r
101 if %errorlevel% neq 0 goto :fail
\r
103 call :msg "directory with custom security descriptor (inheritence enabled)"
\r
105 icacls subdir /inheritance:e > nul
\r
107 if %errorlevel% neq 0 goto :fail
\r
109 call :msg "directory with custom security descriptor (inheritence disabled)"
\r
111 icacls subdir /inheritance:d > nul
\r
113 if %errorlevel% neq 0 goto :fail
\r
115 REM win32-tree-cmp can't handle this case.
\r
117 REM call :msg "file with custom security descriptor (all inherited ACEs removed)"
\r
118 REM echo hello > file
\r
119 REM icacls file /inheritance:r > nul
\r
121 REM if %errorlevel% neq 0 goto :fail
\r
123 call :msg "file with custom integrity level"
\r
125 icacls file /setintegritylevel H > nul
\r
127 if %errorlevel% neq 0 goto :fail
\r
129 call :msg "relative symlink"
\r
130 mklink relink dest > nul
\r
132 if %errorlevel% neq 0 goto :fail
\r
134 call :msg "absolute symlink, with drive letter"
\r
135 mklink abslink C:\absolute\target > nul
\r
137 if %errorlevel% neq 0 goto :fail
\r
139 call :msg "absolute symlink, without drive letter"
\r
140 mklink abslink \absolute\target > nul
\r
142 if %errorlevel% neq 0 goto :fail
\r
144 call :msg "relative symlink, with file target"
\r
146 mklink relink 1 > nul
\r
148 if %errorlevel% neq 0 goto :fail
\r
150 call :msg "relative symlink, with directory target"
\r
152 mklink reldlink subdir > nul
\r
154 if %errorlevel% neq 0 goto :fail
\r
156 call :msg "junction"
\r
158 mklink /j junction subdir > nul
\r
160 if %errorlevel% neq 0 goto :fail
\r
162 call :msg "symlinks, junctions, files, subdirectories, etc."
\r
164 mklink relink 1 > nul
\r
165 mklink rellinklink relink > nul
\r
166 mklink /j junction . > nul
\r
168 mklink /h subdir\hardlink 1 > nul
\r
169 echo "hello world!!!!" > hello
\r
170 mklink subdir\hello hello > nul
\r
171 mklink abslink C:\Users > nul
\r
173 type nul > emptyfile
\r
174 type nul > subdir2\emptyfile
\r
178 echo "hello world!!!!" > subdir2\otherfile
\r
180 if %errorlevel% neq 0 goto :fail
\r
182 call :msg "reparse point that is neither a symlink nor a junction"
\r
184 %SET_REPARSE_POINT% file
\r
186 if %errorlevel% neq 0 goto :fail
\r
188 call :msg "reparse point with named data streams"
\r
192 %SET_REPARSE_POINT% file
\r
194 if %errorlevel% neq 0 goto :fail
\r
196 call :msg "reparse point with unnamed data stream"
\r
198 %SET_REPARSE_POINT% file
\r
200 if %errorlevel% neq 0 goto :fail
\r
202 call :msg "reparse point with unnamed data stream and named data streams"
\r
206 %SET_REPARSE_POINT% file
\r
208 if %errorlevel% neq 0 goto :fail
\r
210 call :msg "directory reparse point that is neither a symlink nor a junction"
\r
212 %SET_REPARSE_POINT% subdir
\r
214 if %errorlevel% neq 0 goto :fail
\r
216 call :msg "directory reparse point with named data streams"
\r
220 %SET_REPARSE_POINT% subdir
\r
222 if %errorlevel% neq 0 goto :fail
\r
224 call :msg "compressed file"
\r
226 compact /C test > nul
\r
228 if %errorlevel% neq 0 goto :fail
\r
230 call :msg "compressed directory"
\r
232 compact /C subdir > nul
\r
234 if %errorlevel% neq 0 goto :fail
\r
236 call :msg "compressed directory with files in it"
\r
238 compact /C subdir > nul
\r
239 echo 1 > subdir\file1
\r
240 echo 2 > subdir\file2
\r
241 echo 1 > subdir\file1
\r
242 md subdir\subsubdir
\r
243 mklink /h subdir\hardlink subdir\file1 > nul
\r
244 mklink /j subdir\j subdir\subsubdir > nul
\r
246 if %errorlevel% neq 0 goto :fail
\r
248 call :msg "compressed directory with some uncompressed files in it"
\r
250 compact /C subdir > nul
\r
253 compact /U subdir\1 > nul
\r
255 if %errorlevel% neq 0 goto :fail
\r
257 call :msg "file with alternate data stream"
\r
261 if %errorlevel% neq 0 goto :fail
\r
263 call :msg "file with multiple alternate data streams"
\r
267 echo aaa > file:aaa
\r
268 echo aaaa > file:aaaa
\r
270 if %errorlevel% neq 0 goto :fail
\r
272 call :msg "file with multiple alternate data streams, with hard link"
\r
276 echo aaa > file:aaa
\r
277 echo aaaa > file:aaaa
\r
278 mklink /h link file > nul
\r
280 if %errorlevel% neq 0 goto :fail
\r
282 call :msg "files with multiple alternate data streams, some identical, with hard link"
\r
286 echo 1 > file:1again
\r
287 echo aaa > file:aaa
\r
289 mklink /h link file > nul
\r
290 echo aaa > file2:aaa
\r
292 if %errorlevel% neq 0 goto :fail
\r
294 call :msg "file with empty alternate data stream"
\r
296 type nul > file:ads
\r
298 if %errorlevel% neq 0 goto :fail
\r
300 call :msg "directory with empty alternate data stream"
\r
302 type nul > subdir:ads
\r
304 if %errorlevel% neq 0 goto :fail
\r
306 call :msg "root directory with alternate data stream"
\r
307 echo 1 > ..\in.dir:ads
\r
309 if %errorlevel% neq 0 goto :fail
\r
311 call :msg "root directory with empty alternate data stream"
\r
312 type nul > ..\in.dir:ads
\r
314 if %errorlevel% neq 0 goto :fail
\r
316 call :msg "subdirectory with alternate data streams"
\r
320 echo 2 > subdir:2again
\r
322 if %errorlevel% neq 0 goto :fail
\r
324 call :msg "subdirectories and files with alternate data streams"
\r
327 echo hello > subdir:hello
\r
328 echo hello > subdir:helloagain
\r
329 echo hello > helloagain
\r
330 mklink /h hellolink hello > nul
\r
331 echo 1 > helloagain:1
\r
332 echo 8 > helloagain:8
\r
334 type nul > helloagain:dummy
\r
336 if %errorlevel% neq 0 goto :fail
\r
338 call :msg "symbolic link and hard link, to file with alternate data streams"
\r
340 echo test > .\1:test
\r
341 mklink symlink 1 > nul
\r
342 mklink /h hardlink 1 > nul
\r
344 if %errorlevel% neq 0 goto :fail
\r
346 call :msg "compressed file with alternate data streams"
\r
352 if %errorlevel% neq 0 goto :fail
\r
354 call :msg "hidden file"
\r
358 if %errorlevel% neq 0 goto :fail
\r
360 call :msg "hidden system file"
\r
364 if %errorlevel% neq 0 goto :fail
\r
366 call :msg "hidden, readonly, system file"
\r
368 attrib +h +r +s file
\r
370 if %errorlevel% neq 0 goto :fail
\r
372 call :msg "hidden directory"
\r
376 if %errorlevel% neq 0 goto :fail
\r
378 call :msg "hidden system directory"
\r
380 attrib +h +s subdir
\r
382 if %errorlevel% neq 0 goto :fail
\r
384 call :msg "hidden, readonly, system directory"
\r
386 attrib +h +r +s subdir
\r
388 if %errorlevel% neq 0 goto :fail
\r
390 call :msg "readonly directory with named data stream"
\r
392 echo foo > subdir:ads
\r
395 if %errorlevel% neq 0 goto :fail
\r
397 call :msg "encrypted file"
\r
398 echo "hello" > encrypted
\r
399 cipher /e encrypted > nul
\r
401 if %errorlevel% neq 0 goto :fail
\r
403 call :msg "identical encrypted files"
\r
404 echo "hello" > encrypted1
\r
405 echo "hello" > encrypted2
\r
406 cipher /e encrypted1 > nul
\r
407 cipher /e encrypted2 > nul
\r
409 if %errorlevel% neq 0 goto :fail
\r
411 call :msg "encrypted directory"
\r
413 cipher /e subdir > nul
\r
415 if %errorlevel% neq 0 goto :fail
\r
417 call :msg "encrypted directory with encrypted file in it"
\r
420 cipher /e subdir > nul
\r
421 cipher /e subdir\1 > nul
\r
423 if %errorlevel% neq 0 goto :fail
\r
425 call :msg "encrypted directory with unencrypted file in it"
\r
428 cipher /e subdir > nul
\r
429 cipher /d subdir\1 > nul
\r
431 if %errorlevel% neq 0 goto :fail
\r
433 call :msg "encrypted root directory"
\r
435 cipher /e in.dir > nul
\r
437 echo "hello" > encrypted
\r
439 if %errorlevel% neq 0 goto :fail
\r
441 call :msg "unencrypted file in encrypted directory in compressed directory"
\r
445 cipher /e 1\2 > nul
\r
446 echo hello > 1\2\file
\r
447 cipher /d 1\2\file > nul
\r
449 if %errorlevel% neq 0 goto :fail
\r
451 call :msg "encrypted directory with alternate data streams"
\r
453 cipher /e subdir > nul
\r
454 echo ads1 > subdir:ads1
\r
455 echo ads2 > subdir:ads2
\r
457 if %errorlevel% neq 0 goto :fail
\r
459 call :msg "hardlinked, encrypted file with alternate data streams"
\r
461 echo hello > file:ads
\r
462 cipher /e file > nul
\r
463 mklink /h link file > nul
\r
465 if %errorlevel% neq 0 goto :fail
\r
469 echo Testing rpfix junction
\r
471 echo 1 > subdir\file
\r
472 mklink /j junction subdir > nul
\r
474 %WIMLIB_IMAGEX% capture in.dir test.wim > nul
\r
476 %WIMLIB_IMAGEX% apply test.wim out.dir > nul
\r
478 type out.dir\junction\file > tmp2
\r
480 if %errorlevel% neq 0 goto :fail
\r
486 echo Testing rpfix relative
\r
488 mklink relink file > nul
\r
490 %WIMLIB_IMAGEX% capture in.dir test.wim > nul
\r
491 %WIMLIB_IMAGEX% apply test.wim out.dir > nul
\r
492 type out.dir\relink > out.dir\tmp
\r
493 if %errorlevel% neq 0 goto :fail
\r
494 fc in.dir\file out.dir\tmp > nul
\r
495 if %errorlevel% neq 0 goto :fail
\r
496 rd /s /q in.dir out.dir
\r
511 %WIMLIB_IMAGEX% capture in.dir test.wim --norpfix > NUL
\r
512 if %errorlevel% neq 0 goto :fail
\r
513 %WIMLIB_IMAGEX% apply test.wim out.dir > NUL
\r
514 if %errorlevel% neq 0 goto :fail
\r
515 %WIN32_TREE_CMP% in.dir out.dir
\r
516 if %errorlevel% neq 0 goto :fail
\r
518 REM apply a second time so we test the case where the files already exist
\r
519 %WIMLIB_IMAGEX% apply test.wim out.dir > NUL
\r
520 if %errorlevel% neq 0 goto :fail
\r
521 %WIN32_TREE_CMP% in.dir out.dir
\r
522 if %errorlevel% neq 0 goto :fail
\r
524 REM Fun fact: Microsoft's WIMGAPI has bugs that make it fail some of our tests.
\r
525 REM Even the Windows 8.1 version has incorrect behavior with empty files with
\r
526 REM multiple links, or files with named data streams and multiple links.
\r
529 REM dism /capture-image /capturedir:in.dir /imagefile:test.wim /name:"test" /norpfix > nul
\r
530 REM if %errorlevel% neq 0 goto :fail
\r
531 dism /apply-image /imagefile:test.wim /index:1 /applydir:out.dir > nul
\r
532 if %errorlevel% neq 0 goto :fail
\r
533 %WIN32_TREE_CMP% in.dir out.dir
\r
535 rd /S /Q in.dir out.dir
\r
541 echo Testing capture and apply of %~1
\r
545 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\r
546 echo TEST FAILED!!!!!!!
\r
547 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\r
548 exit /b %errorlevel%
\r