Fix IsolatedStorageFile directory creation/deletion with rooted paths. Fix bug #5011
authorSebastien Pouliot <sebastien@xamarin.com>
Tue, 22 May 2012 18:37:04 +0000 (14:37 -0400)
committerSebastien Pouliot <sebastien@xamarin.com>
Tue, 22 May 2012 18:37:13 +0000 (14:37 -0400)
mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFile.cs
mcs/class/corlib/Test/System.IO.IsolatedStorage/IsolatedStorageFileTest.cs

index 4bc72182f7679e586aab36bdc8021c1ff7a8f59d..47ce1efaa346a960c5e64e63d8380928ebf6a4af 100644 (file)
@@ -579,7 +579,7 @@ namespace System.IO.IsolatedStorage {
 #endif
                                directory.CreateSubdirectory (dir);
                        } else {
-                               string[] dirs = dir.Split (Path.PathSeparatorChars);
+                               string[] dirs = dir.Split (Path.PathSeparatorChars, StringSplitOptions.RemoveEmptyEntries);
                                DirectoryInfo dinfo = directory;
 
                                for (int i = 0; i < dirs.Length; i++) {
@@ -646,6 +646,8 @@ namespace System.IO.IsolatedStorage {
                public void DeleteDirectory (string dir)
                {
                        try {
+                               if (Path.IsPathRooted (dir))
+                                       dir = dir.Substring (1);
                                DirectoryInfo subdir = directory.CreateSubdirectory (dir);
                                subdir.Delete ();
                        }
index 224e3058d40f278367ac8af0c60c6719508d4132..10bf9bf136714c5f21bcb07ef21a0697cae110b3 100644 (file)
@@ -1119,5 +1119,25 @@ namespace MonoTests.System.IO.IsolatedStorageTest {
                        }
                }
 #endif
+               [Test]
+               public void RootedDirectory ()
+               {
+                       IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForAssembly ();
+                       try {
+                               isf.CreateDirectory ("test/nested/directory/structure/without/root");
+                               isf.CreateDirectory ("/test/nested/directory/structure/with/root");
+                       }
+                       finally {
+                               isf.DeleteDirectory ("test/nested/directory/structure/without/root");
+                               isf.DeleteDirectory ("test/nested/directory/structure/without");
+
+                               isf.DeleteDirectory ("/test/nested/directory/structure/with/root");
+                               isf.DeleteDirectory ("/test/nested/directory/structure/with");
+                               isf.DeleteDirectory ("/test/nested/directory/structure");
+                               isf.DeleteDirectory ("/test/nested/directory");
+                               isf.DeleteDirectory ("/test/nested");
+                               isf.DeleteDirectory ("/test");
+                       }
+               }
        }
 }