зеркало из https://github.com/github/ruby.git
* file.c (rb_find_file_ext, rb_find_file): not to split load path with
path separator. [ruby-Bugs-21356] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18242 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
66660a893a
Коммит
31aa0986b8
|
@ -1,3 +1,8 @@
|
|||
Mon Jul 28 18:15:45 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* file.c (rb_find_file_ext, rb_find_file): not to split load path with
|
||||
path separator. [ruby-Bugs-21356]
|
||||
|
||||
Mon Jul 28 18:14:03 2008 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* win32/win32.c (overlapped_socket_io, fcntl, rb_w32_close): must not
|
||||
|
|
82
file.c
82
file.c
|
@ -4447,34 +4447,16 @@ file_load_ok(const char *path)
|
|||
return eaccess(path, R_OK) == 0;
|
||||
}
|
||||
|
||||
#ifdef __CYGWIN__
|
||||
static void
|
||||
intern_cygwin_path(volatile VALUE *path)
|
||||
{
|
||||
char rubylib[MAXPATHLEN];
|
||||
VALUE str = *path;
|
||||
const char *p = RSTRING_PTR(str);
|
||||
|
||||
if (*p == '\\' || has_drive_letter(p)) {
|
||||
if (cygwin_conv_to_posix_path(p, rubylib) == 0) {
|
||||
*path = rb_str_new2(rubylib);
|
||||
}
|
||||
}
|
||||
}
|
||||
#define intern_path(str) intern_cygwin_path(&(str))
|
||||
#else
|
||||
#define intern_path(str) (void)(str)
|
||||
#endif
|
||||
|
||||
VALUE rb_get_load_path(void);
|
||||
|
||||
int
|
||||
rb_find_file_ext(VALUE *filep, const char *const *ext)
|
||||
{
|
||||
const char *path, *found;
|
||||
const char *f = RSTRING_PTR(*filep);
|
||||
VALUE fname, load_path;
|
||||
long i, j;
|
||||
VALUE fname, load_path, tmp;
|
||||
long i, j, fnlen;
|
||||
|
||||
if (!ext[0]) return 0;
|
||||
|
||||
if (f[0] == '~') {
|
||||
fname = rb_file_expand_path(*filep, Qnil);
|
||||
|
@ -4502,24 +4484,26 @@ rb_find_file_ext(VALUE *filep, const char *const *ext)
|
|||
load_path = rb_get_load_path();
|
||||
if (!load_path) return 0;
|
||||
|
||||
fname = rb_str_dup(*filep);
|
||||
RBASIC(fname)->klass = 0;
|
||||
fnlen = RSTRING_LEN(fname);
|
||||
tmp = rb_str_tmp_new(MAXPATHLEN + 2);
|
||||
for (j=0; ext[j]; j++) {
|
||||
fname = rb_str_dup(*filep);
|
||||
rb_str_cat2(fname, ext[j]);
|
||||
OBJ_FREEZE(fname);
|
||||
for (i = 0; i < RARRAY_LEN(load_path); i++) {
|
||||
VALUE str = RARRAY_PTR(load_path)[i];
|
||||
char fbuf[MAXPATHLEN];
|
||||
|
||||
FilePathValue(str);
|
||||
if (RSTRING_LEN(str) == 0) continue;
|
||||
intern_path(str);
|
||||
path = RSTRING_PTR(str);
|
||||
found = dln_find_file_r(StringValueCStr(fname), path, fbuf, sizeof(fbuf));
|
||||
if (found && file_load_ok(found)) {
|
||||
*filep = rb_str_new2(found);
|
||||
file_expand_path(fname, str, tmp);
|
||||
if (file_load_ok(RSTRING_PTR(tmp))) {
|
||||
RBASIC(tmp)->klass = RBASIC(*filep)->klass;
|
||||
OBJ_FREEZE(tmp);
|
||||
*filep = tmp;
|
||||
return j+1;
|
||||
}
|
||||
}
|
||||
rb_str_set_len(fname, fnlen);
|
||||
}
|
||||
RB_GC_GUARD(load_path);
|
||||
return 0;
|
||||
|
@ -4530,8 +4514,6 @@ rb_find_file(VALUE path)
|
|||
{
|
||||
VALUE tmp, load_path;
|
||||
const char *f = StringValueCStr(path);
|
||||
const char *lpath;
|
||||
char fbuf[MAXPATHLEN];
|
||||
|
||||
if (f[0] == '~') {
|
||||
path = rb_file_expand_path(path, Qnil);
|
||||
|
@ -4548,6 +4530,7 @@ rb_find_file(VALUE path)
|
|||
rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
|
||||
}
|
||||
if (file_load_ok(f)) return path;
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
@ -4556,6 +4539,7 @@ rb_find_file(VALUE path)
|
|||
rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
|
||||
}
|
||||
if (file_load_ok(f)) return path;
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (rb_safe_level() >= 4) {
|
||||
|
@ -4566,42 +4550,30 @@ rb_find_file(VALUE path)
|
|||
if (load_path) {
|
||||
long i;
|
||||
|
||||
tmp = rb_ary_new();
|
||||
tmp = rb_str_tmp_new(MAXPATHLEN + 2);
|
||||
for (i = 0; i < RARRAY_LEN(load_path); i++) {
|
||||
VALUE str = RARRAY_PTR(load_path)[i];
|
||||
FilePathValue(str);
|
||||
if (RSTRING_LEN(str) > 0) {
|
||||
intern_path(str);
|
||||
rb_ary_push(tmp, str);
|
||||
file_expand_path(path, str, tmp);
|
||||
f = RSTRING_PTR(tmp);
|
||||
if (file_load_ok(f)) goto found;
|
||||
}
|
||||
}
|
||||
tmp = rb_ary_join(tmp, rb_str_new2(PATH_SEP));
|
||||
if (RSTRING_LEN(tmp) == 0) {
|
||||
lpath = 0;
|
||||
}
|
||||
else {
|
||||
lpath = RSTRING_PTR(tmp);
|
||||
}
|
||||
return 0;
|
||||
found:
|
||||
RBASIC(tmp)->klass = RBASIC(path)->klass;
|
||||
OBJ_FREEZE(tmp);
|
||||
}
|
||||
else {
|
||||
lpath = 0;
|
||||
}
|
||||
|
||||
if (!lpath) {
|
||||
return 0; /* no path, no load */
|
||||
}
|
||||
if (!(f = dln_find_file_r(f, lpath, fbuf, sizeof(fbuf)))) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (rb_safe_level() >= 1 && !fpath_check(f)) {
|
||||
rb_raise(rb_eSecurityError, "loading from unsafe file %s", f);
|
||||
}
|
||||
if (file_load_ok(f)) {
|
||||
tmp = rb_str_new2(f);
|
||||
OBJ_FREEZE(tmp);
|
||||
return tmp;
|
||||
}
|
||||
return 0;
|
||||
|
||||
return tmp;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
Загрузка…
Ссылка в новой задаче