summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-22 06:59:54 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-10-22 06:59:54 +0000
commitf57c988e343a4d682d3a988127b0552dde3caf3e (patch)
treef1992e7887b122a0297c6a44bf741e48c3cbe2a6 /dir.c
parent4ae79ade414c7e54a6b044e5569233bd688d7b97 (diff)
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
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c16
1 files changed, 12 insertions, 4 deletions
diff --git a/dir.c b/dir.c
index 3844087..d168190 100644
--- a/dir.c
+++ b/dir.c
@@ -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)