aboutsummaryrefslogtreecommitdiffstats
path: root/dir.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-09-05 01:44:36 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-09-05 01:44:36 +0000
commitf65e683ccc3b6689ac00e7c1fe0fd2c0384824b2 (patch)
tree100126997e4f5ddc53e883469dbf28e36409f845 /dir.c
parent9e9dff33421b3a16d2b0a710479fcdd1eb44c082 (diff)
downloadruby-f65e683ccc3b6689ac00e7c1fe0fd2c0384824b2.tar.gz
dir.c: not recurse dot files
* dir.c (glob_helper): skip dot files early on recursive match. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@36903 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/dir.c b/dir.c
index c7ffef269a..1dc54dce66 100644
--- a/dir.c
+++ b/dir.c
@@ -1379,15 +1379,24 @@ glob_helper(
if (dirp == NULL) return 0;
while (READDIR(dirp, enc, &STRUCT_DIRENT(entry), dp)) {
- char *buf = join_path(path, dirsep, dp->d_name);
+ char *buf;
enum answer new_isdir = UNKNOWN;
+ 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;
+ }
+
+ buf = join_path(path, dirsep, dp->d_name);
if (!buf) {
status = -1;
break;
}
- if (recursive && strcmp(dp->d_name, ".") != 0 && strcmp(dp->d_name, "..") != 0
- && fnmatch("*", rb_usascii_encoding(), dp->d_name, flags) == 0) {
+ if (recursive) {
#ifndef _WIN32
if (do_lstat(buf, &st, flags) == 0)
new_isdir = S_ISDIR(st.st_mode) ? YES : S_ISLNK(st.st_mode) ? UNKNOWN : NO;