ソースを参照

2008-03-28 Sebastien Pouliot <[email protected]>

	* IsolatedStorageFile.cs: Don't show the full path on exception if a 
	directory can't be created (fix bug #354539). Also fix path/patterns when
	looking for files (it behave differently than DirectoryInfo does).


svn path=/trunk/mcs/; revision=99231
Sebastien Pouliot 18 年 前
コミット
b79a9d5847

+ 6 - 0
mcs/class/corlib/System.IO.IsolatedStorage/ChangeLog

@@ -1,3 +1,9 @@
+2008-03-28  Sebastien Pouliot  <[email protected]>
+
+	* IsolatedStorageFile.cs: Don't show the full path on exception if a 
+	directory can't be created (fix bug #354539). Also fix path/patterns when
+	looking for files (it behave differently than DirectoryInfo does).
+
 2008-01-17  Sebastien Pouliot  <[email protected]>
 
 	* IsolatedStorageFile.cs: Fix bug #354539

+ 27 - 2
mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFile.cs

@@ -453,7 +453,11 @@ namespace System.IO.IsolatedStorage {
 
 		public void CreateDirectory (string dir)
 		{
-			directory.CreateSubdirectory (dir);	
+			if (dir == null)
+				throw new ArgumentNullException ("dir");
+			if (directory.GetFiles (dir).Length > 0)
+				throw new IOException (Locale.GetText ("Directory name already exists as a file."));
+			directory.CreateSubdirectory (dir);
 		}
 
 		public void DeleteDirectory (string dir)
@@ -489,7 +493,28 @@ namespace System.IO.IsolatedStorage {
 
 		public string[] GetFileNames (string searchPattern)
 		{
-			FileInfo[] afi = directory.GetFiles (searchPattern);
+			if (searchPattern == null)
+				throw new ArgumentNullException ("searchPattern");
+
+			// note: IsolatedStorageFile accept a "dir/file" pattern which is not allowed by DirectoryInfo
+			// so we need to split them to get the right results
+			string path = Path.GetDirectoryName (searchPattern);
+			string pattern = Path.GetFileName (searchPattern);
+			FileInfo[] afi = null;
+			if (path == null || path.Length == 0) {
+				afi = directory.GetFiles (searchPattern);
+			} else {
+				DirectoryInfo[] subdirs = directory.GetDirectories (path);
+				// we're looking for a single result, identical to path (no pattern here)
+				// we're also looking for something under the current path (not outside isolated storage)
+				if ((subdirs.Length == 1) && (subdirs [0].Name == path) && (subdirs [0].FullName.IndexOf (directory.FullName) >= 0)) {
+					afi = subdirs [0].GetFiles (pattern);
+				} else {
+					// CAS, even in FullTrust, normally enforce IsolatedStorage
+					throw new SecurityException ();
+				}
+			}
+
 			return GetNames (afi);
 		}