summaryrefslogtreecommitdiff
path: root/dir.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-03 03:39:33 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-03 03:39:33 +0000
commit1ef613dd0b6db1a3df63224803eadd2911ab427d (patch)
tree1fd99d8e21f3b48831b5fd77bfdc420f78eece8e /dir.c
parent6c676acfa258e85a0ea2f0c7941446568a78d828 (diff)
downloadbundler-1ef613dd0b6db1a3df63224803eadd2911ab427d.tar.gz
dir.c: relative path Dir base
* dir.c (glob_helper): fix globbing based on a relative path Dir. [Feature #13056] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59479 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'dir.c')
-rw-r--r--dir.c13
1 files changed, 8 insertions, 5 deletions
diff --git a/dir.c b/dir.c
index c02c071b97..f4608bcab4 100644
--- a/dir.c
+++ b/dir.c
@@ -1896,6 +1896,9 @@ glob_helper(
int plain = 0, magical = 0, recursive = 0, match_all = 0, match_dir = 0;
int escape = !(flags & FNM_NOESCAPE);
size_t pathlen = baselen + namelen;
+ const char *base = path;
+
+ if (fd != AT_FDCWD && *(base += baselen) == '/') base++;
for (cur = beg; cur < end; ++cur) {
struct glob_pattern *p = *cur;
@@ -1928,9 +1931,9 @@ glob_helper(
}
}
- if (*path) {
+ if (*base) {
if (match_all && pathtype == path_unknown) {
- if (do_lstat(fd, path, &st, flags, enc) == 0) {
+ if (do_lstat(fd, base, &st, flags, enc) == 0) {
pathtype = IFTODT(st.st_mode);
}
else {
@@ -1938,7 +1941,7 @@ glob_helper(
}
}
if (match_dir && pathtype == path_unknown) {
- if (do_stat(fd, path, &st, flags, enc) == 0) {
+ if (do_stat(fd, base, &st, flags, enc) == 0) {
pathtype = IFTODT(st.st_mode);
}
else {
@@ -1980,7 +1983,7 @@ glob_helper(
# else
;
# endif
- dirp = do_opendir(fd, *path ? path : ".", flags, enc, funcs->error, arg, &status);
+ dirp = do_opendir(fd, *base ? base : ".", flags, enc, funcs->error, arg, &status);
if (dirp == NULL) {
# if FNM_SYSCASE || NORMALIZE_UTF8PATH
if ((magical < 2) && !recursive && (errno == EACCES)) {
@@ -1990,7 +1993,7 @@ glob_helper(
# endif
return status;
}
- IF_NORMALIZE_UTF8PATH(norm_p = need_normalization(dirp, *path ? path : "."));
+ IF_NORMALIZE_UTF8PATH(norm_p = need_normalization(dirp, *base ? base : "."));
# if NORMALIZE_UTF8PATH
if (!(norm_p || magical || recursive)) {