Your message dated Wed, 8 Oct 2008 00:08:58 +0200
with message-id <[EMAIL PROTECTED]>
and subject line RE: cloning of 498983
has caused the Debian Bug report #501505,
regarding DirectoryNotFoundException IsolatedStorageFile.GetFileNames() when 
using a sub-directory.
to be marked as done.

This means that you claim that the problem has been dealt with.
If this is not the case it is now your responsibility to reopen the
Bug report if necessary, and/or fix the problem forthwith.

(NB: If you are a system administrator and have no idea what this
message is talking about, this may indicate a serious mail system
misconfiguration somewhere. Please contact [EMAIL PROTECTED]
immediately.)


-- 
501505: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=501505
Debian Bug Tracking System
Contact [EMAIL PROTECTED] with problems
--- Begin Message ---
Package: libmono-corlib1.0-cil
Version: 1.9.1+dfsg-3
Severity: serious
Tags: patch

Creating and using subdirectories or files which are not in the top-level directory of isolated storage causes exceptions with the version of Mono in testing. This works as expected in stable.

Test case:

using System.IO;
using System.IO.IsolatedStorage;

namespace IsolatedStorageBug
{
    class TestCase
    {
        public static void Main()
        {
            string DirName = "Foo";
            string FileMask = DirName + Path.DirectorySeparatorChar + "*";
string SubdirName = DirName + Path.DirectorySeparatorChar + "Bar"; IsolatedStorageFile store = IsolatedStorageFile.GetUserStoreForAssembly();
            if (store.GetDirectoryNames(DirName).Length == 0)
                store.CreateDirectory(DirName);

            // First bug: fixed in SVN r99231
            store.GetFileNames(FileMask);

            // Second bug: fixed in SVN r101172
            if (store.GetDirectoryNames(SubdirName).Length == 0)
                store.CreateDirectory(SubdirName);

            store.DeleteDirectory(SubdirName);
            store.DeleteDirectory(DirName);
        }

    }
}

As noted, these issues are fixed in Mono SVN. Additionally, the second bug has a Novell Bugzilla entry: https://bugzilla.novell.com/show_bug.cgi?id=376188

As this is a regression from stable and there appears to be no workaround for using directories in isolated storage I've provisionally set the severity to serious. I'm not sure if this is the appropriate level.

Diffs for the noted revisions are attached. The GetFileNames, CreateDirectory and GetDirectoryNames hunks are the most relevant.

 - Sharif
--- trunk/mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFile.cs	2008/01/17 22:00:31	93209
+++ trunk/mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFile.cs	2008/03/28 19:09:25	99231
@@ -453,7 +453,11 @@
 
 		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 @@
 
 		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);
 		}
 
--- trunk/mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFile.cs	2008/03/28 19:09:25	99231
+++ trunk/mcs/class/corlib/System.IO.IsolatedStorage/IsolatedStorageFile.cs	2008/04/18 21:54:27	101172
@@ -455,15 +455,34 @@
 		{
 			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);
+
+			if (dir.IndexOfAny (Path.PathSeparatorChars) < 0) {
+				if (directory.GetFiles (dir).Length > 0)
+					throw new IOException (Locale.GetText ("Directory name already exists as a file."));
+				directory.CreateSubdirectory (dir);
+			} else {
+				string[] dirs = dir.Split (Path.PathSeparatorChars);
+				DirectoryInfo dinfo = directory;
+
+				for (int i = 0; i < dirs.Length; i++) {
+					if (dinfo.GetFiles (dirs [i]).Length > 0)
+						throw new IOException (Locale.GetText (
+							"Part of the directory name already exists as a file."));
+					dinfo = dinfo.CreateSubdirectory (dirs [i]);
+				}
+			}
 		}
 
 		public void DeleteDirectory (string dir)
 		{
-			DirectoryInfo subdir = directory.CreateSubdirectory (dir);
-			subdir.Delete ();
+			try {
+				DirectoryInfo subdir = directory.CreateSubdirectory (dir);
+				subdir.Delete ();
+			}
+			catch {
+				// hide the real exception to avoid leaking the full path
+				throw new IsolatedStorageException (Locale.GetText ("Could not delete directory '{0}'", dir));
+			}
 		}
 
 		public void DeleteFile (string file)
@@ -479,7 +498,28 @@
 
 		public string[] GetDirectoryNames (string searchPattern)
 		{
-			DirectoryInfo[] adi = directory.GetDirectories (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);
+			DirectoryInfo[] adi = null;
+			if (path == null || path.Length == 0) {
+				adi = directory.GetDirectories (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)) {
+					adi = subdirs [0].GetDirectories (pattern);
+				} else {
+					// CAS, even in FullTrust, normally enforce IsolatedStorage
+					throw new SecurityException ();
+				}
+			}
+			 
 			return GetNames (adi);
 		}
 

--- End Message ---
--- Begin Message ---
Actually it was a mistake to clone 498983, as the bug has the same
cause (not supporting sub-directories) with 2 different visible symptoms
(2 methods). So I am closing this one. Sorry for the noise.

-- 
Regards,

Mirco 'meebey' Bauer

PGP-Key ID: 0xEEF946C8

FOSS Developer    [EMAIL PROTECTED]  http://www.meebey.net/
PEAR Developer    [EMAIL PROTECTED]     http://pear.php.net/
Debian Developer  [EMAIL PROTECTED]  http://www.debian.org/


--- End Message ---

Reply via email to