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]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43385 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2013-10-22 06:59:54 +00:00
parent 4ae79ade41
commit f57c988e34
3 changed files with 20 additions and 4 deletions

View File

@ -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.

16
dir.c
View File

@ -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)

View File

@ -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)