]> wimlib.net Git - wimlib/blobdiff - tests/win32-test-imagex-capture_and_apply.bat
Update version-info
[wimlib] / tests / win32-test-imagex-capture_and_apply.bat
index 6e2bebafd995c6169ae0a34b8de365fa51f72a99..8f573eceb62bd5ea4c7f8f7ca4b0692fa1ef816f 100644 (file)
@@ -6,10 +6,13 @@ REM
 REM Run some tests on the Windows version of wimlib-imagex.\r
 REM\r
 REM This must be run on Windows Vista or later in a clean directory, with\r
-REM Administrator privileges.  wimlib-imagex and win32-tree-cmp must be callable\r
-REM (on PATH or in same directory).\r
+REM Administrator privileges.  wimlib-imagex and win32-tree-cmp must be\r
+REM executable using the paths set below.\r
 \r
 setlocal EnableDelayedExpansion\r
+set WIMLIB_IMAGEX=wimlib-imagex\r
+set WIN32_TREE_CMP=win32-tree-cmp\r
+set SET_REPARSE_POINT=set_reparse_point\r
 \r
 if exist in.dir rd /S /Q in.dir\r
 if exist out.dir rd /S /Q out.dir\r
@@ -22,42 +25,48 @@ REM
 \r
 call :msg "empty directory"\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "single file"\r
 echo 1 > file\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "different files"\r
 echo 1 > file\r
 echo 2 > anotherfile\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "identical files"\r
 echo 1 > file\r
 echo 1 > identicalfile\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "hard linked file"\r
 echo 1 > file\r
 mklink /h link file > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "hard linked file, with other identical files"\r
 echo 1 > file\r
 mklink /h link file > nul\r
 echo 1 > identicalfile\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "empty file"\r
 type nul > emptyfile\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "hard linked empty file"\r
+type nul > file\r
+mklink /h link file > nul\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "various hard linked, identical, different, and empty files"\r
 echo 1 > file\r
@@ -71,7 +80,7 @@ echo 5 > identicalfile
 echo 1 > 1file\r
 mklink /h 1filelink 1file > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "multiple subdirectories, some empty, some not"\r
 md subdir1\r
@@ -83,40 +92,72 @@ mklink /h link subdir1\1 > nul
 md subdir2\subdir2subdir\r
 type nul > subdir2\emptyfile\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "file with custom security descriptor"\r
+echo hello > file\r
+icacls file /deny Administrator:F > nul\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "directory with custom security descriptor (inheritence enabled)"\r
+md subdir\r
+icacls subdir /inheritance:e > nul\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "directory with custom security descriptor (inheritence disabled)"\r
+md subdir\r
+icacls subdir /inheritance:d > nul\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+REM            win32-tree-cmp can't handle this case.\r
+REM\r
+REM call :msg "file with custom security descriptor (all inherited ACEs removed)"\r
+REM echo hello > file\r
+REM icacls file /inheritance:r > nul\r
+REM call :do_test\r
+REM if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "file with custom integrity level"\r
+echo hello > file\r
+icacls file /setintegritylevel H > nul\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "relative symlink"\r
 mklink relink dest > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "absolute symlink, with drive letter"\r
 mklink abslink C:\absolute\target > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "absolute symlink, without drive letter"\r
 mklink abslink \absolute\target > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "relative symlink, with file target"\r
 echo 1 > 1\r
 mklink relink 1 > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "relative symlink, with directory target"\r
 md subdir\r
 mklink reldlink subdir > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "junction"\r
 md subdir\r
 mklink /j junction subdir > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "symlinks, junctions, files, subdirectories, etc."\r
 echo 1 > 1\r
@@ -136,19 +177,87 @@ md subdir2\s\s
 md subdir2\s\s\s\r
 echo "hello world!!!!" > subdir2\otherfile\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "reparse point that is neither a symlink nor a junction"\r
+type nul > file\r
+%SET_REPARSE_POINT% file\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "reparse point with named data streams"\r
+type nul > file\r
+echo 11 > file:a\r
+echo 1 > file:aa\r
+%SET_REPARSE_POINT% file\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "reparse point with unnamed data stream"\r
+echo "test" > file\r
+%SET_REPARSE_POINT% file\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "reparse point with unnamed data stream and named data streams"\r
+echo "test" > file\r
+echo 11 > file:a\r
+echo 1 > file:aa\r
+%SET_REPARSE_POINT% file\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "empty reparse point"\r
+type nul > file\r
+%SET_REPARSE_POINT% file 0\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "empty reparse point with unnamed data stream"\r
+echo hello > file\r
+%SET_REPARSE_POINT% file 0\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "empty reparse point with unnamed data stream and named data streams"\r
+echo hello > file\r
+echo hello > file:ads1\r
+type nul > file:ads2\r
+%SET_REPARSE_POINT% file 0\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "maximum length reparse point"\r
+type nul > file\r
+%SET_REPARSE_POINT% file 16376\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "directory reparse point that is neither a symlink nor a junction"\r
+md subdir\r
+%SET_REPARSE_POINT% subdir\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "directory reparse point with named data streams"\r
+md subdir\r
+echo 11 > subdir:a\r
+echo 1 > subdir:aa\r
+%SET_REPARSE_POINT% subdir\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "compressed file"\r
 echo "test" > test\r
 compact /C test > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "compressed directory"\r
 md subdir\r
 compact /C subdir > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "compressed directory with files in it"\r
 md subdir\r
@@ -160,7 +269,7 @@ md subdir\subsubdir
 mklink /h subdir\hardlink subdir\file1 > nul\r
 mklink /j subdir\j subdir\subsubdir > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "compressed directory with some uncompressed files in it"\r
 md subdir\r
@@ -169,13 +278,13 @@ echo 1 > subdir\1
 echo 5 > subdir\5\r
 compact /U subdir\1 > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "file with alternate data stream"\r
 echo 1 > file\r
 echo 5 > file:ads\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "file with multiple alternate data streams"\r
 echo 1 > file\r
@@ -184,7 +293,7 @@ echo aa > file:aa
 echo aaa > file:aaa\r
 echo aaaa > file:aaaa\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "file with multiple alternate data streams, with hard link"\r
 echo 1 > file\r
@@ -194,7 +303,7 @@ echo aaa > file:aaa
 echo aaaa > file:aaaa\r
 mklink /h link file > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "files with multiple alternate data streams, some identical, with hard link"\r
 echo 1 > file\r
@@ -206,12 +315,29 @@ echo 5 > file:5
 mklink /h link file > nul\r
 echo aaa > file2:aaa\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "file with empty alternate data stream"\r
+echo 1 > file\r
+type nul > file:ads\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "directory with empty alternate data stream"\r
+md subdir\r
+type nul > subdir:ads\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "root directory with alternate data stream"\r
 echo 1 > ..\in.dir:ads\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "root directory with empty alternate data stream"\r
+type nul > ..\in.dir:ads\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "subdirectory with alternate data streams"\r
 md subdir\r
@@ -219,7 +345,7 @@ echo 1 > subdir:1
 echo 2 > subdir:2\r
 echo 2 > subdir:2again\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "subdirectories and files with alternate data streams"\r
 md subdir\r
@@ -233,7 +359,7 @@ echo 8 > helloagain:8
 echo 1 > 1\r
 type nul > helloagain:dummy\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "symbolic link and hard link, to file with alternate data streams"\r
 echo 1 > 1\r
@@ -241,7 +367,7 @@ echo test > .\1:test
 mklink symlink 1 > nul\r
 mklink /h hardlink 1 > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "compressed file with alternate data streams"\r
 echo 1 > 1\r
@@ -249,25 +375,56 @@ echo 1 > .\1:1
 echo 2 > .\1:2\r
 compact /C 1 > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "hidden file"\r
 echo 1 > hidden\r
 attrib +h hidden\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "hidden system file"\r
+echo 1 > file\r
+attrib +h +s file\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "hidden, readonly, system file"\r
+echo 1 > file\r
+attrib +h +r +s file\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "hidden directory"\r
 md subdir\r
 attrib +h subdir\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "hidden system directory"\r
+md subdir\r
+attrib +h +s subdir\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "hidden, readonly, system directory"\r
+md subdir\r
+attrib +h +r +s subdir\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "readonly directory with named data stream"\r
+md subdir\r
+echo foo > subdir:ads\r
+attrib +r subdir\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "encrypted file"\r
 echo "hello" > encrypted\r
 cipher /e encrypted > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "identical encrypted files"\r
 echo "hello" > encrypted1\r
@@ -275,13 +432,13 @@ echo "hello" > encrypted2
 cipher /e encrypted1 > nul\r
 cipher /e encrypted2 > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "encrypted directory"\r
 md subdir\r
 cipher /e subdir > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "encrypted directory with encrypted file in it"\r
 md subdir\r
@@ -289,15 +446,41 @@ echo 1 > subdir\1
 cipher /e subdir > nul\r
 cipher /e subdir\1 > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
 \r
-REM call :msg "encrypted directory with unencrypted file in it"\r
-REM md subdir\r
-REM echo 1 > subdir\1\r
-REM cipher /e subdir > nul\r
-REM cipher /d subdir\1 > nul\r
-REM call :do_test\r
-REM if %errorlevel% neq 0 exit /b %errorlevel%\r
+call :msg "encrypted directory with unencrypted file in it"\r
+md subdir\r
+echo 1 > subdir\1\r
+cipher /e subdir > nul\r
+cipher /d subdir\1 > nul\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "encrypted root directory"\r
+cd ..\r
+cipher /e in.dir > nul\r
+cd in.dir\r
+echo "hello" > encrypted\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "unencrypted file in encrypted directory in compressed directory"\r
+md 1\r
+md 1\2\r
+compact /c 1 > nul\r
+cipher /e 1\2 > nul\r
+echo hello > 1\2\file\r
+cipher /d 1\2\file > nul\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+call :msg "encrypted directory with alternate data streams"\r
+md subdir\r
+cipher /e subdir > nul\r
+echo ads1 > subdir:ads1\r
+echo ads2 > subdir:ads2\r
+call :do_test\r
+if %errorlevel% neq 0 goto :fail\r
 \r
 call :msg "hardlinked, encrypted file with alternate data streams"\r
 echo hello > file\r
@@ -305,44 +488,75 @@ echo hello > file:ads
 cipher /e file > nul\r
 mklink /h link file > nul\r
 call :do_test\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+:rpfix_tests\r
+\r
+echo Testing rpfix junction\r
+md subdir\r
+echo 1 > subdir\file\r
+mklink /j junction subdir > nul\r
+cd ..\r
+%WIMLIB_IMAGEX% capture in.dir test.wim > nul\r
+rd /s /q in.dir\r
+%WIMLIB_IMAGEX% apply test.wim out.dir > nul\r
+echo 1 > tmp1\r
+type out.dir\junction\file > tmp2\r
+fc tmp1 tmp2 > nul\r
+if %errorlevel% neq 0 goto :fail\r
+rd /s /q out.dir\r
+del tmp1 tmp2\r
+md in.dir\r
+cd in.dir\r
+\r
+echo Testing rpfix relative\r
+echo 1 > file\r
+mklink relink file > nul\r
+cd ..\r
+%WIMLIB_IMAGEX% capture in.dir test.wim > nul\r
+%WIMLIB_IMAGEX% apply test.wim out.dir > nul\r
+type out.dir\relink > out.dir\tmp\r
+if %errorlevel% neq 0 goto :fail\r
+fc in.dir\file out.dir\tmp > nul\r
+if %errorlevel% neq 0 goto :fail\r
+rd /s /q in.dir out.dir\r
+md in.dir\r
+cd in.dir\r
 \r
 REM\r
 REM END OF TESTS\r
 REM\r
 \r
+cd ..\r
+del test.wim\r
+rd /s /q in.dir\r
 exit /b 0\r
 \r
 :do_test\r
 cd ..\r
-wimlib-imagex capture in.dir test.wim --norpfix > NUL\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
-wimlib-imagex apply test.wim out.dir > NUL\r
-if %errorlevel% neq 0 exit /b %errorlevel%\r
-win32-tree-cmp in.dir out.dir\r
-if %errorlevel% neq 0 (\r
-       echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
-       echo            TEST FAILED!!!!!!!\r
-       echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
-       exit /b %errorlevel%\r
-)\r
-\r
-REM Fun fact:  There are bugs in Microsoft's imagex.exe that make it fail some\r
-REM of our tests.\r
-REM\r
-REM rd /S /Q out.dir\r
-REM md out.dir\r
-REM imagex /capture in.dir test.wim "test" /norpfix > nul\r
-REM if %errorlevel% neq 0 exit /b %errorlevel%\r
-REM imagex /apply test.wim 1 out.dir > nul\r
-REM if %errorlevel% neq 0 exit /b %errorlevel%\r
-REM win32-tree-cmp in.dir out.dir\r
-REM if %errorlevel% neq 0 (\r
-       REM echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
-       REM echo            TEST FAILED!!!!!!! ^(imagex^)\r
-       REM echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
-       REM exit /b %errorlevel%\r
-REM )\r
+%WIMLIB_IMAGEX% capture in.dir test.wim --norpfix > NUL\r
+if %errorlevel% neq 0 goto :fail\r
+%WIMLIB_IMAGEX% apply test.wim out.dir > NUL\r
+if %errorlevel% neq 0 goto :fail\r
+%WIN32_TREE_CMP% in.dir out.dir\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+REM  apply a second time so we test the case where the files already exist\r
+%WIMLIB_IMAGEX% apply test.wim out.dir > NUL\r
+if %errorlevel% neq 0 goto :fail\r
+%WIN32_TREE_CMP% in.dir out.dir\r
+if %errorlevel% neq 0 goto :fail\r
+\r
+REM Fun fact: Microsoft's WIMGAPI has bugs that make it fail some of our tests.\r
+REM Even the Windows 8.1 version has incorrect behavior with empty files with\r
+REM multiple links, or files with named data streams and multiple links.\r
+rd /S /Q out.dir\r
+md out.dir\r
+REM dism /capture-image /capturedir:in.dir /imagefile:test.wim /name:"test" /norpfix > nul\r
+REM if %errorlevel% neq 0 goto :fail\r
+dism /apply-image /imagefile:test.wim /index:1 /applydir:out.dir > nul\r
+if %errorlevel% neq 0 goto :fail\r
+%WIN32_TREE_CMP% in.dir out.dir\r
 \r
 rd /S /Q in.dir out.dir\r
 md in.dir\r
@@ -352,3 +566,9 @@ goto :eof
 :msg\r
 echo Testing capture and apply of %~1\r
 goto :eof\r
+\r
+:fail\r
+echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
+echo            TEST FAILED!!!!!!!\r
+echo @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@\r
+exit /b %errorlevel%\r