From: Elliott Hughes Date: 2007-04-18T11:47:12+09:00 Subject: Re: [BUG] accidental Dir.glob behavior change in 1.8.6 looks good. i like the idea of factoring out the repeated test, too. that's nicer than what i did. actually i think you missed a couple of words in the comment. maybe something like this? +/* + * ENOTDIR can be returned by stat(2) if a non-leaf element of the path + * is not a directory. + */ btw, was this the right place to report a bug? there was no obvious link on http://www.ruby-lang.org/en/ and searching that site for "bug database" came back with 0 matches. -- Elliott Hughes, BlueArc Engineering -----Original Message----- From: Nobuyoshi Nakada [mailto:nobu@ruby-lang.org] Sent: 2007-04-17 19:42 To: ruby-talk ML Subject: Re: [BUG] accidental Dir.glob behavior change in 1.8.6 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