ruby-changes:17293
From: akr <ko1@a...>
Date: Sun, 19 Sep 2010 07:57:58 +0900 (JST)
Subject: [ruby-changes:17293] Ruby:r29296 (trunk): * ext/pathname/pathname.c (path_unlink): Pathname#unlink and
akr 2010-09-19 07:49:34 +0900 (Sun, 19 Sep 2010) New Revision: 29296 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=29296 Log: * ext/pathname/pathname.c (path_unlink): Pathname#unlink and Pathname#delete translated from pathname.rb. Modified files: trunk/ChangeLog trunk/ext/pathname/lib/pathname.rb trunk/ext/pathname/pathname.c Index: ChangeLog =================================================================== --- ChangeLog (revision 29295) +++ ChangeLog (revision 29296) @@ -1,3 +1,8 @@ +Sun Sep 19 07:48:20 2010 Tanaka Akira <akr@f...> + + * ext/pathname/pathname.c (path_unlink): Pathname#unlink and + Pathname#delete translated from pathname.rb. + Sun Sep 19 06:06:07 2010 Kenta Murata <mrkn@m...> * ext/bigdecimal/bigdecimal.c (check_rounding_mode): added for Index: ext/pathname/lib/pathname.rb =================================================================== --- ext/pathname/lib/pathname.rb (revision 29295) +++ ext/pathname/lib/pathname.rb (revision 29296) @@ -526,19 +526,6 @@ end -class Pathname # * mixed * - # Removes a file or directory, using <tt>File.unlink</tt> or - # <tt>Dir.unlink</tt> as necessary. - def unlink() - begin - Dir.unlink @path - rescue Errno::ENOTDIR - File.unlink @path - end - end - alias delete unlink -end - class Pathname undef =~ end Index: ext/pathname/pathname.c =================================================================== --- ext/pathname/pathname.c (revision 29295) +++ ext/pathname/pathname.c (revision 29296) @@ -937,7 +937,31 @@ 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 <tt>File.unlink</tt> or + * <tt>Dir.unlink</tt> 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 * * Pathname represents a pathname which locates a file in a filesystem. @@ -1198,4 +1222,6 @@ 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); } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/