diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-02-22 06:01:08 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2019-02-22 06:01:08 +0000 |
commit | fc90c4ec5da9e60c18785b3b4c393b5294009c1e (patch) | |
tree | 92a8e777962d8a706170e1021be26aa062377ab7 | |
parent | 607ecea7c9ca30ef4dbdadc72c9d32131946a069 (diff) | |
download | ruby-fc90c4ec5da9e60c18785b3b4c393b5294009c1e.tar.gz |
Support File#birthtime on Linux
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@67116 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | file.c | 8 | ||||
-rw-r--r-- | test/ruby/test_file_exhaustive.rb | 11 |
2 files changed, 16 insertions, 3 deletions
@@ -1208,6 +1208,8 @@ statx_birthtime(const struct statx *stx, VALUE fname) } 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 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 diff --git a/test/ruby/test_file_exhaustive.rb b/test/ruby/test_file_exhaustive.rb index 7d4eeb6d59..57eb01b4ec 100644 --- a/test/ruby/test_file_exhaustive.rb +++ b/test/ruby/test_file_exhaustive.rb @@ -623,6 +623,17 @@ class TestFileExhaustive < Test::Unit::TestCase 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)) |