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

ruby-changes:28293

From: nobu <ko1@a...>
Date: Thu, 18 Apr 2013 16:21:06 +0900 (JST)
Subject: [ruby-changes:28293] nobu:r40345 (trunk): dir.c: not skip dot directories if matching

nobu	2013-04-18 16:20:53 +0900 (Thu, 18 Apr 2013)

  New Revision: 40345

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

  Log:
    dir.c: not skip dot directories if matching
    
    * dir.c (glob_helper): should skip dot directories only for recursion,
      but should not if matching to the given pattern.  [ruby-core:54387]
      [Bug #8283]

  Modified files:
    trunk/ChangeLog
    trunk/dir.c
    trunk/test/ruby/test_dir.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 40344)
+++ ChangeLog	(revision 40345)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Thu Apr 18 16:20:51 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* dir.c (glob_helper): should skip dot directories only for recursion,
+	  but should not if matching to the given pattern.  [ruby-core:54387]
+	  [Bug #8283]
+
 Thu Apr 18 16:20:21 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* pack.c (pack_unpack): increase buffer size to fix buffer overflow,
Index: dir.c
===================================================================
--- dir.c	(revision 40344)
+++ dir.c	(revision 40345)
@@ -1434,9 +1434,6 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/dir.c#L1434
 	    IF_HAVE_HFS(VALUE utf8str = Qnil);
 
 	    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;
@@ -1461,7 +1458,8 @@ glob_helper( https://github.com/ruby/ruby/blob/trunk/dir.c#L1458
 		break;
 	    }
 	    name = buf + pathlen + (dirsep != 0);
-	    if (recursive) {
+	    if (recursive && ((flags & FNM_DOTMATCH) || dp->d_name[0] != '.')) {
+		/* RECURSIVE never match dot files unless FNM_DOTMATCH is set */
 #ifndef _WIN32
 		if (do_lstat(buf, &st, flags) == 0)
 		    new_isdir = S_ISDIR(st.st_mode) ? YES : S_ISLNK(st.st_mode) ? UNKNOWN : NO;
Index: test/ruby/test_dir.rb
===================================================================
--- test/ruby/test_dir.rb	(revision 40344)
+++ test/ruby/test_dir.rb	(revision 40345)
@@ -177,6 +177,15 @@ class TestDir < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_dir.rb#L177
       assert_equal(["a/b/c/d/e/f"], Dir.glob("a/**/c/?/e/f"), bug6977)
       assert_equal(["a/b/c/d/e/f"], Dir.glob("a/**/c/**/d/e/f"), bug6977)
       assert_equal(["a/b/c/d/e/f"], Dir.glob("a/**/c/**/d/e/f"), bug6977)
+
+      bug8283 = '[ruby-core:54387] [Bug #8283]'
+      dirs = ["a/.x", "a/b/.y"]
+      FileUtils.mkdir_p(dirs)
+      dirs.map {|dir| open("#{dir}/z", "w") {}}
+      assert_equal([], Dir.glob("a/**/z").sort, bug8283)
+      assert_equal(["a/.x/z"], Dir.glob("a/**/.x/z"), bug8283)
+      assert_equal(["a/.x/z"], Dir.glob("a/.x/**/z"), bug8283)
+      assert_equal(["a/b/.y/z"], Dir.glob("a/**/.y/z"), bug8283)
     end
   end
 

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

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