Skip to content

Stat IO arguments through their fd in File.identical? - #10219

Open
CufeHaco wants to merge 1 commit into
jruby:masterfrom
CufeHaco:file-identical-io
Open

CufeHaco wants to merge 1 commit into
jruby:masterfrom
CufeHaco:file-identical-io

Conversation

@CufeHaco

@CufeHaco CufeHaco commented Dec 5, 2026

Copy link
Copy Markdown
Contributor

Split out of #9874, as Sampo asked.

File.identical? compared IO arguments by their path. A pipe or a socket has no path, so File.identical?(r, r) returned false for a pipe. This now follows CRuby's rb_stat:

  • an IO, or anything with to_io, is statted through its open fd
  • a closed IO raises IOError
  • other arguments are still looked up by path

I added examples to spec/ruby/shared/file/identical.rb (not on Windows) for an IO by fd, to_io, and a closed IO.

Testing: the new examples pass on CRuby 4.0 and with this change (18 examples, 0 failures). On master they fail.

File.identical? with IO arguments compared their paths, and a pipe or a
socket has none, so File.identical?(r, r) was false for a pipe. It now
follows CRuby's rb_stat: an IO, or anything with to_io, is statted
through its open fd, a closed IO raises IOError, and other arguments are
still looked up by path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant