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 in a clean directory, with Administrator privileges.
\r
9 REM wimlib-imagex, win32-tree-cmp, and set_reparse_point must be executable
\r
10 REM 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
29 call :msg "single file"
\r
33 call :msg "different files"
\r
35 echo 2 > anotherfile
\r
38 call :msg "identical files"
\r
40 echo 1 > identicalfile
\r
43 call :msg "hard linked file"
\r
45 mklink /h link file > nul
\r
48 call :msg "hard linked file, with other identical files"
\r
50 mklink /h link file > nul
\r
51 echo 1 > identicalfile
\r
54 call :msg "empty file"
\r
55 type nul > emptyfile
\r
58 call :msg "hard linked empty file"
\r
60 mklink /h link file > nul
\r
63 call :msg "various hard linked, identical, different, and empty files"
\r
66 mklink /h link1 file > nul
\r
67 mklink /h link2 file > nul
\r
68 type nul > emptyfile
\r
69 type nul > emptyfile2
\r
70 mklink /h emptyfilelink emptyfile > nul
\r
71 echo 5 > identicalfile
\r
73 mklink /h 1filelink 1file > nul
\r
76 call :msg "multiple subdirectories, some empty, some not"
\r
82 mklink /h link subdir1\1 > nul
\r
83 md subdir2\subdir2subdir
\r
84 type nul > subdir2\emptyfile
\r
87 call :msg "file with custom security descriptor"
\r
89 icacls file /deny Administrator:F > nul
\r
92 call :msg "directory with custom security descriptor (inheritence enabled)"
\r
94 icacls subdir /inheritance:e > nul
\r
97 call :msg "directory with custom security descriptor (inheritence disabled)"
\r
99 icacls subdir /inheritance:d > nul
\r
102 REM win32-tree-cmp can't handle this case.
\r
104 REM call :msg "file with custom security descriptor (all inherited ACEs removed)"
\r
105 REM echo hello > file
\r
106 REM icacls file /inheritance:r > nul
\r
109 call :msg "file with custom integrity level"
\r
111 icacls file /setintegritylevel H > nul
\r
114 call :msg "relative symlink"
\r
115 mklink relink dest > nul
\r
118 call :msg "absolute symlink, with drive letter"
\r
119 mklink abslink C:\absolute\target > nul
\r
122 call :msg "absolute symlink, without drive letter"
\r
123 mklink abslink \absolute\target > nul
\r
126 call :msg "relative symlink, with file target"
\r
128 mklink relink 1 > nul
\r
131 call :msg "relative symlink, with directory target"
\r
133 mklink reldlink subdir > nul
\r
136 call :msg "junction"
\r
138 mklink /j junction subdir > nul
\r
141 call :msg "symlinks, junctions, files, subdirectories, etc."
\r
143 mklink relink 1 > nul
\r
144 mklink rellinklink relink > nul
\r
145 mklink /j junction . > nul
\r
147 mklink /h subdir\hardlink 1 > nul
\r
148 echo "hello world!!!!" > hello
\r
149 mklink subdir\hello hello > nul
\r
150 mklink abslink C:\Users > nul
\r
152 type nul > emptyfile
\r
153 type nul > subdir2\emptyfile
\r
157 echo "hello world!!!!" > subdir2\otherfile
\r
160 call :msg "reparse point that is neither a symlink nor a junction"
\r
162 %SET_REPARSE_POINT% file
\r
165 call :msg "reparse point with named data streams"
\r
169 %SET_REPARSE_POINT% file
\r
172 call :msg "reparse point with unnamed data stream"
\r
174 %SET_REPARSE_POINT% file
\r
177 call :msg "reparse point with unnamed data stream and named data streams"
\r
181 %SET_REPARSE_POINT% file
\r
184 call :msg "empty reparse point"
\r
186 %SET_REPARSE_POINT% file 0
\r
189 call :msg "empty reparse point with unnamed data stream"
\r
191 %SET_REPARSE_POINT% file 0
\r
194 call :msg "empty reparse point with unnamed data stream and named data streams"
\r
196 echo hello > file:ads1
\r
197 type nul > file:ads2
\r
198 %SET_REPARSE_POINT% file 0
\r
201 call :msg "maximum length reparse point"
\r
203 %SET_REPARSE_POINT% file 16376
\r
206 call :msg "directory reparse point that is neither a symlink nor a junction"
\r
208 %SET_REPARSE_POINT% subdir
\r
211 call :msg "directory reparse point with named data streams"
\r
215 %SET_REPARSE_POINT% subdir
\r
218 call :msg "compressed file"
\r
220 compact /C test > nul
\r
223 call :msg "compressed directory"
\r
225 compact /C subdir > nul
\r
228 call :msg "compressed directory with files in it"
\r
230 compact /C subdir > nul
\r
231 echo 1 > subdir\file1
\r
232 echo 2 > subdir\file2
\r
233 echo 1 > subdir\file1
\r
234 md subdir\subsubdir
\r
235 mklink /h subdir\hardlink subdir\file1 > nul
\r
236 mklink /j subdir\j subdir\subsubdir > nul
\r
239 call :msg "compressed directory with some uncompressed files in it"
\r
241 compact /C subdir > nul
\r
244 compact /U subdir\1 > nul
\r
247 call :msg "file with alternate data stream"
\r
252 call :msg "file with multiple alternate data streams"
\r
256 echo aaa > file:aaa
\r
257 echo aaaa > file:aaaa
\r
260 call :msg "file with multiple alternate data streams, with hard link"
\r
264 echo aaa > file:aaa
\r
265 echo aaaa > file:aaaa
\r
266 mklink /h link file > nul
\r
269 call :msg "files with multiple alternate data streams, some identical, with hard link"
\r
273 echo 1 > file:1again
\r
274 echo aaa > file:aaa
\r
276 mklink /h link file > nul
\r
277 echo aaa > file2:aaa
\r
280 call :msg "file with empty alternate data stream"
\r
282 type nul > file:ads
\r
285 call :msg "directory with empty alternate data stream"
\r
287 type nul > subdir:ads
\r
290 call :msg "root directory with alternate data stream"
\r
291 echo 1 > ..\in.dir:ads
\r
294 call :msg "root directory with empty alternate data stream"
\r
295 type nul > ..\in.dir:ads
\r
298 call :msg "subdirectory with alternate data streams"
\r
302 echo 2 > subdir:2again
\r
305 call :msg "subdirectories and files with alternate data streams"
\r
308 echo hello > subdir:hello
\r
309 echo hello > subdir:helloagain
\r
310 echo hello > helloagain
\r
311 mklink /h hellolink hello > nul
\r
312 echo 1 > helloagain:1
\r
313 echo 8 > helloagain:8
\r
315 type nul > helloagain:dummy
\r
318 call :msg "symbolic link and hard link, to file with alternate data streams"
\r
320 echo test > .\1:test
\r
321 mklink symlink 1 > nul
\r
322 mklink /h hardlink 1 > nul
\r
325 call :msg "compressed file with alternate data streams"
\r
332 call :msg "hidden file"
\r
337 call :msg "hidden system file"
\r
342 call :msg "hidden, readonly, system file"
\r
344 attrib +h +r +s file
\r
347 call :msg "hidden directory"
\r
352 call :msg "hidden system directory"
\r
354 attrib +h +s subdir
\r
357 call :msg "hidden, readonly, system directory"
\r
359 attrib +h +r +s subdir
\r
362 call :msg "readonly directory with named data stream"
\r
364 echo foo > subdir:ads
\r
368 call :msg "encrypted file"
\r
369 echo "hello" > encrypted
\r
370 cipher /e encrypted > nul
\r
373 call :msg "identical encrypted files"
\r
374 echo "hello" > encrypted1
\r
375 echo "hello" > encrypted2
\r
376 cipher /e encrypted1 > nul
\r
377 cipher /e encrypted2 > nul
\r
380 call :msg "encrypted directory"
\r
382 cipher /e subdir > nul
\r
385 call :msg "encrypted directory with encrypted file in it"
\r
388 cipher /e subdir > nul
\r
389 cipher /e subdir\1 > nul
\r
392 call :msg "encrypted directory with unencrypted file in it"
\r
395 cipher /e subdir > nul
\r
396 cipher /d subdir\1 > nul
\r
399 call :msg "encrypted root directory"
\r
401 cipher /e in.dir > nul
\r
403 echo "hello" > encrypted
\r
406 call :msg "unencrypted file in encrypted directory in compressed directory"
\r
410 cipher /e 1\2 > nul
\r
411 echo hello > 1\2\file
\r
412 cipher /d 1\2\file > nul
\r
415 call :msg "encrypted directory with alternate data streams"
\r
417 cipher /e subdir > nul
\r
418 echo ads1 > subdir:ads1
\r
419 echo ads2 > subdir:ads2
\r
422 call :msg "hardlinked, encrypted file with alternate data streams"
\r
424 echo hello > file:ads
\r
425 cipher /e file > nul
\r
426 mklink /h link file > nul
\r
429 REM Note: since object IDs must be unique per filesystem, we can't expect them
\r
430 REM to preserved using our testing scheme. Therefore, win32-tree-cmp doesn't
\r
431 REM compare them, and the below tests really just ensure the object ID code is
\r
432 REM run to some extent.
\r
434 call :msg "file with object ID"
\r
436 fsutil objectid create file > nul
\r
439 call :msg "directory with object ID"
\r
441 fsutil objectid set f67394c12b17608e1d050d181ba8ffd2 7df80cbdf620f4c82c79b9e6799147b6 97621aff72915ade05abb96b15dea1a3 e0bda4caa9e33cfd461c92c16be9713d subdir
\r
444 call :msg "sparse files"
\r
445 fsutil file createnew sparse 1000000 > nul
\r
446 fsutil sparse setflag sparse
\r
447 fsutil sparse setrange sparse 0 1000000
\r
449 fsutil file createnew mostly_sparse 1000000 > nul
\r
450 fsutil sparse setflag mostly_sparse
\r
451 fsutil sparse setrange mostly_sparse 0 1000000
\r
452 echo hello >> mostly_sparse
\r
453 type sparse >> mostly_sparse
\r
454 fsutil sparse setrange mostly_sparse 1000100 2000000
\r
457 call :msg "sparse and compressed files"
\r
458 fsutil file createnew sparse 1000000 > nul
\r
459 fsutil sparse setflag sparse
\r
460 fsutil sparse setrange sparse 0 1000000
\r
461 compact /c sparse > nul
\r
463 fsutil file createnew mostly_sparse 1000000 > nul
\r
464 fsutil sparse setflag mostly_sparse
\r
465 fsutil sparse setrange mostly_sparse 0 1000000
\r
466 echo hello >> mostly_sparse
\r
467 type sparse >> mostly_sparse
\r
468 fsutil sparse setrange mostly_sparse 1000100 2000000
\r
469 compact /c mostly_sparse > nul
\r
471 type nul > compressed_first
\r
472 compact /c compressed_first > nul
\r
473 type sparse >> compressed_first
\r
474 fsutil sparse setflag compressed_first
\r
475 fsutil sparse setrange compressed_first 0 500000
\r
480 echo Testing rpfix junction
\r
482 echo 1 > subdir\file
\r
483 mklink /j junction subdir > nul
\r
485 %WIMLIB_IMAGEX% capture in.dir test.wim > nul
\r
487 %WIMLIB_IMAGEX% apply test.wim out.dir > nul
\r
489 type out.dir\junction\file > tmp2
\r
491 if %errorlevel% neq 0 goto :fail
\r
497 echo Testing rpfix relative
\r
499 mklink relink file > nul
\r
501 %WIMLIB_IMAGEX% capture in.dir test.wim > nul
\r
502 %WIMLIB_IMAGEX% apply test.wim out.dir > nul
\r
503 type out.dir\relink > out.dir\tmp
\r
504 if %errorlevel% neq 0 goto :fail
\r
505 fc in.dir\file out.dir\tmp > nul
\r
506 if %errorlevel% neq 0 goto :fail
\r
507 rd /s /q in.dir out.dir
\r
522 %WIMLIB_IMAGEX% capture in.dir test.wim --norpfix > NUL
\r
523 if %errorlevel% neq 0 goto :fail
\r
524 %WIMLIB_IMAGEX% apply test.wim out.dir > NUL
\r
525 if %errorlevel% neq 0 goto :fail
\r
526 %WIN32_TREE_CMP% in.dir out.dir
\r
527 if %errorlevel% neq 0 goto :fail
\r
529 REM apply a second time so we test the case where the files already exist
\r
530 %WIMLIB_IMAGEX% apply test.wim out.dir > NUL
\r
531 if %errorlevel% neq 0 goto :fail
\r
532 %WIN32_TREE_CMP% in.dir out.dir
\r
533 if %errorlevel% neq 0 goto :fail
\r
535 REM Fun fact: Microsoft's WIMGAPI has bugs that make it fail some of our tests.
\r
536 REM Even the Windows 8.1 version has incorrect behavior with empty files with
\r
537 REM multiple links, or files with named data streams and multiple links.
\r
540 REM dism /capture-image /capturedir:in.dir /imagefile:test.wim /name:"test" /norpfix > nul
\r
541 REM if %errorlevel% neq 0 goto :fail
\r
542 dism /apply-image /imagefile:test.wim /index:1 /applydir:out.dir > nul
\r
543 if %errorlevel% neq 0 goto :fail
\r
544 %WIN32_TREE_CMP% in.dir out.dir
\r
546 rd /S /Q in.dir out.dir
\r
552 echo Testing capture and apply of %~1
\r
556 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\r
557 echo TEST FAILED!!!!!!!
\r
558 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\r