Commit 44ae1364 authored by Eli Zaretskii's avatar Eli Zaretskii

Fix error messages when readdir cannot open a directory on MS-Windows

 src/dired.c (read_dirent): Accept an additional argument
 FIRST_ENTRY.  If readdir fails with ENOENT or EACCES the first
 time it is called, report the error as if it happened in
 open_directory.
 (directory_files_internal, file_name_completion): Adjust callers
 or read_dirent.
parent d7adc7d9
2015-01-30 Eli Zaretskii <eliz@gnu.org>
* dired.c (read_dirent): Accept an additional argument
FIRST_ENTRY. If readdir fails with ENOENT or EACCES the first
time it is called, report the error as if it happened in
open_directory.
(directory_files_internal, file_name_completion): Adjust callers
or read_dirent.
2015-01-30 Paul Eggert <eggert@cs.ucla.edu> 2015-01-30 Paul Eggert <eggert@cs.ucla.edu>
Refactor calls to opendir for simplicity Refactor calls to opendir for simplicity
......
...@@ -124,10 +124,11 @@ directory_files_internal_unwind (void *dh) ...@@ -124,10 +124,11 @@ directory_files_internal_unwind (void *dh)
/* Return the next directory entry from DIR; DIR's name is DIRNAME. /* Return the next directory entry from DIR; DIR's name is DIRNAME.
If there are no more directory entries, return a null pointer. If there are no more directory entries, return a null pointer.
Signal any unrecoverable errors. */ Signal any unrecoverable errors. FIRST_ENTRY true means this is
the first call after open_directory. */
static struct dirent * static struct dirent *
read_dirent (DIR *dir, Lisp_Object dirname) read_dirent (DIR *dir, Lisp_Object dirname, bool first_entry)
{ {
while (true) while (true)
{ {
...@@ -136,7 +137,16 @@ read_dirent (DIR *dir, Lisp_Object dirname) ...@@ -136,7 +137,16 @@ read_dirent (DIR *dir, Lisp_Object dirname)
if (dp || errno == 0) if (dp || errno == 0)
return dp; return dp;
if (! (errno == EAGAIN || errno == EINTR)) if (! (errno == EAGAIN || errno == EINTR))
report_file_error ("Reading directory", dirname); {
/* 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 ENOENT or EACCES, see w32.c. */
if (first_entry && (errno == ENOENT || errno == EACCES))
report_file_error ("Opening directory", dirname);
else
report_file_error ("Reading directory", dirname);
}
QUIT; QUIT;
} }
} }
...@@ -239,7 +249,8 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full, ...@@ -239,7 +249,8 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full,
needsep = 1; needsep = 1;
/* Loop reading directory entries. */ /* Loop reading directory entries. */
for (struct dirent *dp; (dp = read_dirent (d, directory)); ) bool first_entry = true;
for (struct dirent *dp; (dp = read_dirent (d, directory, first_entry)); )
{ {
ptrdiff_t len = dirent_namelen (dp); ptrdiff_t len = dirent_namelen (dp);
Lisp_Object name = make_unibyte_string (dp->d_name, len); Lisp_Object name = make_unibyte_string (dp->d_name, len);
...@@ -247,6 +258,8 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full, ...@@ -247,6 +258,8 @@ directory_files_internal (Lisp_Object directory, Lisp_Object full,
struct gcpro gcpro1, gcpro2; struct gcpro gcpro1, gcpro2;
GCPRO2 (finalname, name); GCPRO2 (finalname, name);
first_entry = false;
/* Note: DECODE_FILE can GC; it should protect its argument, /* Note: DECODE_FILE can GC; it should protect its argument,
though. */ though. */
name = DECODE_FILE (name); name = DECODE_FILE (name);
...@@ -486,11 +499,13 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag, ...@@ -486,11 +499,13 @@ file_name_completion (Lisp_Object file, Lisp_Object dirname, bool all_flag,
record_unwind_protect_ptr (directory_files_internal_unwind, d); record_unwind_protect_ptr (directory_files_internal_unwind, d);
/* Loop reading directory entries. */ /* Loop reading directory entries. */
for (struct dirent *dp; (dp = read_dirent (d, dirname)); ) bool first_entry = true;
for (struct dirent *dp; (dp = read_dirent (d, dirname, first_entry)); )
{ {
ptrdiff_t len = dirent_namelen (dp); ptrdiff_t len = dirent_namelen (dp);
bool canexclude = 0; bool canexclude = 0;
first_entry = false;
QUIT; QUIT;
if (len < SCHARS (encoded_file) if (len < SCHARS (encoded_file)
|| (scmp (dp->d_name, SSDATA (encoded_file), || (scmp (dp->d_name, SSDATA (encoded_file),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment