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
179 REM Use skip_dism_apply=1 due to DISM bug
\r
180 call :do_test_with_params 1 0
\r
182 call :msg "reparse point with unnamed data stream and named data streams"
\r
186 %SET_REPARSE_POINT% file
\r
187 REM Use skip_dism_apply=1 due to DISM bug
\r
188 call :do_test_with_params 1 0
\r
190 call :msg "empty reparse point"
\r
192 %SET_REPARSE_POINT% file 0
\r
195 call :msg "empty reparse point with unnamed data stream"
\r
197 %SET_REPARSE_POINT% file 0
\r
200 call :msg "empty reparse point with unnamed data stream and named data streams"
\r
202 echo hello > file:ads1
\r
203 type nul > file:ads2
\r
204 %SET_REPARSE_POINT% file 0
\r
205 REM Use skip_dism_apply=1 due to DISM bug
\r
206 call :do_test_with_params 1 0
\r
208 call :msg "maximum length reparse point"
\r
210 %SET_REPARSE_POINT% file 16376
\r
213 call :msg "directory reparse point that is neither a symlink nor a junction"
\r
215 %SET_REPARSE_POINT% subdir
\r
218 call :msg "directory reparse point with named data streams"
\r
222 %SET_REPARSE_POINT% subdir
\r
225 call :msg "compressed file"
\r
227 compact /C test > nul
\r
230 call :msg "compressed directory"
\r
232 compact /C subdir > nul
\r
235 call :msg "compressed directory with files in it"
\r
237 compact /C subdir > nul
\r
238 echo 1 > subdir\file1
\r
239 echo 2 > subdir\file2
\r
240 echo 1 > subdir\file1
\r
241 md subdir\subsubdir
\r
242 mklink /h subdir\hardlink subdir\file1 > nul
\r
243 mklink /j subdir\j subdir\subsubdir > nul
\r
246 call :msg "compressed directory with some uncompressed files in it"
\r
248 compact /C subdir > nul
\r
251 compact /U subdir\1 > nul
\r
254 call :msg "file with alternate data stream"
\r
259 call :msg "file with multiple alternate data streams"
\r
263 echo aaa > file:aaa
\r
264 echo aaaa > file:aaaa
\r
267 call :msg "file with multiple alternate data streams, with hard link"
\r
271 echo aaa > file:aaa
\r
272 echo aaaa > file:aaaa
\r
273 mklink /h link file > nul
\r
276 call :msg "files with multiple alternate data streams, some identical, with hard link"
\r
280 echo 1 > file:1again
\r
281 echo aaa > file:aaa
\r
283 mklink /h link file > nul
\r
284 echo aaa > file2:aaa
\r
287 call :msg "file with empty alternate data stream"
\r
289 type nul > file:ads
\r
292 call :msg "directory with empty alternate data stream"
\r
294 type nul > subdir:ads
\r
295 REM Use skip_dism_apply=1 due to DISM bug
\r
296 call :do_test_with_params 1 0
\r
298 call :msg "root directory with alternate data stream"
\r
299 echo 1 > ..\in.dir:ads
\r
300 REM Use skip_dism_apply=1 due to DISM bug
\r
301 call :do_test_with_params 1 0
\r
303 call :msg "root directory with empty alternate data stream"
\r
304 type nul > ..\in.dir:ads
\r
305 REM Use skip_dism_apply=1 due to DISM bug
\r
306 call :do_test_with_params 1 0
\r
308 call :msg "subdirectory with alternate data streams"
\r
312 echo 2 > subdir:2again
\r
313 REM Use skip_dism_apply=1 due to DISM bug
\r
314 call :do_test_with_params 1 0
\r
316 call :msg "subdirectories and files with alternate data streams"
\r
319 echo hello > subdir:hello
\r
320 echo hello > subdir:helloagain
\r
321 echo hello > helloagain
\r
322 mklink /h hellolink hello > nul
\r
323 echo 1 > helloagain:1
\r
324 echo 8 > helloagain:8
\r
326 type nul > helloagain:dummy
\r
327 REM Use skip_dism_apply=1 due to DISM bug
\r
328 call :do_test_with_params 1 0
\r
330 call :msg "symbolic link and hard link, to file with alternate data streams"
\r
332 echo test > .\1:test
\r
333 mklink symlink 1 > nul
\r
334 mklink /h hardlink 1 > nul
\r
335 REM Use skip_dism_apply=1 due to DISM bug
\r
336 call :do_test_with_params 1 0
\r
338 call :msg "compressed file with alternate data streams"
\r
345 call :msg "hidden file"
\r
350 call :msg "hidden system file"
\r
355 call :msg "hidden, readonly, system file"
\r
357 attrib +h +r +s file
\r
360 call :msg "hidden directory"
\r
365 call :msg "hidden system directory"
\r
367 attrib +h +s subdir
\r
370 call :msg "hidden, readonly, system directory"
\r
372 attrib +h +r +s subdir
\r
375 call :msg "readonly directory with named data stream"
\r
377 echo foo > subdir:ads
\r
379 REM Use skip_dism_apply=1 due to DISM bug
\r
380 call :do_test_with_params 1 0
\r
382 call :msg "encrypted file"
\r
383 echo "hello" > encrypted
\r
384 cipher /e encrypted > nul
\r
387 call :msg "identical encrypted files"
\r
388 echo "hello" > encrypted1
\r
389 echo "hello" > encrypted2
\r
390 cipher /e encrypted1 > nul
\r
391 cipher /e encrypted2 > nul
\r
394 call :msg "encrypted directory"
\r
396 cipher /e subdir > nul
\r
399 call :msg "encrypted directory with encrypted file in it"
\r
402 cipher /e subdir > nul
\r
403 cipher /e subdir\1 > nul
\r
406 call :msg "encrypted directory with unencrypted file in it"
\r
409 cipher /e subdir > nul
\r
410 cipher /d subdir\1 > nul
\r
413 REM FIXME: apply fails with STATUS_ACCESS_DENIED
\r
415 REM call :msg "encrypted root directory"
\r
417 REM cipher /e in.dir > nul
\r
419 REM echo "hello" > encrypted
\r
422 call :msg "unencrypted file in encrypted directory in compressed directory"
\r
426 cipher /e 1\2 > nul
\r
427 echo hello > 1\2\file
\r
428 cipher /d 1\2\file > nul
\r
431 call :msg "encrypted directory with alternate data streams"
\r
433 cipher /e subdir > nul
\r
434 echo ads1 > subdir:ads1
\r
435 echo ads2 > subdir:ads2
\r
438 call :msg "hardlinked, encrypted file with alternate data streams"
\r
440 echo hello > file:ads
\r
441 cipher /e file > nul
\r
442 mklink /h link file > nul
\r
445 REM Note: since object IDs must be unique per filesystem, we can't expect them
\r
446 REM to preserved using our testing scheme. Therefore, win32-tree-cmp doesn't
\r
447 REM compare them, and the below tests really just ensure the object ID code is
\r
448 REM run to some extent.
\r
450 call :msg "file with object ID"
\r
452 fsutil objectid create file > nul
\r
455 call :msg "directory with object ID"
\r
457 fsutil objectid set f67394c12b17608e1d050d181ba8ffd2 7df80cbdf620f4c82c79b9e6799147b6 97621aff72915ade05abb96b15dea1a3 e0bda4caa9e33cfd461c92c16be9713d subdir
\r
460 call :msg "sparse files"
\r
461 fsutil file createnew sparse 1000000 > nul
\r
462 fsutil sparse setflag sparse
\r
463 fsutil sparse setrange sparse 0 1000000
\r
465 fsutil file createnew mostly_sparse 1000000 > nul
\r
466 fsutil sparse setflag mostly_sparse
\r
467 fsutil sparse setrange mostly_sparse 0 1000000
\r
468 echo hello >> mostly_sparse
\r
469 type sparse >> mostly_sparse
\r
470 fsutil sparse setrange mostly_sparse 1000100 2000000
\r
473 call :msg "sparse and compressed files"
\r
474 fsutil file createnew sparse 1000000 > nul
\r
475 fsutil sparse setflag sparse
\r
476 fsutil sparse setrange sparse 0 1000000
\r
477 compact /c sparse > nul
\r
479 fsutil file createnew mostly_sparse 1000000 > nul
\r
480 fsutil sparse setflag mostly_sparse
\r
481 fsutil sparse setrange mostly_sparse 0 1000000
\r
482 echo hello >> mostly_sparse
\r
483 type sparse >> mostly_sparse
\r
484 fsutil sparse setrange mostly_sparse 1000100 2000000
\r
485 compact /c mostly_sparse > nul
\r
487 type nul > compressed_first
\r
488 compact /c compressed_first > nul
\r
489 type sparse >> compressed_first
\r
490 fsutil sparse setflag compressed_first
\r
491 fsutil sparse setrange compressed_first 0 500000
\r
496 echo Testing rpfix junction
\r
498 echo 1 > subdir\file
\r
499 mklink /j junction subdir > nul
\r
501 %WIMLIB_IMAGEX% capture in.dir test.wim > nul
\r
503 %WIMLIB_IMAGEX% apply test.wim out.dir > nul
\r
505 type out.dir\junction\file > tmp2
\r
507 if %errorlevel% neq 0 goto :fail
\r
513 echo Testing rpfix relative
\r
515 mklink relink file > nul
\r
517 %WIMLIB_IMAGEX% capture in.dir test.wim > nul
\r
518 %WIMLIB_IMAGEX% apply test.wim out.dir > nul
\r
519 type out.dir\relink > out.dir\tmp
\r
520 if %errorlevel% neq 0 goto :fail
\r
521 fc in.dir\file out.dir\tmp > nul
\r
522 if %errorlevel% neq 0 goto :fail
\r
523 rd /s /q in.dir out.dir
\r
537 call :do_test_with_params 0 0
\r
540 :do_test_with_params
\r
541 set skip_dism_apply=%1
\r
542 set skip_dism_cmp=%2
\r
544 echo wimlib test (first time)
\r
545 %WIMLIB_IMAGEX% capture in.dir test.wim --norpfix > NUL
\r
546 if %errorlevel% neq 0 goto :fail
\r
547 %WIMLIB_IMAGEX% apply test.wim out.dir > NUL
\r
548 if %errorlevel% neq 0 goto :fail
\r
549 %WIN32_TREE_CMP% in.dir out.dir
\r
550 if %errorlevel% neq 0 goto :fail
\r
552 REM apply a second time so we test the case where the files already exist
\r
553 echo wimlib test (second time)
\r
554 %WIMLIB_IMAGEX% apply test.wim out.dir > NUL
\r
555 if %errorlevel% neq 0 goto :fail
\r
556 %WIN32_TREE_CMP% in.dir out.dir
\r
557 if %errorlevel% neq 0 goto :fail
\r
559 REM compatibility test: apply the image with DISM
\r
563 if %skip_dism_apply% neq 1 (
\r
564 dism /apply-image /imagefile:test.wim /index:1 /applydir:out.dir > nul
\r
565 if !errorlevel! neq 0 (
\r
566 echo ERROR: DISM apply failed!
\r
569 if %skip_dism_cmp% neq 1 (
\r
570 %WIN32_TREE_CMP% in.dir out.dir
\r
571 if !errorlevel! neq 0 (
\r
572 echo ERROR: DISM comparison failed!
\r
578 rd /S /Q in.dir out.dir
\r
584 echo Testing capture and apply of %~1
\r
588 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\r
589 echo TEST FAILED!!!!!!!
\r
590 echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
\r