Permalink
Browse files

Cleanup File#identical?: use a shared implementation which fixes 1.8

It was failing if arguments were not Strings:
TypeError:
      Tried to use object of type PackedObject (49) as type String (56)
  • Loading branch information...
1 parent 075cb50 commit 1b151fe4c84aeed4bbc6a95ffb720c348a651709 @eregon eregon committed May 28, 2012
Showing with 5 additions and 30 deletions.
  1. +5 −2 kernel/common/file.rb
  2. +0 −28 kernel/common/file19.rb
View
7 kernel/common/file.rb
@@ -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
View
28 kernel/common/file19.rb
@@ -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

0 comments on commit 1b151fe

Please sign in to comment.