diff --git a/tools/build-sample.bat b/tools/build-sample.bat index 3a3e2e23..a934992a 100644 --- a/tools/build-sample.bat +++ b/tools/build-sample.bat @@ -12,20 +12,26 @@ if X!ProjDir!==X (echo usage: build-sample Config Arch Sample ProjDir >&2 & goto call "%VS140COMNTOOLS%\..\..\VC\vcvarsall.bat" x64 -set RegKey="HKLM\SOFTWARE\WinFsp" -set RegVal="InstallDir" -reg query !RegKey! /v !RegVal! /reg:32 >nul 2>&1 -if !ERRORLEVEL! equ 0 ( - for /f "tokens=2,*" %%i in ('reg query !RegKey! /v !RegVal! /reg:32 ^| findstr !RegVal!') do ( - set InstallDir=%%j - ) +if X!FSP_SAMPLE_DIR!==X ( + set RegKey="HKLM\SOFTWARE\WinFsp" + set RegVal="InstallDir" + reg query !RegKey! /v !RegVal! /reg:32 >nul 2>&1 + if !ERRORLEVEL! equ 0 ( + for /f "tokens=2,*" %%i in ('reg query !RegKey! /v !RegVal! /reg:32 ^| findstr !RegVal!') do ( + set InstallDir=%%j + ) + ) + if not exist "!InstallDir!" (echo cannot find WinFsp installation >&2 & goto fail) + if not exist "!InstallDir!samples\!Sample!" (echo cannot find WinFsp sample !Sample! >&2 & goto fail) + + set SampleDir=!InstallDir!samples +) else ( + set SampleDir=!FSP_SAMPLE_DIR! ) -if not exist "!InstallDir!" (echo cannot find WinFsp installation >&2 & goto fail) -if not exist "!InstallDir!samples\!Sample!" (echo cannot find WinFsp sample !Sample! >&2 & goto fail) if exist "!ProjDir!" rmdir /s/q "!ProjDir!" mkdir "!ProjDir!" -xcopy /s/e/q/y "!InstallDir!samples\!Sample!" "!ProjDir!" +xcopy /s/e/q/y "!SampleDir!\!Sample!" "!ProjDir!" devenv "!ProjDir!\!Sample!.sln" /build "!Config!|!Arch!" if !ERRORLEVEL! neq 0 goto :fail diff --git a/tools/run-tests.bat b/tools/run-tests.bat index 562e5d76..bd6caabc 100755 --- a/tools/run-tests.bat +++ b/tools/run-tests.bat @@ -364,20 +364,20 @@ exit /b 0 :__ifstest-memfs %1 set IfsTestDirectories=^ - securit^ - opcreatg^ - opcreatp^ - closedel^ - volinfo^ - fileinfo^ - dirinfo^ - filelock^ - oplocks^ - chgnotif^ - readwr^ - seccache^ - reparspt^ - estream + securit^ + opcreatg^ + opcreatp^ + closedel^ + volinfo^ + fileinfo^ + dirinfo^ + filelock^ + oplocks^ + chgnotif^ + readwr^ + seccache^ + reparspt^ + estream set IfsTestMemfsExit=0 call :__ifstest %1 /g Security if !ERRORLEVEL! neq 0 set IfsTestMemfsExit=1 @@ -421,7 +421,7 @@ rem StreamEnhancements.StreamNotifyNameTest: WinFsp does not notify when streams call :__ifstest %1 /g StreamEnhancements -t StreamRenameTest -t StreamNotifyNameTest if !ERRORLEVEL! neq 0 set IfsTestMemfsExit=1 for %%d in (!IfsTestDirectories!) do ( - if exist %%d (echo :ifstest directory %%d still exists & set IfsTestMemfsExit=1) + if exist %%d (echo :ifstest directory %%d still exists & set IfsTestMemfsExit=1) ) exit /b !IfsTestMemfsExit! @@ -505,7 +505,8 @@ if !ERRORLEVEL! neq 0 goto fail exit /b 0 :sample-passthrough-dotnet -call :__run_sample_test passthrough-dotnet anycpu passthrough-dotnet winfsp-tests-x64 +call :__run_sample_test passthrough-dotnet anycpu passthrough-dotnet winfsp-tests-x64 ^ + "-create_backup_test -create_restore_test -create_namelen_test -delete_access_test" if !ERRORLEVEL! neq 0 goto fail exit /b 0 @@ -536,7 +537,7 @@ L: "%ProjRoot%\build\VStudio\build\%Configuration%\%4.exe" ^ --external --resilient --case-insensitive-cmp --share-prefix="\%1\%TMP::=$%\%1\test" ^ -create_allocation_test -getfileinfo_name_test -rename_flipflop_test -rename_mmap_test -exec_rename_dir_test ^ - -reparse* -stream* + -reparse* -stream* %~5 if !ERRORLEVEL! neq 0 set RunSampleTestExit=1 popd echo net use L: /delete diff --git a/tst/passthrough-dotnet/Program.cs b/tst/passthrough-dotnet/Program.cs index 2b7a2ea9..55f8529a 100644 --- a/tst/passthrough-dotnet/Program.cs +++ b/tst/passthrough-dotnet/Program.cs @@ -197,6 +197,11 @@ namespace passthrough ThrowIoExceptionWithHResult(ex.HResult); } } + public static void Rename(String FileName, String NewFileName, Boolean ReplaceIfExists) + { + if (!MoveFileExW(FileName, NewFileName, ReplaceIfExists ? 1U/*MOVEFILE_REPLACE_EXISTING*/ : 0)) + ThrowIoExceptionWithWin32(Marshal.GetLastWin32Error()); + } /* interop */ [StructLayout(LayoutKind.Sequential, Pack = 4)] @@ -243,6 +248,11 @@ namespace passthrough Int32 FileInformationClass, ref FILE_DISPOSITION_INFO lpFileInformation, UInt32 dwBufferSize); + [DllImport("kernel32.dll", SetLastError = true)] + private static extern Boolean MoveFileExW( + [MarshalAs(UnmanagedType.LPWStr)] String lpExistingFileName, + [MarshalAs(UnmanagedType.LPWStr)] String lpNewFileName, + UInt32 dwFlags); [DllImport("advapi32.dll", SetLastError = true)] private static extern Boolean SetFileSecurityW( [MarshalAs(UnmanagedType.LPWStr)] String FileName, @@ -590,21 +600,9 @@ namespace passthrough String NewFileName, Boolean ReplaceIfExists) { - FileDesc FileDesc = (FileDesc)FileDesc0; FileName = ConcatPath(FileName); NewFileName = ConcatPath(NewFileName); - if (null != FileDesc.Stream) - { - if (ReplaceIfExists) - File.Delete(NewFileName); - File.Move(FileName, NewFileName); - } - else - { - if (ReplaceIfExists) - throw new UnauthorizedAccessException(); - Directory.Move(FileName, NewFileName); - } + FileDesc.Rename(FileName, NewFileName, ReplaceIfExists); return STATUS_SUCCESS; } protected override Int32 GetSecurity(