]> git.eshelyaron.com Git - emacs.git/commitdiff
Signal a file-error from directory-files on MS-Windows (Bug#19701)
authorEli Zaretskii <eliz@gnu.org>
Tue, 27 Jan 2015 19:02:13 +0000 (21:02 +0200)
committerEli Zaretskii <eliz@gnu.org>
Tue, 27 Jan 2015 19:02:13 +0000 (21:02 +0200)
 src/dired.c (directory_files_internal) [WINDOWSNT]: If readdir
 returns NULL and errno is ENOTDIR, behave as if opendir failed to
 open the directory.
 src/w32.c (sys_readdir): If FindFirstFile fails because the
 directory doesn't exist, set errno to ENOTDIR.

src/ChangeLog
src/dired.c
src/w32.c

index 9cf5eb591bbcc588b43f0e6907926c9e4cce6eb2..a33e834e0ec22e9472f4ef6dbd40aa9894cc1223 100644 (file)
@@ -1,3 +1,12 @@
+2015-01-27  Eli Zaretskii  <eliz@gnu.org>
+
+       * dired.c (directory_files_internal) [WINDOWSNT]: If readdir
+       returns NULL and errno is ENOTDIR, behave as if opendir failed to
+       open the directory.  (Bug#19701)
+
+       * w32.c (sys_readdir): If FindFirstFile fails because the
+       directory doesn't exist, set errno to ENOTDIR.
+
 2015-01-24  Jan Djärv  <jan.h.d@swipnet.se>
 
        * nsterm.m (drawRect:): Add block/unblock_input (Bug#19660).
index 5d7977bf0242c31b2f3c12718f9b8ca70edcb5cb..f6c47a7140017485c26f07b90854759260a32608 100644 (file)
@@ -247,6 +247,19 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full,
              QUIT;
              continue;
            }
+#ifdef WINDOWSNT
+         /* The MS-Windows implementation of 'opendir' doesn't
+            actually open a directory until the first call to
+            'readdir'.  If 'readdir' fails to open the directory, it
+            sets errno to ENOTDIR; we convert it here to ENOENT so
+            that the error message is similar to what happens on
+            Posix hosts in such cases.  */
+         if (errno == ENOTDIR)
+           {
+             errno = ENOENT;
+             report_file_error ("Opening directory", directory);
+           }
+#endif
          break;
        }
 
index 09902a2bb0d5719ba09fd6c7596f8ca7dcbfaf4c..aedf64942e09beaff23b6b1967eb01e9f1362d76 100644 (file)
--- a/src/w32.c
+++ b/src/w32.c
@@ -3432,7 +3432,22 @@ sys_readdir (DIR *dirp)
        }
 
       if (dir_find_handle == INVALID_HANDLE_VALUE)
-       return NULL;
+       {
+         switch (GetLastError ())
+           {
+           case ERROR_PATH_NOT_FOUND:
+           case ERROR_ACCESS_DENIED:
+           case ERROR_INVALID_DRIVE:
+           case ERROR_BAD_NETPATH:
+             /* This special value will be noticed by
+                directory_files_internal, which see.  */
+             errno = ENOTDIR;
+             break;
+           default:
+             break;
+           }
+         return NULL;
+       }
     }
   else if (w32_unicode_filenames)
     {