ruby-changes:54911
From: nobu <ko1@a...>
Date: Fri, 22 Feb 2019 15:01:17 +0900 (JST)
Subject: [ruby-changes:54911] nobu:r67116 (trunk): Support File#birthtime on Linux
nobu 2019-02-22 15:01:08 +0900 (Fri, 22 Feb 2019) New Revision: 67116 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=67116 Log: Support File#birthtime on Linux Modified files: trunk/file.c trunk/test/ruby/test_file_exhaustive.rb Index: test/ruby/test_file_exhaustive.rb =================================================================== --- test/ruby/test_file_exhaustive.rb (revision 67115) +++ test/ruby/test_file_exhaustive.rb (revision 67116) @@ -623,6 +623,17 @@ class TestFileExhaustive < Test::Unit::T https://github.com/ruby/ruby/blob/trunk/test/ruby/test_file_exhaustive.rb#L623 assert_raise(Errno::ENOENT) { File.ctime(nofile) } end + def test_birthtime + [regular_file, utf8_file].each do |file| + t1 = File.birthtime(file) + t2 = File.open(file) {|f| f.birthtime} + assert_kind_of(Time, t1) + assert_kind_of(Time, t2) + assert_equal(t1, t2) + end + assert_raise(Errno::ENOENT) { File.birthtime(nofile) } + end if File.respond_to?(:birthtime) + def test_chmod [regular_file, utf8_file].each do |file| assert_equal(1, File.chmod(0444, file)) Index: file.c =================================================================== --- file.c (revision 67115) +++ file.c (revision 67116) @@ -1208,6 +1208,8 @@ statx_birthtime(const struct statx *stx, https://github.com/ruby/ruby/blob/trunk/file.c#L1208 } typedef struct statx statx_data; +# define HAVE_STAT_BIRTHTIME + #elif defined(HAVE_STAT_BIRTHTIME) # define statx_without_gvl(path, st, mask) stat_without_gvl(path, st) # define fstatx_without_gvl(fd, st, mask) fstat_without_gvl(fd, st) @@ -2434,13 +2436,13 @@ static VALUE https://github.com/ruby/ruby/blob/trunk/file.c#L2436 rb_file_birthtime(VALUE obj) { rb_io_t *fptr; - struct stat st; + statx_data st; GetOpenFile(obj, fptr); - if (fstat(fptr->fd, &st) == -1) { + if (fstatx_without_gvl(fptr->fd, &st, STATX_BTIME) == -1) { rb_sys_fail_path(fptr->pathv); } - return stat_birthtime(&st); + return statx_birthtime(&st, fptr->pathv); } #else # define rb_file_birthtime rb_f_notimplement -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/