Skip to content

Commit

Permalink
Cleanup File#identical?: use a shared implementation which fixes 1.8
Browse files Browse the repository at this point in the history
It was failing if arguments were not Strings:
TypeError:
      Tried to use object of type PackedObject (49) as type String (56)
  • Loading branch information
eregon committed May 28, 2012
1 parent 075cb50 commit 1b151fe
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 30 deletions.
7 changes: 5 additions & 2 deletions kernel/common/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -609,8 +609,11 @@ def self.grpowned?(path)
# open("d", "w") {}
# p File.identical?("a", "d") #=> false
def self.identical?(orig, copy)
st_o = File::Stat.stat(Rubinius::Type.coerce_to_path(orig))
st_c = File::Stat.stat(Rubinius::Type.coerce_to_path(copy))
orig = Rubinius::Type.coerce_to_path(orig)
st_o = File::Stat.stat(orig)
copy = Rubinius::Type.coerce_to_path(copy)
st_c = File::Stat.stat(copy)

return false if st_o.nil? || st_c.nil?

return false unless st_o.ino == st_c.ino
Expand Down
28 changes: 0 additions & 28 deletions kernel/common/file19.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,6 @@ def self.absolute_path(obj, dir = nil)
end
end

##
# Returns true if the named files are identical.
#
# open("a", "w") {}
# p File.identical?("a", "a") #=> true
# p File.identical?("a", "./a") #=> true
# File.link("a", "b")
# p File.identical?("a", "b") #=> true
# File.symlink("a", "c")
# p File.identical?("a", "c") #=> true
# open("d", "w") {}
# p File.identical?("a", "d") #=> false
def self.identical?(orig, copy)
orig = Rubinius::Type.coerce_to_path(orig)
st_o = File::Stat.stat(orig)
copy = Rubinius::Type.coerce_to_path(copy)
st_c = File::Stat.stat(copy)

return false if st_o.nil? || st_c.nil?

return false unless st_o.ino == st_c.ino
return false unless st_o.ftype == st_c.ftype
return false unless POSIX.access(orig, Constants::R_OK)
return false unless POSIX.access(copy, Constants::R_OK)

true
end

def self.world_readable?(path)
path = Rubinius::Type.coerce_to_path path
return nil unless exists? path
Expand Down

0 comments on commit 1b151fe

Please sign in to comment.