From ac7b7f4a1bca59409de4bd1dd896ad7f399a9794 Mon Sep 17 00:00:00 2001 From: Bill Zissimopoulos Date: Mon, 10 Apr 2017 10:03:59 -0700 Subject: [PATCH] tst: passthrough-dotnet: testing --- src/dotnet/Interop.cs | 2 +- tst/passthrough-dotnet/Program.cs | 38 +++++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/src/dotnet/Interop.cs b/src/dotnet/Interop.cs index bff71a7b..3577bc21 100644 --- a/src/dotnet/Interop.cs +++ b/src/dotnet/Interop.cs @@ -852,7 +852,7 @@ namespace Fsp.Interop } static Api() { -#if DEBUG +#if false //DEBUG if (Debugger.IsAttached) Debugger.Break(); #endif diff --git a/tst/passthrough-dotnet/Program.cs b/tst/passthrough-dotnet/Program.cs index 3a730dcf..51676168 100644 --- a/tst/passthrough-dotnet/Program.cs +++ b/tst/passthrough-dotnet/Program.cs @@ -85,6 +85,14 @@ namespace passthrough return NtStatusFromWin32((UInt32)HResult & 0xFFFF); return STATUS_UNEXPECTED_IO_ERROR; } + private Int32 HResultFromWin32(UInt32 Error) + { + return unchecked((Int32)(0x80070000 | Error)); + } + private void ThrowIoException(Int32 Result) + { + throw new IOException(null, HResultFromWin32(Win32FromNtStatus(Result))); + } protected String ConcatPath(String FileName) { return _Path + FileName; @@ -155,13 +163,14 @@ namespace passthrough FileName = ConcatPath(FileName); if (0 != (CreateOptions & FILE_DIRECTORY_FILE)) { + if (Directory.Exists(FileName)) + ThrowIoException(STATUS_OBJECT_NAME_COLLISION); DirectorySecurity Security = null; if (null != SecurityDescriptor) { Security = new DirectorySecurity(); Security.SetSecurityDescriptorBinaryForm(SecurityDescriptor); } - // ???: FILE_DELETE_ON_CLOSE FileDesc = new FileDesc( Directory.CreateDirectory(FileName, Security), null); @@ -174,8 +183,6 @@ namespace passthrough Security = new FileSecurity(); Security.SetSecurityDescriptorBinaryForm(SecurityDescriptor); } - FileOptions Options = 0 != (CreateOptions & FILE_DELETE_ON_CLOSE) ? - FileOptions.DeleteOnClose : 0; FileDesc = new FileDesc( new System.IO.FileInfo(FileName), new FileStream( @@ -184,7 +191,7 @@ namespace passthrough (FileSystemRights)GrantedAccess, FileShare.Read | FileShare.Write | FileShare.Delete, 4096, - Options, + 0, Security)); } FileDesc.FileAttributes = FileAttributes; @@ -206,15 +213,12 @@ namespace passthrough FileName = ConcatPath(FileName); if (Directory.Exists(FileName)) { - // ???: FILE_DELETE_ON_CLOSE FileDesc = new FileDesc( new System.IO.DirectoryInfo(FileName), null); } else { - FileOptions Options = 0 != (CreateOptions & FILE_DELETE_ON_CLOSE) ? - FileOptions.DeleteOnClose : 0; FileDesc = new FileDesc( new System.IO.FileInfo(FileName), new FileStream( @@ -223,7 +227,7 @@ namespace passthrough (FileSystemRights)GrantedAccess, FileShare.Read | FileShare.Write | FileShare.Delete, 4096, - Options)); + 0)); } FileNode = default(Object); FileDesc0 = FileDesc; @@ -254,7 +258,21 @@ namespace passthrough { FileDesc FileDesc = (FileDesc)FileDesc0; if (0 != (Flags & CleanupDelete)) - FileDesc.Stream.Dispose(); + { + FileName = ConcatPath(FileName); + try + { + if (null == FileDesc.Stream) + Directory.Delete(FileName); + else + FileDesc.Stream.Dispose(); + } + catch + { + } + if (null != FileDesc.Stream) + FileDesc.Stream.Dispose(); + } } protected override void Close( Object FileNode, @@ -411,7 +429,7 @@ namespace passthrough if (null == FileDesc.Stream) { if (ReplaceIfExists) - return STATUS_ACCESS_DENIED; + throw new UnauthorizedAccessException(); Directory.Move(FileName, NewFileName); } else