Ignore:
Timestamp:
3/1/2010 9:52:43 AM (5 years ago)
Author:
lowjoel
Message:

Don't double error-handle in VolumeInfo?: The OpenHandle? and Open functions check for a valid file handle each, which is redundant. Since OpenHandle? is supposed to be called internally from the assembly, do no error checking and assume the calling function knows what it is doing. This can be seen in NtfsApi? where an exception has been replaced with an if-statement.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/eraser6/Eraser.Util/VolumeInfo.cs

    r1867 r1873  
    620620            //Check that the handle is valid 
    621621            if (handle.IsInvalid) 
    622                 throw Win32ErrorCode.GetExceptionForWin32Error(Marshal.GetLastWin32Error()); 
     622            { 
     623                int errorCode = Marshal.GetLastWin32Error(); 
     624                handle.Close(); 
     625                throw Win32ErrorCode.GetExceptionForWin32Error(errorCode); 
     626            } 
    623627 
    624628            //Return the FileStream 
     
    660664            if (openPath.Length > 0 && openPath[openPath.Length - 1] == '\\') 
    661665                openPath = openPath.Remove(openPath.Length - 1); 
    662             SafeFileHandle result = NativeMethods.CreateFile(openPath, access, 
    663                 (uint)share, IntPtr.Zero, (uint)FileMode.Open, (uint)options, IntPtr.Zero); 
    664             if (result.IsInvalid) 
    665             { 
    666                 int errorCode = Marshal.GetLastWin32Error(); 
    667                 result.Close(); 
    668                 throw Win32ErrorCode.GetExceptionForWin32Error(errorCode); 
    669             } 
    670  
    671             return result; 
     666            return NativeMethods.CreateFile(openPath, access, (uint)share, IntPtr.Zero, 
     667                (uint)FileMode.Open, (uint)options, IntPtr.Zero); 
    672668        } 
    673669 
Note: See TracChangeset for help on using the changeset viewer.