Nobuyoshi Nakada
4/18/2007 2:42:00 AM
Hi,
At Wed, 18 Apr 2007 06:44:30 +0900,
Elliott Hughes wrote in [ruby-talk:248288]:
> evaluation
> -------------
>
> stat(2)/lstat(2) can return ENOTDIR if a non-leaf element of
> the path they're given is not a directory.
> this is a fairly common case when people are using globbing
> as a cheap way of finding files at a fixed depth below a
> given directory.
Thank you.
> it might also be worth a code comment, since it's not likely
> to be immediately obvious to most readers that
> stat(2)/lstat(2) can return ENOTDIR.
What about this? The comment was borrowed from your post.
Index: dir.c
===================================================================
--- dir.c (revision 12191)
+++ dir.c (working copy)
@@ -929,4 +929,10 @@ sys_warning_1(const char* mesg)
#define GLOB_JUMP_TAG(status) ((status == -1) ? rb_memerror() : rb_jump_tag(status))
+/*
+ * ENOTDIR can return even if a non-leaf element of the path is not a
+ * directory.
+ */
+#define to_be_ignored(e) ((e) == ENOENT || (e) == ENOTDIR)
+
/* System call with warning */
static int
@@ -935,5 +941,5 @@ do_stat(const char *path, struct stat *p
{
int ret = stat(path, pst);
- if (ret < 0 && errno != ENOENT)
+ if (ret < 0 && !to_be_ignored(errno))
sys_warning(path);
@@ -945,5 +951,5 @@ do_lstat(const char *path, struct stat *
{
int ret = lstat(path, pst);
- if (ret < 0 && errno != ENOENT)
+ if (ret < 0 && !to_be_ignored(errno))
sys_warning(path);
@@ -955,5 +961,5 @@ do_opendir(const char *path, int flags)
{
DIR *dirp = opendir(path);
- if (dirp == NULL && errno != ENOENT && errno != ENOTDIR)
+ if (dirp == NULL && !to_be_ignored(errno))
sys_warning(path);
--
Nobu Nakada