diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-27 06:49:43 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-02-27 06:49:43 +0000 |
commit | 5f47ed9b59afa0fbaa30aa191d739a260f54c3f9 (patch) | |
tree | c8f72dd0fb781b4c2fd3965742e8a4bdb5b99818 | |
parent | c691d55bcdd09081bb18d7ee88983175470f7249 (diff) |
* 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
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | bootstraptest/test_load.rb | 12 | ||||
-rw-r--r-- | file.c | 23 |
3 files changed, 23 insertions, 16 deletions
@@ -1,3 +1,7 @@ +Fri Feb 27 15:49:41 2009 Nobuyoshi Nakada <[email protected]> + + * file.c (file_load_ok): checks if regular file. [ruby-dev:38097] + Fri Feb 27 14:39:40 2009 NAKAMURA Usaku <[email protected]> * numeric.c (flo_eq, flo_gt, flo_ge, flo_lt, flo_le, flo_eql): revert diff --git a/bootstraptest/test_load.rb b/bootstraptest/test_load.rb index 18e8cc06a4..e63c93a8f4 100644 --- a/bootstraptest/test_load.rb +++ b/bootstraptest/test_load.rb @@ -13,3 +13,15 @@ assert_equal 'ok', %q{ }.map {|t| t.value } vs[0] == M && vs[1] == M ? :ok : :ng }, '[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]' @@ -107,7 +107,6 @@ rb_get_path_check(VALUE obj, int check) tmp = rb_check_string_type(obj); if (!NIL_P(tmp)) goto exit; - CONST_ID(to_path, "to_path"); if (rb_respond_to(obj, to_path)) { tmp = rb_funcall(obj, to_path, 0, 0); @@ -294,7 +293,6 @@ rb_stat_dev_minor(VALUE self) #endif } - /* * call-seq: * stat.ino => fixnum @@ -352,7 +350,6 @@ rb_stat_nlink(VALUE self) return UINT2NUM(get_stat(self)->st_nlink); } - /* * call-seq: * stat.uid => fixnum @@ -385,7 +382,6 @@ rb_stat_gid(VALUE self) return GIDT2NUM(get_stat(self)->st_gid); } - /* * call-seq: * stat.rdev => fixnum or nil @@ -839,7 +835,6 @@ rb_file_s_lstat(VALUE klass, VALUE fname) #endif } - /* * call-seq: * 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 @@ -1014,7 +1008,6 @@ rb_file_directory_p(VALUE obj, VALUE fname) return Qfalse; } - /* * call-seq: * File.pipe?(file_name) => true or false @@ -1158,7 +1151,6 @@ rb_file_chardev_p(VALUE obj, VALUE fname) return Qfalse; } - /* * call-seq: * File.exist?(file_name) => true or false @@ -2035,7 +2027,6 @@ lchown_internal(const char *path, void *arg) rb_sys_fail(path); } - /* * call-seq: * file.lchown(owner_int, group_int, file_name,..) => integer @@ -2172,7 +2163,6 @@ rb_file_s_utime(int argc, VALUE *argv) return LONG2FIX(n); } - NORETURN(static void sys_fail2(VALUE,VALUE)); static void sys_fail2(VALUE s1, VALUE s2) @@ -3779,7 +3769,6 @@ rb_f_test(int argc, VALUE *argv) } - /* * Document-class: File::Stat * @@ -4082,8 +4071,6 @@ rb_stat_r(VALUE obj) return Qtrue; } - - /* * call-seq: * stat.readable_real? -> true or false @@ -4280,7 +4267,6 @@ rb_stat_x(VALUE obj) * the process. */ - static VALUE rb_stat_X(VALUE obj) { @@ -4341,7 +4327,6 @@ rb_stat_z(VALUE obj) return Qfalse; } - /* * call-seq: * state.size => integer @@ -4536,7 +4521,13 @@ rb_path_check(const char *path) static int 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 |