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 with Administrator privileges, in a directory containing
\r
9 REM the wimlib-imagex, win32-tree-cmp, and set_reparse_point programs.
\r
11 setlocal EnableDelayedExpansion
\r
12 set WIMLIB_IMAGEX=%cd%\wimlib-imagex
\r
13 set WIN32_TREE_CMP=%cd%\win32-tree-cmp
\r
14 set SET_REPARSE_POINT=%cd%\set_reparse_point
\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
28 call :msg "single file"
\r
32 call :msg "different files"
\r
34 echo 2 > anotherfile
\r
37 call :msg "identical files"
\r
39 echo 1 > identicalfile
\r
42 call :msg "hard linked file"
\r
44 mklink /h link file > nul
\r
47 call :msg "hard linked file, with other identical files"
\r
49 mklink /h link file > nul
\r
50 echo 1 > identicalfile
\r
53 call :msg "empty file"
\r
54 type nul > emptyfile
\r
57 call :msg "hard linked empty file"
\r
59 mklink /h link file > nul
\r
60 REM Use skip_dism_cmp=1 due to DISM bug
\r
61 call :do_test_with_params 0 1
\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
74 REM Use skip_dism_cmp=1 due to DISM bug
\r
75 call :do_test_with_params 0 1
\r
77 call :msg "multiple subdirectories, some empty, some not"
\r
83 mklink /h link subdir1\1 > nul
\r
84 md subdir2\subdir2subdir
\r
85 type nul > subdir2\emptyfile
\r
88 REM FIXME: win32-tree-cmp can't handle this case.
\r
90 REM call :msg "file with custom security descriptor"
\r
91 REM echo hello > file
\r
92 REM icacls file /deny Administrator:F > nul
\r
95 call :msg "directory with custom security descriptor (inheritence enabled)"
\r
97 icacls subdir /inheritance:e > nul
\r
100 call :msg "directory with custom security descriptor (inheritence disabled)"
\r
102 icacls subdir /inheritance:d > nul
\r
105 REM FIXME: win32-tree-cmp can't handle this case.
\r
107 REM call :msg "file with custom security descriptor (all inherited ACEs removed)"
\r
108 REM echo hello > file
\r
109 REM icacls file /inheritance:r > nul
\r
112 call :msg "file with custom integrity level"
\r
114 icacls file /setintegritylevel H > nul
\r
115 REM Use skip_dism_cmp=1 due to DISM bug
\r
116 call :do_test_with_params 0 1
\r
118 call :msg "relative symlink"
\r
119 mklink relink dest > nul
\r
122 call :msg "absolute symlink, with drive letter"
\r
123 mklink abslink C:\absolute\target > nul
\r
126 call :msg "absolute symlink, without drive letter"
\r
127 mklink abslink \absolute\target > nul
\r
130 call :msg "relative symlink, with file target"
\r
132 mklink relink 1 > nul
\r
135 call :msg "relative symlink, with directory target"
\r
137 mklink reldlink subdir > nul
\r
140 call :msg "junction"
\r
142 mklink /j junction subdir > nul
\r
145 call :msg "symlinks, junctions, files, subdirectories, etc."
\r
147 mklink relink 1 > nul
\r
148 mklink rellinklink relink > nul
\r
149 mklink /j junction . > nul
\r
151 mklink /h subdir\hardlink 1 > nul
\r
152 echo "hello world!!!!" > hello
\r
153 mklink subdir\hello hello > nul
\r
154 mklink abslink C:\Users > nul
\r
156 type nul > emptyfile
\r
157 type nul > subdir2\emptyfile
\r
161 echo "hello world!!!!" > subdir2\otherfile
\r
164 call :msg "reparse point that is neither a symlink nor a junction"
\r
166 %SET_REPARSE_POINT% file
\r
169 call :msg "reparse point with named data streams"
\r
173 %SET_REPARSE_POINT% file
\r
176 call :msg "reparse point with unnamed data stream"
\r
178 %SET_REPARSE_POINT% file
\r
181 call :msg "reparse point with unnamed data stream and named data streams"
\r
185 %SET_REPARSE_POINT% file
\r
188 call :msg "empty reparse point"
\r
190 %SET_REPARSE_POINT% file 0
\r
193 call :msg "empty reparse point with unnamed data stream"
\r
195 %SET_REPARSE_POINT% file 0
\r
198 call :msg "empty reparse point with unnamed data stream and named data streams"
\r
200 echo hello > file:ads1
\r
201 type nul > file:ads2
\r
202 %SET_REPARSE_POINT% file 0
\r
205 call :msg "maximum length reparse point"
\r
207 %SET_REPARSE_POINT% file 16376
\r
210 call :msg "directory reparse point that is neither a symlink nor a junction"
\r
212 %SET_REPARSE_POINT% subdir
\r
215 call :msg "directory reparse point with named data streams"
\r
219 %SET_REPARSE_POINT% subdir
\r
222 call :msg "compressed file"
\r
224 compact /C test > nul
\r
227 call :msg "compressed directory"
\r
229 compact /C subdir > nul
\r
232 call :msg "compressed directory with files in it"
\r
234 compact /C subdir > nul
\r
235 echo 1 > subdir\file1
\r
236 echo 2 > subdir\file2
\r
237 echo 1 > subdir\file1
\r
238 md subdir\subsubdir
\r
239 mklink /h subdir\hardlink subdir\file1 > nul
\r
240 mklink /j subdir\j subdir\subsubdir > nul
\r
243 call :msg "compressed directory with some uncompressed files in it"
\r
245 compact /C subdir > nul
\r
248 compact /U subdir\1 > nul
\r
251 call :msg "file with alternate data stream"
\r
256 call :msg "file with multiple alternate data streams"
\r
260 echo aaa > file:aaa
\r
261 echo aaaa > file:aaaa
\r
264 call :msg "file with multiple alternate data streams, with hard link"
\r
268 echo aaa > file:aaa
\r
269 echo aaaa > file:aaaa
\r
270 mklink /h link file > nul
\r
273 call :msg "files with multiple alternate data streams, some identical, with hard link"
\r
277 echo 1 > file:1again
\r
278 echo aaa > file:aaa
\r
280 mklink /h link file > nul
\r
281 echo aaa > file2:aaa
\r
284 call :msg "file with empty alternate data stream"
\r
286 type nul > file:ads
\r
289 call :msg "directory with empty alternate data stream"
\r
291 type nul > subdir:ads
\r
294 call :msg "root directory with alternate data stream"
\r
295 echo 1 > ..\in.dir:ads
\r
298 call :msg "root directory with empty alternate data stream"
\r
299 type nul > ..\in.dir:ads
\r
302 call :msg "subdirectory with alternate data streams"
\r
306 echo 2 > subdir:2again
\r
309 call :msg "subdirectories and files with alternate data streams"
\r
312 echo hello > subdir:hello
\r
313 echo hello > subdir:helloagain
\r
314 echo hello > helloagain
\r
315 mklink /h hellolink hello > nul
\r
316 echo 1 > helloagain:1
\r
317 echo 8 > helloagain:8
\r
319 type nul > helloagain:dummy
\r
322 call :msg "symbolic link and hard link, to file with alternate data streams"
\r
324 echo test > .\1:test
\r
325 mklink symlink 1 > nul
\r
326 mklink /h hardlink 1 > nul
\r
329 call :msg "compressed file with alternate data streams"
\r
336 call :msg "hidden file"
\r
341 call :msg "hidden system file"
\r
346 call :msg "hidden, readonly, system file"
\r
348 attrib +h +r +s file
\r
351 call :msg "hidden directory"
\r
356 call :msg "hidden system directory"
\r
358 attrib +h +s subdir
\r
361 call :msg "hidden, readonly, system directory"
\r
363 attrib +h +r +s subdir
\r
366 call :msg "readonly directory with named data stream"
\r
368 echo foo > subdir:ads
\r
372 call :msg "encrypted file"
\r
373 echo "hello" > encrypted
\r
374 cipher /e encrypted > nul
\r
377 call :msg "identical encrypted files"
\r
378 echo "hello" > encrypted1
\r
379 echo "hello" > encrypted2
\r
380 cipher /e encrypted1 > nul
\r
381 cipher /e encrypted2 > nul
\r
384 call :msg "encrypted directory"
\r
386 cipher /e subdir > nul
\r
389 call :msg "encrypted directory with encrypted file in it"
\r
392 cipher /e subdir > nul
\r
393 cipher /e subdir\1 > nul
\r
396 call :msg "encrypted directory with unencrypted file in it"
\r
399 cipher /e subdir > nul
\r
400 cipher /d subdir\1 > nul
\r
403 REM FIXME: apply fails with STATUS_ACCESS_DENIED
\r
405 REM call :msg "encrypted root directory"
\r
407 REM cipher /e in.dir > nul
\r
409 REM echo "hello" > encrypted
\r
412 call :msg "unencrypted file in encrypted directory in compressed directory"
\r
416 cipher /e 1\2 > nul
\r
417 echo hello > 1\2\file
\r
418 cipher /d 1\2\file > nul
\r
421 call :msg "encrypted directory with alternate data streams"
\r
423 cipher /e subdir > nul
\r
424 echo ads1 > subdir:ads1
\r
425 echo ads2 > subdir:ads2
\r
428 call :msg "hardlinked, encrypted file with alternate data streams"
\r
430 echo hello > file:ads
\r
431 cipher /e file > nul
\r
432 mklink /h link file > nul
\r
435 REM Note: since object IDs must be unique per filesystem, we can't expect them
\r
436 REM to preserved using our testing scheme. Therefore, win32-tree-cmp doesn't
\r
437 REM compare them, and the below tests really just ensure the object ID code is
\r
438 REM run to some extent.
\r
440 call :msg "file with object ID"
\r
442 fsutil objectid create file > nul
\r
445 call :msg "directory with object ID"
\r
447 fsutil objectid set f67394c12b17608e1d050d181ba8ffd2 7df80cbdf620f4c82c79b9e6799147b6 97621aff72915ade05abb96b15dea1a3 e0bda4caa9e33cfd461c92c16be9713d subdir
\r
450 call :msg "sparse files"
\r
451 fsutil file createnew sparse 1000000 > nul
\r
452 fsutil sparse setflag sparse
\r
453 fsutil sparse setrange sparse 0 1000000
\r
455 fsutil file createnew mostly_sparse 1000000 > nul
\r
456 fsutil sparse setflag mostly_sparse
\r
457 fsutil sparse setrange mostly_sparse 0 1000000
\r
458 echo hello >> mostly_sparse
\r
459 type sparse >> mostly_sparse
\r
460 fsutil sparse setrange mostly_sparse 1000100 2000000
\r
463 call :msg "sparse and compressed files"
\r
464 fsutil file createnew sparse 1000000 > nul
\r
465 fsutil sparse setflag sparse
\r
466 fsutil sparse setrange sparse 0 1000000
\r
467 compact /c sparse > nul
\r
469 fsutil file createnew mostly_sparse 1000000 > nul
\r
470 fsutil sparse setflag mostly_sparse
\r
471 fsutil sparse setrange mostly_sparse 0 1000000
\r
472 echo hello >> mostly_sparse
\r
473 type sparse >> mostly_sparse
\r
474 fsutil sparse setrange mostly_sparse 1000100 2000000
\r
475 compact /c mostly_sparse > nul
\r
477 type nul > compressed_first
\r
478 compact /c compressed_first > nul
\r
479 type sparse >> compressed_first
\r
480 fsutil sparse setflag compressed_first
\r
481 fsutil sparse setrange compressed_first 0 500000
\r
486 echo Testing rpfix junction
\r
488 echo 1 > subdir\file
\r
489 mklink /j junction subdir > nul
\r
491 %WIMLIB_IMAGEX% capture in.dir test.wim > nul
\r
493 %WIMLIB_IMAGEX% apply test.wim out.dir > nul
\r
495 type out.dir\junction\file > tmp2
\r
497 if %errorlevel% neq 0 goto :fail
\r
503 echo Testing rpfix relative
\r
505 mklink relink file > nul
\r
507 %WIMLIB_IMAGEX% capture in.dir test.wim > nul
\r
508 %WIMLIB_IMAGEX% apply test.wim out.dir > nul
\r
509 type out.dir\relink > out.dir\tmp
\r
510 if %errorlevel% neq 0 goto :fail
\r
511 fc in.dir\file out.dir\tmp > nul
\r
512 if %errorlevel% neq 0 goto :fail
\r
513 rd /s /q in.dir out.dir
\r
527 call :do_test_with_params 0 0
\r
530 :do_test_with_params
\r
531 set skip_dism_apply=%1
\r
532 set skip_dism_cmp=%2
\r
534 echo wimlib test (first time)
\r
535 %WIMLIB_IMAGEX% capture in.dir test.wim --norpfix > NUL
\r
536 if %errorlevel% neq 0 goto :fail
\r
537 %WIMLIB_IMAGEX% apply test.wim out.dir > NUL
\r
538 if %errorlevel% neq 0 goto :fail
\r
539 %WIN32_TREE_CMP% in.dir out.dir
\r
540 if %errorlevel% neq 0 goto :fail
\r
542 REM apply a second time so we test the case where the files already exist
\r
543 echo wimlib test (second time)
\r
544 %WIMLIB_IMAGEX% apply test.wim out.dir > NUL
\r
545 if %errorlevel% neq 0 goto :fail
\r
546 %WIN32_TREE_CMP% in.dir out.dir
\r
547 if %errorlevel% neq 0 goto :fail
\r
549 REM compatibility test: apply the image with DISM
\r
553 if %skip_dism_apply% neq 1 (
\r
554 dism /apply-image /imagefile:test.wim /index:1 /applydir:out.dir > nul
\r
555 if !errorlevel! neq 0 (
\r
556 echo ERROR: DISM apply failed!
\r
559 if %skip_dism_cmp% neq 1 (
\r
560 %WIN32_TREE_CMP% in.dir out.dir
\r
561 if !errorlevel! neq 0 (
\r
562 echo ERROR: DISM comparison failed!
\r
568 rd /S /Q in.dir out.dir
\r
574 echo Testing capture and apply of %~1
\r
578 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\r
579 echo TEST FAILED!!!!!!!
\r
580 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\r