[前][次][番号順一覧][スレッド一覧]

ruby-changes:47412

From: nobu <ko1@a...>
Date: Tue, 8 Aug 2017 17:34:21 +0900 (JST)
Subject: [ruby-changes:47412] nobu:r59527 (trunk): dir.c: fix up r59481 for old kernels

nobu	2017-08-08 17:34:10 +0900 (Tue, 08 Aug 2017)

  New Revision: 59527

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=59527

  Log:
    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]

  Modified files:
    trunk/dir.c
Index: dir.c
===================================================================
--- dir.c	(revision 59526)
+++ dir.c	(revision 59527)
@@ -2021,6 +2021,7 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/dir.c#L2021
 		    /* 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( https://github.com/ruby/ruby/blob/trunk/dir.c#L2043
 		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( https://github.com/ruby/ruby/blob/trunk/dir.c#L2069
 		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) {

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]