diff options
-rw-r--r-- | ChangeLog | 5 | ||||
-rw-r--r-- | dir.c | 16 | ||||
-rw-r--r-- | test/ruby/test_dir.rb | 3 |
3 files changed, 20 insertions, 4 deletions
@@ -1,3 +1,8 @@ +Tue Oct 22 15:59:51 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * 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@atdot.net> * vm_trace.c: exterminate Zombies. @@ -1406,12 +1406,20 @@ glob_helper( 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( 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) diff --git a/test/ruby/test_dir.rb b/test/ruby/test_dir.rb index 91fbf35c45..0948ae748d 100644 --- a/test/ruby/test_dir.rb +++ b/test/ruby/test_dir.rb @@ -152,7 +152,10 @@ class TestDir < Test::Unit::TestCase 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) |