[runtime,IO] Filesystem entries can only be sought for in directories, not files.
authorMarek Habersack <grendel@twistedcode.net>
Wed, 13 Apr 2011 14:24:08 +0000 (16:24 +0200)
committerMarek Habersack <grendel@twistedcode.net>
Wed, 13 Apr 2011 14:56:37 +0000 (16:56 +0200)
mcs/class/corlib/System.IO/Directory.cs
mono/metadata/file-io.c

index d1617c6ac3919b0ea06e628224bc1adb6c9fe06d..6b426027e8e0c8a9e46a136626142b058526be31 100644 (file)
@@ -461,11 +461,9 @@ namespace System.IO
                        MonoIOError error;
                        if (!MonoIO.ExistsDirectory (wildpath, out error)) {
                                if (error == MonoIOError.ERROR_SUCCESS) {
-                                       MonoIOError file_error;
-                                       if (MonoIO.ExistsFile (wildpath, out file_error)) {
-                                               stop = true;
-                                               return wildpath;
-                                       }
+                                       MonoIOError file_error;
+                                       if (MonoIO.ExistsFile (wildpath, out file_error))
+                                               throw new IOException ("The directory name is invalid.");
                                }
 
                                if (error != MonoIOError.ERROR_PATH_NOT_FOUND)
index c52cbfabf780f207d5db58362492a073045e2d6f..e35680bc4b4a12a3e83bb59ff15976c3dcc9b2e4 100644 (file)
@@ -330,6 +330,7 @@ ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
        HANDLE find_handle;
        GPtrArray *names;
        gchar *utf8_path, *utf8_result, *full_name;
+       gint32 attributes;
        
        MONO_ARCH_SAVE_REGS;
 
@@ -337,9 +338,18 @@ ves_icall_System_IO_MonoIO_GetFileSystemEntries (MonoString *path,
 
        domain = mono_domain_get ();
        mask = convert_attrs (mask);
+       attributes = get_file_attributes (mono_string_chars (path));
+       if (attributes != -1) {
+               if ((attributes & FILE_ATTRIBUTE_DIRECTORY) == 0) {
+                       *error = ERROR_INVALID_NAME;
+                       return (NULL);
+               }
+       } else {
+               *error = GetLastError ();
+               return (NULL);
+       }
        
-       find_handle = FindFirstFile (mono_string_chars (path_with_pattern),
-                                    &data);
+       find_handle = FindFirstFile (mono_string_chars (path_with_pattern), &data);
        if (find_handle == INVALID_HANDLE_VALUE) {
                gint32 find_error = GetLastError ();