From b88008d56cac7b8dc22e812e761cd68ccb853fc6 Mon Sep 17 00:00:00 2001 From: Steve Berdy Date: Wed, 14 Jul 2021 12:48:36 -0400 Subject: [PATCH] Removed sourceFullPath from Unix FileSystem.MoveDirectory thrown exception --- .../src/System/IO/Directory.cs | 2 +- .../src/System/IO/FileSystem.Unix.cs | 4 ++-- .../src/System/IO/FileSystem.Windows.cs | 23 ++++++++++--------- 3 files changed, 15 insertions(+), 14 deletions(-) diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/Directory.cs b/src/libraries/System.Private.CoreLib/src/System/IO/Directory.cs index f6bc4f42b064d..9768c16248dfd 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/Directory.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/Directory.cs @@ -288,7 +288,7 @@ public static void Move(string sourceDirName, string destDirName) if (!FileSystem.DirectoryExists(fullsourceDirName) && !FileSystem.FileExists(fullsourceDirName)) throw new DirectoryNotFoundException(SR.Format(SR.IO_PathNotFound_Path, fullsourceDirName)); - if (!sameDirectoryDifferentCase // This check is to allowing renaming of directories + if (!sameDirectoryDifferentCase // This check is to allow renaming of directories && FileSystem.DirectoryExists(fulldestDirName)) throw new IOException(SR.Format(SR.IO_AlreadyExists_Name, fulldestDirName)); diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs b/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs index 0151499893aa8..43111fb81ae01 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Unix.cs @@ -380,7 +380,7 @@ public static void MoveDirectory(string sourceFullPath, string destFullPath) // On Windows we end up with ERROR_INVALID_NAME, which is // "The filename, directory name, or volume label syntax is incorrect." // - // This surfaces as a IOException, if we let it go beyond here it would + // This surfaces as an IOException, if we let it go beyond here it would // give DirectoryNotFound. if (Path.EndsInDirectorySeparator(sourceFullPath)) @@ -405,7 +405,7 @@ public static void MoveDirectory(string sourceFullPath, string destFullPath) case Interop.Error.EACCES: // match Win32 exception throw new IOException(SR.Format(SR.UnauthorizedAccess_IODenied_Path, sourceFullPath), errorInfo.RawErrno); default: - throw Interop.GetExceptionForIoErrno(errorInfo, sourceFullPath, isDirectory: true); + throw Interop.GetExceptionForIoErrno(errorInfo, isDirectory: true); } } } diff --git a/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Windows.cs b/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Windows.cs index 5f88f53a7c539..43a5084e1765d 100644 --- a/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Windows.cs +++ b/src/libraries/System.Private.CoreLib/src/System/IO/FileSystem.Windows.cs @@ -123,17 +123,18 @@ public static void MoveDirectory(string sourceFullPath, string destFullPath) { int errorCode = Marshal.GetLastWin32Error(); - if (errorCode == Interop.Errors.ERROR_FILE_NOT_FOUND) - throw Win32Marshal.GetExceptionForWin32Error(Interop.Errors.ERROR_PATH_NOT_FOUND, sourceFullPath); - - if (errorCode == Interop.Errors.ERROR_ALREADY_EXISTS) - throw Win32Marshal.GetExceptionForWin32Error(Interop.Errors.ERROR_ALREADY_EXISTS, destFullPath); - - // This check was originally put in for Win9x (unfortunately without special casing it to be for Win9x only). We can't change the NT codepath now for backcomp reasons. - if (errorCode == Interop.Errors.ERROR_ACCESS_DENIED) // WinNT throws IOException. This check is for Win9x. We can't change it for backcomp. - throw new IOException(SR.Format(SR.UnauthorizedAccess_IODenied_Path, sourceFullPath), Win32Marshal.MakeHRFromErrorCode(errorCode)); - - throw Win32Marshal.GetExceptionForWin32Error(errorCode); + switch (errorCode) + { + case Interop.Errors.ERROR_FILE_NOT_FOUND: + throw Win32Marshal.GetExceptionForWin32Error(Interop.Errors.ERROR_PATH_NOT_FOUND, sourceFullPath); + case Interop.Errors.ERROR_ALREADY_EXISTS: + throw Win32Marshal.GetExceptionForWin32Error(Interop.Errors.ERROR_ALREADY_EXISTS, destFullPath); + // This check was originally put in for Win9x (unfortunately without special casing it to be for Win9x only). We can't change the NT codepath now for backcomp reasons. + case Interop.Errors.ERROR_ACCESS_DENIED: // WinNT throws IOException. This check is for Win9x. We can't change it for backcomp. + throw new IOException(SR.Format(SR.UnauthorizedAccess_IODenied_Path, sourceFullPath), Win32Marshal.MakeHRFromErrorCode(errorCode)); + default: + throw Win32Marshal.GetExceptionForWin32Error(errorCode); + } } }