[corlib] Handle CreateDirectory with relative paths. Fixes #40187
authorMarek Safar <marek.safar@gmail.com>
Tue, 12 Apr 2016 14:44:58 +0000 (16:44 +0200)
committerMarek Safar <marek.safar@gmail.com>
Tue, 12 Apr 2016 14:44:58 +0000 (16:44 +0200)
mcs/class/corlib/System.IO/Directory.cs
mcs/class/corlib/System.IO/DirectoryInfo.cs
mcs/class/corlib/Test/System.IO/DirectoryTest.cs

index f263eeb1cc9c5673811165cf436fbfb7693285ff..3c7e87a6b7ac78ad8fbe13e42343fb67337d0698 100644 (file)
@@ -96,7 +96,7 @@ namespace System.IO
                                 info.Parent.Create ();
 
                        MonoIOError error;
-                       if (!MonoIO.CreateDirectory (path, out error)) {
+                       if (!MonoIO.CreateDirectory (info.FullName, out error)) {
                                // LAMESPEC: 1.1 and 1.2alpha allow CreateDirectory on a file path.
                                // So CreateDirectory ("/tmp/somefile") will succeed if 'somefile' is
                                // not a directory. However, 1.0 will throw an exception.
index 8289c288c20ffe228d3133c28a4c4569bf05b9d1..4f74c12bf8309441d336ed37bed907003651547f 100644 (file)
@@ -62,7 +62,7 @@ namespace System.IO {
 
                        FullPath = Path.GetFullPath (path);
                        if (simpleOriginalPath)
-                               OriginalPath = Path.GetFileName (path);
+                               OriginalPath = Path.GetFileName (FullPath);
                        else
                                OriginalPath = path;
 
index b17cfd62c55c5724bea9f608fbbb058f4382471f..8ef9dcf4680b0a486793b9eb69a4abc518cf75a1 100644 (file)
@@ -230,6 +230,17 @@ public class DirectoryTest
                }\r
        }\r
 \r
+       [Test]\r
+       public void CreateDirectoryRelativePath ()\r
+       {\r
+               var path = Path.Combine (TempFolder, "relativepath", "not_this_folder");\r
+               path = Path.Combine (path, "..");\r
+\r
+               var res = Directory.CreateDirectory (path);\r
+               Assert.AreEqual ("relativepath", res.ToString (), "#1");\r
+               Assert.IsTrue (Directory.Exists (Path.Combine (TempFolder, "relativepath")), "#2");\r
+       }\r
+\r
        [Test]\r
        public void Delete ()\r
        {\r