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

ruby-changes:24852

From: nobu <ko1@a...>
Date: Wed, 5 Sep 2012 10:44:46 +0900 (JST)
Subject: [ruby-changes:24852] nobu:r36903 (trunk): dir.c: not recurse dot files

nobu	2012-09-05 10:44:36 +0900 (Wed, 05 Sep 2012)

  New Revision: 36903

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=36903

  Log:
    dir.c: not recurse dot files
    
    * dir.c (glob_helper): skip dot files early on recursive match.

  Modified files:
    trunk/dir.c

Index: dir.c
===================================================================
--- dir.c	(revision 36902)
+++ dir.c	(revision 36903)
@@ -1379,15 +1379,24 @@
 	if (dirp == NULL) return 0;
 
 	while (READDIR(dirp, enc, &STRUCT_DIRENT(entry), dp)) {
-	    char *buf = join_path(path, dirsep, dp->d_name);
+	    char *buf;
 	    enum answer new_isdir = UNKNOWN;
 
+	    if (recursive && dp->d_name[0] == '.') {
+		/* RECURSIVE never match dot files unless FNM_DOTMATCH is set */
+		if (!(flags & FNM_DOTMATCH)) continue;
+
+		/* always skip current and parent directories not to recurse infinitely */
+		if (!dp->d_name[1]) continue;
+		if (dp->d_name[1] == '.' && !dp->d_name[2]) continue;
+	    }
+
+	    buf = join_path(path, dirsep, dp->d_name);
 	    if (!buf) {
 		status = -1;
 		break;
 	    }
-	    if (recursive && strcmp(dp->d_name, ".") != 0 && strcmp(dp->d_name, "..") != 0
-		&& fnmatch("*", rb_usascii_encoding(), dp->d_name, flags) == 0) {
+	    if (recursive) {
 #ifndef _WIN32
 		if (do_lstat(buf, &st, flags) == 0)
 		    new_isdir = S_ISDIR(st.st_mode) ? YES : S_ISLNK(st.st_mode) ? UNKNOWN : NO;

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

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