Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: rubinius/rubinius
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 92702b5709e4^
Choose a base ref
...
head repository: rubinius/rubinius
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 3ca200532997
Choose a head ref
  • 4 commits
  • 7 files changed
  • 1 contributor

Commits on May 28, 2015

  1. check for birthtime() function

    tak1n committed May 28, 2015
    Copy the full SHA
    92702b5 View commit details
  2. Copy the full SHA
    32bc2c6 View commit details
  3. Copy the full SHA
    525a6b6 View commit details
  4. Copy the full SHA
    3ca2005 View commit details
Showing with 81 additions and 41 deletions.
  1. +4 −0 configure
  2. +5 −0 kernel/bootstrap/stat.rb
  3. +34 −26 kernel/common/file.rb
  4. +27 −11 spec/ruby/core/file/birthtime_spec.rb
  5. +0 −4 spec/tags/ruby/core/file/birthtime_tags.txt
  6. +8 −0 vm/builtin/stat.cpp
  7. +3 −0 vm/builtin/stat.hpp
4 changes: 4 additions & 0 deletions configure
Original file line number Diff line number Diff line change
@@ -1230,6 +1230,10 @@ int main() { return tgetnum(""); }
@defines << "HAVE_GETTID"
end

if has_function("birthtime", ["sys/stat.h"])
@defines << "HAVE_ST_BIRTHTIME"
end

# glibc has useless lchmod() so we don't try to use lchmod() on linux
if !@linux and has_function("lchmod", ["sys/stat.h", "unistd.h"])
@have_lchmod = true
5 changes: 5 additions & 0 deletions kernel/bootstrap/stat.rb
Original file line number Diff line number Diff line change
@@ -87,6 +87,11 @@ def ctime
raise PrimitiveFailure, "Rubinius::Stat#ctime primitive failed"
end

def birthtime
Rubinius.primitive :stat_birthtime
raise NotImplementedError, "birthtime() function is unimplemented on this machine"
end

def inspect
"#<#{self.class.name} dev=0x#{self.dev.to_s(16)}, ino=#{self.ino}, " \
"mode=#{sprintf("%07d", self.mode.to_s(8).to_i)}, nlink=#{self.nlink}, " \
60 changes: 34 additions & 26 deletions kernel/common/file.rb
Original file line number Diff line number Diff line change
@@ -103,6 +103,28 @@ def self.atime(path)
Stat.new(path).atime
end

##
# Returns the change time for the named file (the
# time at which directory information about the
# file was changed, not the file itself).
#
# File.ctime("testfile") #=> Wed Apr 09 08:53:13 CDT 2003
def self.ctime(path)
Stat.new(path).ctime
end

def self.birthtime(path)
Stat.new(path).birthtime
end

##
# Returns the modification time for the named file as a Time object.
#
# File.mtime("testfile") #=> Tue Apr 08 12:58:04 CDT 2003
def self.mtime(path)
Stat.new(path).mtime
end

##
# Returns the last component of the filename given
# in file_name, which must be formed using forward
@@ -304,16 +326,6 @@ def self.lchown(owner, group, *paths)
paths.size
end

##
# Returns the change time for the named file (the
# time at which directory information about the
# file was changed, not the file itself).
#
# File.ctime("testfile") #=> Wed Apr 09 08:53:13 CDT 2003
def self.ctime(path)
Stat.new(path).ctime
end

##
# Returns true if the named file is a directory, false otherwise.
#
@@ -816,14 +828,6 @@ def self.lstat(path)
Stat.lstat path
end

##
# Returns the modification time for the named file as a Time object.
#
# File.mtime("testfile") #=> Tue Apr 08 12:58:04 CDT 2003
def self.mtime(path)
Stat.new(path).mtime
end

def self.path(obj)
return obj.to_path if obj.respond_to? :to_path

@@ -1226,6 +1230,18 @@ def atime
Stat.new(@path).atime
end

def ctime
Stat.new(@path).ctime
end

def birthtime
Stat.new(@path).birthtime
end

def mtime
Stat.new(@path).mtime
end

def reopen(other, mode = 'r+')
rewind unless closed?
unless other.kind_of? IO
@@ -1234,10 +1250,6 @@ def reopen(other, mode = 'r+')
super(other, mode)
end

def ctime
Stat.new(@path).ctime
end

def flock(const)
const = Rubinius::Type.coerce_to const, Integer, :to_int

@@ -1251,10 +1263,6 @@ def lstat
Stat.lstat @path
end

def mtime
Stat.new(@path).mtime
end

def stat
Stat.fstat @descriptor
end
38 changes: 27 additions & 11 deletions spec/ruby/core/file/birthtime_spec.rb
Original file line number Diff line number Diff line change
@@ -9,17 +9,25 @@
@file = nil
end

it "returns the birth time for the named file as a Time object" do
File.birthtime(@file)
File.birthtime(@file).should be_kind_of(Time)
end
platform_is :darwin, :freebsd, :netbsd do
it "returns the birth time for the named file as a Time object" do
File.birthtime(@file)
File.birthtime(@file).should be_kind_of(Time)
end

it "accepts an object that has a #to_path method" do
File.birthtime(mock_to_path(@file))
end

it "accepts an object that has a #to_path method" do
File.birthtime(mock_to_path(@file))
it "raises an Errno::ENOENT exception if the file is not found" do
lambda { File.birthtime('bogus') }.should raise_error(Errno::ENOENT)
end
end

it "raises an Errno::ENOENT exception if the file is not found" do
lambda { File.birthtime('bogus') }.should raise_error(Errno::ENOENT)
platform_is :windows, :linux do
it "raises an NotImplementedError" do
lambda { File.birthtime(@file) }.should raise_error(NotImplementedError)
end
end
end

@@ -33,8 +41,16 @@
@file = nil
end

it "returns the birth time for self" do
@file.birthtime
@file.birthtime.should be_kind_of(Time)
platform_is :darwin, :freebsd, :netbsd, :openbsd do
it "returns the birth time for self" do
@file.birthtime
@file.birthtime.should be_kind_of(Time)
end
end

platform_is :windows, :linux do
it "raises an NotImplementedError" do
lambda { @file.birthtime }.should raise_error(NotImplementedError)
end
end
end
4 changes: 0 additions & 4 deletions spec/tags/ruby/core/file/birthtime_tags.txt

This file was deleted.

8 changes: 8 additions & 0 deletions vm/builtin/stat.cpp
Original file line number Diff line number Diff line change
@@ -77,5 +77,13 @@ namespace rubinius {
return Time::at(state, st_.st_ctime);
}

Object* Stat::stat_birthtime(STATE) {
#ifdef HAVE_ST_BIRTHTIME
return Time::at(state, st_.st_birthtime);
#else
return Primitives::failure();
#endif
}

}

3 changes: 3 additions & 0 deletions vm/builtin/stat.hpp
Original file line number Diff line number Diff line change
@@ -73,6 +73,9 @@ namespace rubinius {
// Rubinius.primitive+ :stat_ctime
Time* stat_ctime(STATE);

// Rubinius.primitive+ :stat_birthtime
Object* stat_birthtime(STATE);

class Info : public TypeInfo {
public:
BASIC_TYPEINFO(TypeInfo)