From 6359b6b6208bf91af31f168f55a481c8eb94768a Mon Sep 17 00:00:00 2001 From: Dick Porter Date: Thu, 6 Jul 2006 15:24:55 +0000 Subject: 2006-07-06 Dick Porter * Directory.cs: When creating a directory treat ERROR_FILE_EXISTS (ie a file already exists with that name) the same as ERROR_ALREADY_EXISTS (ie a directory already exists with that name.) Keeps bug 50753 fixed when I fix the io-layer CreateDirectory() behaviour. 2006-07-06 Dick Porter * DirectoryTest.cs: Test creating a directory when a file or directory already exists with the requested name. svn path=/branches/mono-1-1-13/mcs/; revision=62319 --- mcs/class/corlib/System.IO/ChangeLog | 8 +++++ mcs/class/corlib/System.IO/Directory.cs | 3 +- mcs/class/corlib/Test/System.IO/ChangeLog | 5 +++ mcs/class/corlib/Test/System.IO/DirectoryTest.cs | 43 ++++++++++++++++++++++++ 4 files changed, 58 insertions(+), 1 deletion(-) diff --git a/mcs/class/corlib/System.IO/ChangeLog b/mcs/class/corlib/System.IO/ChangeLog index ec9a240cada..9826447f25b 100644 --- a/mcs/class/corlib/System.IO/ChangeLog +++ b/mcs/class/corlib/System.IO/ChangeLog @@ -1,3 +1,11 @@ +2006-07-06 Dick Porter + + * Directory.cs: When creating a directory treat ERROR_FILE_EXISTS + (ie a file already exists with that name) the same as + ERROR_ALREADY_EXISTS (ie a directory already exists with that + name.) Keeps bug 50753 fixed when I fix the io-layer + CreateDirectory() behaviour. + 2006-04-29 Atsushi Enomoto * UnexceptionalStreamReader.cs (Read): Fix for #78218, where we diff --git a/mcs/class/corlib/System.IO/Directory.cs b/mcs/class/corlib/System.IO/Directory.cs index d212b28dd0e..6783bf2952f 100644 --- a/mcs/class/corlib/System.IO/Directory.cs +++ b/mcs/class/corlib/System.IO/Directory.cs @@ -101,7 +101,8 @@ namespace System.IO // and having di.Exists return false afterwards. // I hope we don't break anyone's code, as they should be catching // the exception anyway. - if (error != MonoIOError.ERROR_ALREADY_EXISTS) + if (error != MonoIOError.ERROR_ALREADY_EXISTS && + error != MonoIOError.ERROR_FILE_EXISTS) throw MonoIO.GetException (path, error); } diff --git a/mcs/class/corlib/Test/System.IO/ChangeLog b/mcs/class/corlib/Test/System.IO/ChangeLog index eab80c443be..e6deb5eb358 100644 --- a/mcs/class/corlib/Test/System.IO/ChangeLog +++ b/mcs/class/corlib/Test/System.IO/ChangeLog @@ -1,3 +1,8 @@ +2006-07-06 Dick Porter + + * DirectoryTest.cs: Test creating a directory when a file or + directory already exists with the requested name. + 2006-03-21 Gonzalo Paniagua Javier * FileStreamTest.cs: new test from bug #77863. diff --git a/mcs/class/corlib/Test/System.IO/DirectoryTest.cs b/mcs/class/corlib/Test/System.IO/DirectoryTest.cs index c2d3ce6e4b9..e0082718491 100644 --- a/mcs/class/corlib/Test/System.IO/DirectoryTest.cs +++ b/mcs/class/corlib/Test/System.IO/DirectoryTest.cs @@ -100,6 +100,43 @@ public class DirectoryTest : Assertion { } } + [Test] + public void CreateDirectoryAlreadyExists () + { + string path = TempFolder + DSC + "DirectoryTest.Test.Exists"; + DeleteDirectory (path); + try { + DirectoryInfo info1 = Directory.CreateDirectory (path); + DirectoryInfo info2 = Directory.CreateDirectory (path); + + AssertEquals ("test#01", true, info2.Exists); + AssertEquals ("test#02", true, info2.FullName.EndsWith ("DirectoryTest.Test.Exists")); + AssertEquals ("test#03", "DirectoryTest.Test.Exists", info2.Name); + } finally { + DeleteDirectory (path); + } + } + + [Test] + public void CreateDirectoryAlreadyExistsAsFile () + { + string path = TempFolder + DSC + "DirectoryTest.Test.ExistsAsFile"; + DeleteDirectory (path); + DeleteFile (path); + try { + FileStream fstream = File.Create (path); + fstream.Close(); + + DirectoryInfo dinfo = Directory.CreateDirectory (path); + AssertEquals ("test#01", false, dinfo.Exists); + AssertEquals ("test#02", true, dinfo.FullName.EndsWith ("DirectoryTest.Test.ExistsAsFile")); + AssertEquals ("test#03", "DirectoryTest.Test.ExistsAsFile", dinfo.Name); + } finally { + DeleteDirectory (path); + DeleteFile (path); + } + } + [Test] public void Delete () { @@ -1192,5 +1229,11 @@ public class DirectoryTest : Assertion { if (Directory.Exists (path)) Directory.Delete (path, true); } + + private void DeleteFile (string path) + { + if (File.Exists (path)) + File.Delete (path); + } } } -- cgit v1.2.3