On 11/02/2020 19:41, Pádraig Brady wrote:
On 11/02/2020 10:45, Colin Watson wrote:
If the current directory has been removed, then "ls" confusingly
produced no output and no error message, indistinguishable from the case
of running on an empty directory. It makes more sense to report ENOENT
in this case.
I don't think this is a general solution as the opendir() spec states:
https://pubs.opengroup.org/onlinepubs/9699919799/functions/opendir.html
"The directory entries for dot and dot-dot are optional".
I've also seen reference to FUSE file systems that don't provide those entries.
In saying that, this is a common gotcha.
I wonder could we do something like:
+#ifdef __linux__
+ else if (! found_any_entries)
+ {
+ /* If readdir finds no directory entries at all, not even "." or
+ "..", then double check that the directory exists. */
+ char buf[1024];
+ if (syscall(SYS_getdents, dirfd (dirp), buf, sizeof buf) == -1)
+ {
+ file_failure (command_line_arg, _("reading directory %s"), name);
+ break;
+ }
+ }
+#endif