2004-05-31 Atsushi Enomoto <atsushi@ximian.com>
authorAtsushi Eno <atsushieno@gmail.com>
Mon, 31 May 2004 16:44:03 +0000 (16:44 -0000)
committerAtsushi Eno <atsushieno@gmail.com>
Mon, 31 May 2004 16:44:03 +0000 (16:44 -0000)
* Directory.cs, File.cs : Fixed Exists() that raised
  DirectoryNotFoundException. Quick fix for bug #59354.

svn path=/trunk/mcs/; revision=28557

mcs/class/corlib/System.IO/ChangeLog
mcs/class/corlib/System.IO/Directory.cs
mcs/class/corlib/System.IO/File.cs

index 3ea62e08f7cc8147239e529bd5530c21be0c2cb6..f433a3ec8fc55f192a41c07b8fb185cb3547085f 100644 (file)
@@ -1,3 +1,8 @@
+2004-05-31  Atsushi Enomoto  <atsushi@ximian.com>
+
+       * Directory.cs, File.cs : Fixed Exists() that raised 
+         DirectoryNotFoundException. Quick fix for bug #59354.
+
 2004-05-30  Sebastien Pouliot  <sebastien@ximian.com>
 
        * BinaryReader.cs: Added missing disposed check for most methods. 
index f7dc0c82c68099022a83368293110f0ded14febb..f6995e9fcb5550646426201fd7fc50da0ff906e0 100644 (file)
@@ -131,19 +131,23 @@ namespace System.IO
 
                public static bool Exists (string path)
                {
-                       if (path == null)
-                               return false;
+                       try {
+                               if (path == null)
+                                       return false;
                                
-                       MonoIOError error;
-                       bool exists;
+                               MonoIOError error;
+                               bool exists;
                        
-                       exists = MonoIO.ExistsDirectory (path, out error);
-                       if (error != MonoIOError.ERROR_SUCCESS &&
-                           error != MonoIOError.ERROR_PATH_NOT_FOUND) {
-                               throw MonoIO.GetException (path, error);
-                       }
+                               exists = MonoIO.ExistsDirectory (path, out error);
+                               if (error != MonoIOError.ERROR_SUCCESS &&
+                                   error != MonoIOError.ERROR_PATH_NOT_FOUND) {
+                                       throw MonoIO.GetException (path, error);
+                               }
 
-                       return(exists);
+                               return(exists);
+                       } catch (Exception) {
+                               return false;
+                       }
                }
 
                public static DateTime GetLastAccessTime (string path)
index 3629aea0f1873c063c2d74ce983e430391704bf5..888f1cfe96a0f5dcea9dceb16fb654a13b3f8ee6 100644 (file)
@@ -129,26 +129,30 @@ namespace System.IO
 
                public static bool Exists (string path)
                {
-                       // For security reasons no exceptions are
-                       // thrown, only false is returned if there is
-                       // any problem with the path or permissions.
-                       // Minimizes what information can be
-                       // discovered by using this method.
-                       if (null == path || String.Empty == path.Trim()
-                           || path.IndexOfAny(Path.InvalidPathChars) >= 0) {
-                               return false;
-                       }
-
-                       MonoIOError error;
-                       bool exists;
+                       try {
+                               // For security reasons no exceptions are
+                               // thrown, only false is returned if there is
+                               // any problem with the path or permissions.
+                               // Minimizes what information can be
+                               // discovered by using this method.
+                               if (null == path || String.Empty == path.Trim()
+                                   || path.IndexOfAny(Path.InvalidPathChars) >= 0) {
+                                       return false;
+                               }
+
+                               MonoIOError error;
+                               bool exists;
                        
-                       exists = MonoIO.ExistsFile (path, out error);
-                       if (error != MonoIOError.ERROR_SUCCESS &&
-                           error != MonoIOError.ERROR_FILE_NOT_FOUND) {
-                               throw MonoIO.GetException (path, error);
+                               exists = MonoIO.ExistsFile (path, out error);
+                               if (error != MonoIOError.ERROR_SUCCESS &&
+                                   error != MonoIOError.ERROR_FILE_NOT_FOUND) {
+                                       throw MonoIO.GetException (path, error);
+                               }
+
+                               return(exists);
+                       } catch (Exception) {
+                               return false;
                        }
-
-                       return(exists);
                }
 
                public static FileAttributes GetAttributes (string path)