From 50dc093d6b8d798e5703d33f7756071f23412c75 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 8 Aug 2017 08:34:10 +0000 Subject: dir.c: fix up r59481 for old kernels * dir.c (glob_helper): fix up r59481 for old kernels, which provide d_type member but just always set DT_UNKNOWN for any entries. [ruby-core:82266] [Bug #13785] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59527 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- dir.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/dir.c b/dir.c index 5ab88144c1..39f1ca0252 100644 --- a/dir.c +++ b/dir.c @@ -2021,6 +2021,7 @@ glob_helper( /* unless DOTMATCH, skip current directories not to recurse infinitely */ if (!(flags & FNM_DOTMATCH)) continue; ++dotfile; + new_pathtype = path_directory; /* force to skip stat/lstat */ } else if (namlen == 2 && name[1] == '.') { /* always skip parent directories not to recurse infinitely */ @@ -2042,12 +2043,14 @@ glob_helper( break; } name = buf + pathlen + (dirsep != 0); - if (dotfile < ((flags & FNM_DOTMATCH) ? 2 : 1) && #ifdef DT_UNKNOWN - ((new_pathtype = dp->d_type) == (rb_pathtype_t)DT_UNKNOWN) && - /* fall back to call lstat(2) */ + if (dp->d_type != DT_UNKNOWN) { + /* Got it. We need no more lstat. */ + new_pathtype = dp->d_type; + } #endif - recursive) { + if (recursive && dotfile < ((flags & FNM_DOTMATCH) ? 2 : 1) && + new_pathtype == path_unknown) { /* RECURSIVE never match dot files unless FNM_DOTMATCH is set */ if (do_lstat(fd, buf, &st, flags, enc) == 0) new_pathtype = IFTODT(st.st_mode); @@ -2066,8 +2069,9 @@ glob_helper( struct glob_pattern *p = *cur; if (p->type == RECURSIVE) { if (new_pathtype == path_directory || /* not symlink but real directory */ - new_pathtype == path_exist) - *new_end++ = p; /* append recursive pattern */ + new_pathtype == path_exist) { + if (dotfile < 2) *new_end++ = p; /* append recursive pattern */ + } p = p->next; /* 0 times recursion */ } switch (p->type) { -- cgit v1.2.3