summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-09 15:15:17 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-02-09 15:15:17 +0000
commitc84397f441d109c0584c5630c80c0fe70b7ee7d7 (patch)
tree27309315723696741de0874270829fd5c400f527 /dir.c
parent24b531f9a16234f5f064ef9fb1536476c05017e8 (diff)
merge revision(s) 43385: [Backport #8006]
* 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/branches/ruby_2_0_0@44897 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 17192141e7..dd44190335 100644
--- a/dir.c
+++ b/dir.c
@@ -1388,11 +1388,19 @@ glob_helper(
while (READDIR(dirp, enc, &STRUCT_DIRENT(entry), dp)) {
char *buf;
enum answer new_isdir = UNKNOWN;
+ int dotfile = 0;
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;
+ }
}
buf = join_path(path, dirsep, dp->d_name, NAMLEN(dp));
@@ -1400,7 +1408,7 @@ glob_helper(
status = -1;
break;
}
- 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)