[前][次][番号順一覧][スレッド一覧]

ruby-changes:34521

From: akr <ko1@a...>
Date: Sat, 28 Jun 2014 22:46:11 +0900 (JST)
Subject: [ruby-changes:34521] akr:r46602 (trunk): * ext/pathname/pathname.c (path_birthtime): New method,

akr	2014-06-28 22:46:02 +0900 (Sat, 28 Jun 2014)

  New Revision: 46602

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46602

  Log:
    * ext/pathname/pathname.c (path_birthtime): New method,
      Pathname#birthtime.
      Proposed by Kazuhiro NISHIYAMA.  [ruby-dev:48232] [Feature #9857]

  Modified files:
    trunk/ChangeLog
    trunk/ext/pathname/extconf.rb
    trunk/ext/pathname/pathname.c
    trunk/test/pathname/test_pathname.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 46601)
+++ ChangeLog	(revision 46602)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sat Jun 28 22:44:16 2014  Tanaka Akira  <akr@f...>
+
+	* ext/pathname/pathname.c (path_birthtime): New method,
+	  Pathname#birthtime.
+	  Proposed by Kazuhiro NISHIYAMA.  [ruby-dev:48232] [Feature #9857]
+
 Sat Jun 28 20:29:03 2014  Simon Baird  <simon.baird@g...>
 
 	* ext/bigdecimal/lib/bigdecimal/math.rb (BigMath#PI): change error
Index: ext/pathname/extconf.rb
===================================================================
--- ext/pathname/extconf.rb	(revision 46601)
+++ ext/pathname/extconf.rb	(revision 46602)
@@ -1,2 +1,3 @@ https://github.com/ruby/ruby/blob/trunk/ext/pathname/extconf.rb#L1
 require 'mkmf'
+have_struct_member("struct stat", "st_birthtimespec", "sys/stat.h")
 create_makefile('pathname')
Index: ext/pathname/pathname.c
===================================================================
--- ext/pathname/pathname.c	(revision 46601)
+++ ext/pathname/pathname.c	(revision 46602)
@@ -442,6 +442,25 @@ path_atime(VALUE self) https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L442
 
 /*
  * call-seq:
+ *   pathname.birthtime	-> time
+ *
+ * Returns the birth time for the file.
+ * If the platform doesn't have birthtime, returns <i>ctime</i>.
+ *
+ * See File.birthtime.
+ */
+#if defined(HAVE_STRUCT_STAT_ST_BIRTHTIMESPEC)
+static VALUE
+path_birthtime(VALUE self)
+{
+    return rb_funcall(rb_cFile, rb_intern("birthtime"), 1, get_strpath(self));
+}
+#else
+# define path_birthtime rb_f_notimplement
+#endif
+
+/*
+ * call-seq:
  *   pathname.ctime	-> time
  *
  * Returns the last change time, using directory information, not the file itself.
@@ -1288,6 +1307,7 @@ path_f_pathname(VALUE self, VALUE str) https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L1307
  *
  * These methods are a facade for File:
  * - #atime
+ * - #birthtime
  * - #ctime
  * - #mtime
  * - #chmod(mode)
@@ -1380,6 +1400,7 @@ Init_pathname() https://github.com/ruby/ruby/blob/trunk/ext/pathname/pathname.c#L1400
     rb_define_method(rb_cPathname, "binwrite", path_binwrite, -1);
     rb_define_method(rb_cPathname, "sysopen", path_sysopen, -1);
     rb_define_method(rb_cPathname, "atime", path_atime, 0);
+    rb_define_method(rb_cPathname, "birthtime", path_birthtime, 0);
     rb_define_method(rb_cPathname, "ctime", path_ctime, 0);
     rb_define_method(rb_cPathname, "mtime", path_mtime, 0);
     rb_define_method(rb_cPathname, "chmod", path_chmod, 1);
Index: test/pathname/test_pathname.rb
===================================================================
--- test/pathname/test_pathname.rb	(revision 46601)
+++ test/pathname/test_pathname.rb	(revision 46602)
@@ -771,6 +771,14 @@ class TestPathname < Test::Unit::TestCas https://github.com/ruby/ruby/blob/trunk/test/pathname/test_pathname.rb#L771
     assert_kind_of(Time, Pathname(__FILE__).atime)
   end
 
+  def test_birthtime
+    assert_kind_of(Time, Pathname(__FILE__).birthtime)
+  rescue NotImplementedError
+    assert_raise(NotImplementedError) do
+      File.birthtime(__FILE__)
+    end
+  end
+
   def test_ctime
     assert_kind_of(Time, Pathname(__FILE__).ctime)
   end

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]