Skip to content

File.identical? should use stat to compare files #7151

@headius

Description

@headius

File.identical? in CRuby compares two files using the following algorithm:

  • fstat each file's fd, or if either are a String path, stat the path.
  • Compare the stat structs' dev and ino fields to confirm they do in fact point at or resolve to the same filesystem entry.

In JRuby, however, we do not use stat and instead just canonicalize the given paths or the original paths of any given open Files and compare the canonicalized results.

This generally works ok, since the canonicalized file path should be unique on most modern filesystems. It fails, however, if an open file's entry has been renamed (or unlinked) on the file system. In that case, our canonicalization of the original path does not reflect the new filesystem entry (or lack thereof).

This is the cause of (at least) the sole remaining Logger test failure, TestLogDevice#test_shifting_size_not_rotate_too_much.

exclude :test_shifting_size_not_rotate_too_much, ""

This test has a comment in the logger gem indicating that we fail it:

https://github.com/ruby/logger/blob/master/test/logger/test_logdevice.rb#L438

Note that our File objects will actually point at the new filesystem entry if it has been renamed, so this is just a flaw in how we implement identical?.

This has been a bug for a very long time, so it may not be a high priority to fix; however we do have the ability to do a native stat or fstat (for a path versus an open File) so it would not be a large amount of work to implement this correctly when native support is available.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions