From fb6763a1c4e512c4bccd2303520bd55e815ffd51 Mon Sep 17 00:00:00 2001 From: =?utf8?q?D=C3=A1vid=20Kaya?= Date: Sat, 4 May 2019 04:50:13 +0200 Subject: [PATCH] Changed File.Copy to throw if destination is a directory on macOS (dotnet/corefx#36713) (dotnet/corefx#37428) Commit migrated from https://github.com/dotnet/corefx/commit/e21c2b5af100dc5d70ef1777f5de21d0d5a96210 --- src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs | 5 ++--- src/libraries/System.IO.FileSystem/tests/File/Copy.cs | 3 ++- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs b/src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs index 71fd183..322db16 100644 --- a/src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs +++ b/src/libraries/System.IO.FileSystem/src/System/IO/FileSystem.Unix.cs @@ -14,11 +14,10 @@ namespace System.IO public static void CopyFile(string sourceFullPath, string destFullPath, bool overwrite) { - // The destination path may just be a directory into which the file should be copied. - // If it is, append the filename from the source onto the destination directory + // If the destination path points to a directory, we throw to match Windows behaviour if (DirectoryExists(destFullPath)) { - destFullPath = Path.Combine(destFullPath, Path.GetFileName(sourceFullPath)); + throw new IOException(SR.Format(SR.Arg_FileIsDirectory_Name, destFullPath)); } // Copy the contents of the file from the source to the destination, creating the destination in the process diff --git a/src/libraries/System.IO.FileSystem/tests/File/Copy.cs b/src/libraries/System.IO.FileSystem/tests/File/Copy.cs index 1caca2a..b677a6e 100644 --- a/src/libraries/System.IO.FileSystem/tests/File/Copy.cs +++ b/src/libraries/System.IO.FileSystem/tests/File/Copy.cs @@ -35,8 +35,9 @@ namespace System.IO.Tests public void CopyOntoDirectory() { string testFile = GetTestFilePath(); + string targetTestDirectory = Directory.CreateDirectory(GetTestFilePath()).FullName; File.Create(testFile).Dispose(); - Assert.Throws(() => Copy(testFile, TestDirectory)); + Assert.Throws(() => Copy(testFile, targetTestDirectory)); } [Fact] -- 2.7.4