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

ruby-changes:31306

From: nobu <ko1@a...>
Date: Tue, 22 Oct 2013 15:59:59 +0900 (JST)
Subject: [ruby-changes:31306] nobu:r43385 (trunk): dir.c: DOTMATCH to current directory

nobu	2013-10-22 15:59:54 +0900 (Tue, 22 Oct 2013)

  New Revision: 43385

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

  Log:
    dir.c: DOTMATCH to current directory
    
    * dir.c (glob_helper): don't skip current directories if FNM_DOTMATCH
      is given.  [ruby-core:53108] [Bug #8006]

  Modified files:
    trunk/ChangeLog
    trunk/dir.c
    trunk/test/ruby/test_dir.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43384)
+++ ChangeLog	(revision 43385)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Oct 22 15:59:51 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* dir.c (glob_helper): don't skip current directories if FNM_DOTMATCH
+	  is given.  [ruby-core:53108] [Bug #8006]
+
 Tue Oct 22 14:53:11 2013  Koichi Sasada  <ko1@a...>
 
 	* vm_trace.c: exterminate Zombies.
Index: dir.c
===================================================================
--- dir.c	(revision 43384)
+++ dir.c	(revision 43385)
@@ -1406,12 +1406,20 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/dir.c#L1406
 	    enum answer new_isdir = UNKNOWN;
 	    const char *name;
 	    size_t namlen;
+	    int dotfile = 0;
 	    IF_HAVE_HFS(VALUE utf8str = Qnil);
 
 	    if (recursive && dp->d_name[0] == '.') {
-		/* 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;
+		++dotfile;
+		if (!dp->d_name[1]) {
+		    /* unless DOTMATCH, skip current directories not to recurse infinitely */
+		    if (!(flags & FNM_DOTMATCH)) continue;
+		    ++dotfile;
+		}
+		else if (dp->d_name[1] == '.' && !dp->d_name[2]) {
+		    /* always skip parent directories not to recurse infinitely */
+		    continue;
+		}
 	    }
 
 	    name = dp->d_name;
@@ -1430,7 +1438,7 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/dir.c#L1438
 		break;
 	    }
 	    name = buf + pathlen + (dirsep != 0);
-	    if (recursive && ((flags & FNM_DOTMATCH) || dp->d_name[0] != '.')) {
+	    if (recursive && dotfile < ((flags & FNM_DOTMATCH) ? 2 : 1)) {
 		/* RECURSIVE never match dot files unless FNM_DOTMATCH is set */
 #ifndef _WIN32
 		if (do_lstat(buf, &st, flags) == 0)
Index: test/ruby/test_dir.rb
===================================================================
--- test/ruby/test_dir.rb	(revision 43384)
+++ test/ruby/test_dir.rb	(revision 43385)
@@ -152,7 +152,10 @@ class TestDir < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_dir.rb#L152
 
   def test_glob_recursive
     bug6977 = '[ruby-core:47418]'
+    bug8006 = '[ruby-core:53108] [Bug #8006]'
     Dir.chdir(@root) do
+      assert_include(Dir.glob("a/**/*", File::FNM_DOTMATCH), "a/.", bug8006)
+
       FileUtils.mkdir_p("a/b/c/d/e/f")
       assert_equal(["a/b/c/d/e/f"], Dir.glob("a/**/e/f"), bug6977)
       assert_equal(["a/b/c/d/e/f"], Dir.glob("a/**/d/e/f"), bug6977)

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

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