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 "empty reparse point"
\r
212 %SET_REPARSE_POINT% file 0
\r
214 if %errorlevel% neq 0 goto :fail
\r
216 call :msg "empty reparse point with unnamed data stream"
\r
218 %SET_REPARSE_POINT% file 0
\r
220 if %errorlevel% neq 0 goto :fail
\r
222 call :msg "empty reparse point with unnamed data stream and named data streams"
\r
224 echo hello > file:ads1
\r
225 type nul > file:ads2
\r
226 %SET_REPARSE_POINT% file 0
\r
228 if %errorlevel% neq 0 goto :fail
\r
230 call :msg "maximum length reparse point"
\r
232 %SET_REPARSE_POINT% file 16376
\r
234 if %errorlevel% neq 0 goto :fail
\r
236 call :msg "directory reparse point that is neither a symlink nor a junction"
\r
238 %SET_REPARSE_POINT% subdir
\r
240 if %errorlevel% neq 0 goto :fail
\r
242 call :msg "directory reparse point with named data streams"
\r
246 %SET_REPARSE_POINT% subdir
\r
248 if %errorlevel% neq 0 goto :fail
\r
250 call :msg "compressed file"
\r
252 compact /C test > nul
\r
254 if %errorlevel% neq 0 goto :fail
\r
256 call :msg "compressed directory"
\r
258 compact /C subdir > nul
\r
260 if %errorlevel% neq 0 goto :fail
\r
262 call :msg "compressed directory with files in it"
\r
264 compact /C subdir > nul
\r
265 echo 1 > subdir\file1
\r
266 echo 2 > subdir\file2
\r
267 echo 1 > subdir\file1
\r
268 md subdir\subsubdir
\r
269 mklink /h subdir\hardlink subdir\file1 > nul
\r
270 mklink /j subdir\j subdir\subsubdir > nul
\r
272 if %errorlevel% neq 0 goto :fail
\r
274 call :msg "compressed directory with some uncompressed files in it"
\r
276 compact /C subdir > nul
\r
279 compact /U subdir\1 > nul
\r
281 if %errorlevel% neq 0 goto :fail
\r
283 call :msg "file with alternate data stream"
\r
287 if %errorlevel% neq 0 goto :fail
\r
289 call :msg "file with multiple alternate data streams"
\r
293 echo aaa > file:aaa
\r
294 echo aaaa > file:aaaa
\r
296 if %errorlevel% neq 0 goto :fail
\r
298 call :msg "file with multiple alternate data streams, with hard link"
\r
302 echo aaa > file:aaa
\r
303 echo aaaa > file:aaaa
\r
304 mklink /h link file > nul
\r
306 if %errorlevel% neq 0 goto :fail
\r
308 call :msg "files with multiple alternate data streams, some identical, with hard link"
\r
312 echo 1 > file:1again
\r
313 echo aaa > file:aaa
\r
315 mklink /h link file > nul
\r
316 echo aaa > file2:aaa
\r
318 if %errorlevel% neq 0 goto :fail
\r
320 call :msg "file with empty alternate data stream"
\r
322 type nul > file:ads
\r
324 if %errorlevel% neq 0 goto :fail
\r
326 call :msg "directory with empty alternate data stream"
\r
328 type nul > subdir:ads
\r
330 if %errorlevel% neq 0 goto :fail
\r
332 call :msg "root directory with alternate data stream"
\r
333 echo 1 > ..\in.dir:ads
\r
335 if %errorlevel% neq 0 goto :fail
\r
337 call :msg "root directory with empty alternate data stream"
\r
338 type nul > ..\in.dir:ads
\r
340 if %errorlevel% neq 0 goto :fail
\r
342 call :msg "subdirectory with alternate data streams"
\r
346 echo 2 > subdir:2again
\r
348 if %errorlevel% neq 0 goto :fail
\r
350 call :msg "subdirectories and files with alternate data streams"
\r
353 echo hello > subdir:hello
\r
354 echo hello > subdir:helloagain
\r
355 echo hello > helloagain
\r
356 mklink /h hellolink hello > nul
\r
357 echo 1 > helloagain:1
\r
358 echo 8 > helloagain:8
\r
360 type nul > helloagain:dummy
\r
362 if %errorlevel% neq 0 goto :fail
\r
364 call :msg "symbolic link and hard link, to file with alternate data streams"
\r
366 echo test > .\1:test
\r
367 mklink symlink 1 > nul
\r
368 mklink /h hardlink 1 > nul
\r
370 if %errorlevel% neq 0 goto :fail
\r
372 call :msg "compressed file with alternate data streams"
\r
378 if %errorlevel% neq 0 goto :fail
\r
380 call :msg "hidden file"
\r
384 if %errorlevel% neq 0 goto :fail
\r
386 call :msg "hidden system file"
\r
390 if %errorlevel% neq 0 goto :fail
\r
392 call :msg "hidden, readonly, system file"
\r
394 attrib +h +r +s file
\r
396 if %errorlevel% neq 0 goto :fail
\r
398 call :msg "hidden directory"
\r
402 if %errorlevel% neq 0 goto :fail
\r
404 call :msg "hidden system directory"
\r
406 attrib +h +s subdir
\r
408 if %errorlevel% neq 0 goto :fail
\r
410 call :msg "hidden, readonly, system directory"
\r
412 attrib +h +r +s subdir
\r
414 if %errorlevel% neq 0 goto :fail
\r
416 call :msg "readonly directory with named data stream"
\r
418 echo foo > subdir:ads
\r
421 if %errorlevel% neq 0 goto :fail
\r
423 call :msg "encrypted file"
\r
424 echo "hello" > encrypted
\r
425 cipher /e encrypted > nul
\r
427 if %errorlevel% neq 0 goto :fail
\r
429 call :msg "identical encrypted files"
\r
430 echo "hello" > encrypted1
\r
431 echo "hello" > encrypted2
\r
432 cipher /e encrypted1 > nul
\r
433 cipher /e encrypted2 > nul
\r
435 if %errorlevel% neq 0 goto :fail
\r
437 call :msg "encrypted directory"
\r
439 cipher /e subdir > nul
\r
441 if %errorlevel% neq 0 goto :fail
\r
443 call :msg "encrypted directory with encrypted file in it"
\r
446 cipher /e subdir > nul
\r
447 cipher /e subdir\1 > nul
\r
449 if %errorlevel% neq 0 goto :fail
\r
451 call :msg "encrypted directory with unencrypted file in it"
\r
454 cipher /e subdir > nul
\r
455 cipher /d subdir\1 > nul
\r
457 if %errorlevel% neq 0 goto :fail
\r
459 call :msg "encrypted root directory"
\r
461 cipher /e in.dir > nul
\r
463 echo "hello" > encrypted
\r
465 if %errorlevel% neq 0 goto :fail
\r
467 call :msg "unencrypted file in encrypted directory in compressed directory"
\r
471 cipher /e 1\2 > nul
\r
472 echo hello > 1\2\file
\r
473 cipher /d 1\2\file > nul
\r
475 if %errorlevel% neq 0 goto :fail
\r
477 call :msg "encrypted directory with alternate data streams"
\r
479 cipher /e subdir > nul
\r
480 echo ads1 > subdir:ads1
\r
481 echo ads2 > subdir:ads2
\r
483 if %errorlevel% neq 0 goto :fail
\r
485 call :msg "hardlinked, encrypted file with alternate data streams"
\r
487 echo hello > file:ads
\r
488 cipher /e file > nul
\r
489 mklink /h link file > nul
\r
491 if %errorlevel% neq 0 goto :fail
\r
495 echo Testing rpfix junction
\r
497 echo 1 > subdir\file
\r
498 mklink /j junction subdir > nul
\r
500 %WIMLIB_IMAGEX% capture in.dir test.wim > nul
\r
502 %WIMLIB_IMAGEX% apply test.wim out.dir > nul
\r
504 type out.dir\junction\file > tmp2
\r
506 if %errorlevel% neq 0 goto :fail
\r
512 echo Testing rpfix relative
\r
514 mklink relink file > nul
\r
516 %WIMLIB_IMAGEX% capture in.dir test.wim > nul
\r
517 %WIMLIB_IMAGEX% apply test.wim out.dir > nul
\r
518 type out.dir\relink > out.dir\tmp
\r
519 if %errorlevel% neq 0 goto :fail
\r
520 fc in.dir\file out.dir\tmp > nul
\r
521 if %errorlevel% neq 0 goto :fail
\r
522 rd /s /q in.dir out.dir
\r
537 %WIMLIB_IMAGEX% capture in.dir test.wim --norpfix > NUL
\r
538 if %errorlevel% neq 0 goto :fail
\r
539 %WIMLIB_IMAGEX% apply test.wim out.dir > NUL
\r
540 if %errorlevel% neq 0 goto :fail
\r
541 %WIN32_TREE_CMP% in.dir out.dir
\r
542 if %errorlevel% neq 0 goto :fail
\r
544 REM apply a second time so we test the case where the files already exist
\r
545 %WIMLIB_IMAGEX% apply test.wim out.dir > NUL
\r
546 if %errorlevel% neq 0 goto :fail
\r
547 %WIN32_TREE_CMP% in.dir out.dir
\r
548 if %errorlevel% neq 0 goto :fail
\r
550 REM Fun fact: Microsoft's WIMGAPI has bugs that make it fail some of our tests.
\r
551 REM Even the Windows 8.1 version has incorrect behavior with empty files with
\r
552 REM multiple links, or files with named data streams and multiple links.
\r
555 REM dism /capture-image /capturedir:in.dir /imagefile:test.wim /name:"test" /norpfix > nul
\r
556 REM if %errorlevel% neq 0 goto :fail
\r
557 dism /apply-image /imagefile:test.wim /index:1 /applydir:out.dir > nul
\r
558 if %errorlevel% neq 0 goto :fail
\r
559 %WIN32_TREE_CMP% in.dir out.dir
\r
561 rd /S /Q in.dir out.dir
\r
567 echo Testing capture and apply of %~1
\r
571 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\r
572 echo TEST FAILED!!!!!!!
\r
573 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\r
574 exit /b %errorlevel%
\r