Skip to content

Commit

Permalink
get last error before calling a method that might fail as well (dotne…
Browse files Browse the repository at this point in the history
  • Loading branch information
adamsitnik authored Jun 24, 2021
1 parent 7833828 commit 72deae8
Showing 1 changed file with 3 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ private static SafeFileHandle Open(string path, Interop.Sys.OpenFlags flags, int

if (handle.IsInvalid)
{
handle.Dispose();
Interop.ErrorInfo error = Interop.Sys.GetLastErrorInfo();
handle.Dispose();

// If we fail to open the file due to a path not existing, we need to know whether to blame
// the file itself or its directory. If we're creating the file, then we blame the directory,
Expand All @@ -70,8 +70,9 @@ private static SafeFileHandle Open(string path, Interop.Sys.OpenFlags flags, int
Interop.Sys.FileStatus status;
if (Interop.Sys.FStat(handle, out status) != 0)
{
Interop.ErrorInfo error = Interop.Sys.GetLastErrorInfo();
handle.Dispose();
throw Interop.GetExceptionForIoErrno(Interop.Sys.GetLastErrorInfo(), path);
throw Interop.GetExceptionForIoErrno(error, path);
}
if ((status.Mode & Interop.Sys.FileTypes.S_IFMT) == Interop.Sys.FileTypes.S_IFDIR)
{
Expand Down

0 comments on commit 72deae8

Please sign in to comment.