* file.c (file_load_ok): checks if regular file. [ruby-dev:38097]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22655 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-02-27 06:49:43 +00:00
parent c691d55bcd
commit 5f47ed9b59
3 changed files with 23 additions and 16 deletions

View File

@ -1,3 +1,7 @@
Fri Feb 27 15:49:41 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* file.c (file_load_ok): checks if regular file. [ruby-dev:38097]
Fri Feb 27 14:39:40 2009 NAKAMURA Usaku <usa@ruby-lang.org> Fri Feb 27 14:39:40 2009 NAKAMURA Usaku <usa@ruby-lang.org>
* numeric.c (flo_eq, flo_gt, flo_ge, flo_lt, flo_le, flo_eql): revert * numeric.c (flo_eq, flo_gt, flo_ge, flo_lt, flo_le, flo_eql): revert

View File

@ -13,3 +13,15 @@ assert_equal 'ok', %q{
}.map {|t| t.value } }.map {|t| t.value }
vs[0] == M && vs[1] == M ? :ok : :ng vs[0] == M && vs[1] == M ? :ok : :ng
}, '[ruby-dev:32048]' }, '[ruby-dev:32048]'
assert_equal 'ok', %q{
%w[a a/foo b].each {|d| Dir.mkdir(d)}
open("b/foo", "w") {|f| f.puts "$ok = :ok"}
$:.replace(%w[a b])
begin
load "foo"
$ok
rescue => e
e.message
end
}, '[ruby-dev:38097]'

23
file.c
View File

@ -107,7 +107,6 @@ rb_get_path_check(VALUE obj, int check)
tmp = rb_check_string_type(obj); tmp = rb_check_string_type(obj);
if (!NIL_P(tmp)) goto exit; if (!NIL_P(tmp)) goto exit;
CONST_ID(to_path, "to_path"); CONST_ID(to_path, "to_path");
if (rb_respond_to(obj, to_path)) { if (rb_respond_to(obj, to_path)) {
tmp = rb_funcall(obj, to_path, 0, 0); tmp = rb_funcall(obj, to_path, 0, 0);
@ -294,7 +293,6 @@ rb_stat_dev_minor(VALUE self)
#endif #endif
} }
/* /*
* call-seq: * call-seq:
* stat.ino => fixnum * stat.ino => fixnum
@ -352,7 +350,6 @@ rb_stat_nlink(VALUE self)
return UINT2NUM(get_stat(self)->st_nlink); return UINT2NUM(get_stat(self)->st_nlink);
} }
/* /*
* call-seq: * call-seq:
* stat.uid => fixnum * stat.uid => fixnum
@ -385,7 +382,6 @@ rb_stat_gid(VALUE self)
return GIDT2NUM(get_stat(self)->st_gid); return GIDT2NUM(get_stat(self)->st_gid);
} }
/* /*
* call-seq: * call-seq:
* stat.rdev => fixnum or nil * stat.rdev => fixnum or nil
@ -839,7 +835,6 @@ rb_file_s_lstat(VALUE klass, VALUE fname)
#endif #endif
} }
/* /*
* call-seq: * call-seq:
* file.lstat => stat * file.lstat => stat
@ -965,7 +960,6 @@ eaccess(const char *path, int mode)
* *
*/ */
/* /*
* File.directory?(file_name) => true or false * File.directory?(file_name) => true or false
* File.directory?(file_name) => true or false * File.directory?(file_name) => true or false
@ -1014,7 +1008,6 @@ rb_file_directory_p(VALUE obj, VALUE fname)
return Qfalse; return Qfalse;
} }
/* /*
* call-seq: * call-seq:
* File.pipe?(file_name) => true or false * File.pipe?(file_name) => true or false
@ -1158,7 +1151,6 @@ rb_file_chardev_p(VALUE obj, VALUE fname)
return Qfalse; return Qfalse;
} }
/* /*
* call-seq: * call-seq:
* File.exist?(file_name) => true or false * File.exist?(file_name) => true or false
@ -2035,7 +2027,6 @@ lchown_internal(const char *path, void *arg)
rb_sys_fail(path); rb_sys_fail(path);
} }
/* /*
* call-seq: * call-seq:
* file.lchown(owner_int, group_int, file_name,..) => integer * file.lchown(owner_int, group_int, file_name,..) => integer
@ -2172,7 +2163,6 @@ rb_file_s_utime(int argc, VALUE *argv)
return LONG2FIX(n); return LONG2FIX(n);
} }
NORETURN(static void sys_fail2(VALUE,VALUE)); NORETURN(static void sys_fail2(VALUE,VALUE));
static void static void
sys_fail2(VALUE s1, VALUE s2) sys_fail2(VALUE s1, VALUE s2)
@ -3779,7 +3769,6 @@ rb_f_test(int argc, VALUE *argv)
} }
/* /*
* Document-class: File::Stat * Document-class: File::Stat
* *
@ -4082,8 +4071,6 @@ rb_stat_r(VALUE obj)
return Qtrue; return Qtrue;
} }
/* /*
* call-seq: * call-seq:
* stat.readable_real? -> true or false * stat.readable_real? -> true or false
@ -4280,7 +4267,6 @@ rb_stat_x(VALUE obj)
* the process. * the process.
*/ */
static VALUE static VALUE
rb_stat_X(VALUE obj) rb_stat_X(VALUE obj)
{ {
@ -4341,7 +4327,6 @@ rb_stat_z(VALUE obj)
return Qfalse; return Qfalse;
} }
/* /*
* call-seq: * call-seq:
* state.size => integer * state.size => integer
@ -4536,7 +4521,13 @@ rb_path_check(const char *path)
static int static int
file_load_ok(const char *path) file_load_ok(const char *path)
{ {
return eaccess(path, R_OK) == 0; struct stat st;
int ret, fd = open(path, O_RDONLY);
if (fd == -1) return 0;
ret = fstat(fd, &st);
(void)close(fd);
if (ret) return 0;
return S_ISREG(st.st_mode);
} }
static int static int