From f9f73768486da483d039a2b6b7e7c31fe5842944 Mon Sep 17 00:00:00 2001 From: akr Date: Sat, 18 Sep 2010 22:49:34 +0000 Subject: * ext/pathname/pathname.c (path_unlink): Pathname#unlink and Pathname#delete translated from pathname.rb. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29296 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 +++++ ext/pathname/lib/pathname.rb | 13 ------------- ext/pathname/pathname.c | 26 ++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index c8607786c5..d79bc89b58 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +Sun Sep 19 07:48:20 2010 Tanaka Akira + + * ext/pathname/pathname.c (path_unlink): Pathname#unlink and + Pathname#delete translated from pathname.rb. + Sun Sep 19 06:06:07 2010 Kenta Murata * ext/bigdecimal/bigdecimal.c (check_rounding_mode): added for diff --git a/ext/pathname/lib/pathname.rb b/ext/pathname/lib/pathname.rb index 0b7458e6cb..0c1351dc1e 100644 --- a/ext/pathname/lib/pathname.rb +++ b/ext/pathname/lib/pathname.rb @@ -526,19 +526,6 @@ class Pathname # * FileUtils * end -class Pathname # * mixed * - # Removes a file or directory, using File.unlink or - # Dir.unlink as necessary. - def unlink() - begin - Dir.unlink @path - rescue Errno::ENOTDIR - File.unlink @path - end - end - alias delete unlink -end - class Pathname undef =~ end diff --git a/ext/pathname/pathname.c b/ext/pathname/pathname.c index 0583b0da3e..f5a0182bf0 100644 --- a/ext/pathname/pathname.c +++ b/ext/pathname/pathname.c @@ -937,6 +937,30 @@ path_each_entry(VALUE self) return rb_block_call(rb_cDir, rb_intern("foreach"), 1, args, each_entry_i, rb_obj_class(self)); } +static VALUE +unlink_body(VALUE str) +{ + return rb_funcall(rb_cDir, rb_intern("unlink"), 1, str); +} + +static VALUE +unlink_rescue(VALUE str, VALUE errinfo) +{ + return rb_funcall(rb_cFile, rb_intern("unlink"), 1, str); +} + +/* + * Removes a file or directory, using File.unlink or + * Dir.unlink as necessary. + */ +static VALUE +path_unlink(VALUE self) +{ + VALUE eENOTDIR = rb_const_get_at(rb_mErrno, rb_intern("ENOTDIR")); + VALUE str = get_strpath(self); + return rb_rescue2(unlink_body, str, unlink_rescue, str, eENOTDIR, (VALUE)0); +} + /* * == Pathname * @@ -1198,4 +1222,6 @@ Init_pathname() rb_define_method(rb_cPathname, "rmdir", path_rmdir, 0); rb_define_method(rb_cPathname, "opendir", path_opendir, 0); rb_define_method(rb_cPathname, "each_entry", path_each_entry, 0); + rb_define_method(rb_cPathname, "unlink", path_unlink, 0); + rb_define_method(rb_cPathname, "delete", path_unlink, 0); } -- cgit v1.2.3