summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-08 08:34:10 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-08 08:34:10 (GMT)
commit50dc093d6b8d798e5703d33f7756071f23412c75 (patch)
treee3c4ced35e9deb55c74923141da4d18ede0ffa53 /dir.c
parent243d188f7c2b6cbd4ed3ba5e75b6952e0b8d13a9 (diff)
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
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c16
1 files changed, 10 insertions, 6 deletions
diff --git a/dir.c b/dir.c
index 5ab8814..39f1ca0 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) {