Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IO.copy_stream doesn't rewind the destination #2762

Closed
janko opened this issue Mar 26, 2015 · 4 comments
Closed

IO.copy_stream doesn't rewind the destination #2762

janko opened this issue Mar 26, 2015 · 4 comments

Comments

@janko
Copy link

janko commented Mar 26, 2015

I mean, I wouldn't normally expect that IO.copy_stream would rewind the destination, but MRI does it, and we're currently relying on that behaviour in Refile (although we will add the rewind now). Just to help you to be the closest to MRI :)

# MRI 2.2.0
require "stringio"
require "tempfile"
file = Tempfile.new('foo')
IO.copy_stream(StringIO.new('foo'), file)
file.eof? #=> false (it's on the beginning)
# JRuby 9.0.0.0.pre1
require "stringio"
require "tempfile"
file = Tempfile.new('foo')
IO.copy_stream(StringIO.new('foo'), file)
file.eof? #=> true
@headius
Copy link
Member

headius commented Mar 29, 2015

Thanks for the report!

@headius
Copy link
Member

headius commented Mar 29, 2015

This looks like a bug in MRI, probably when using copy_stream with Tempfile. Here it is with a normal file, showing that it definitely does not rewind:

$ rvm ruby-2.2 do ruby -e "f1 = File.open('pom.xml'); f2 = File.open('tmp.txt', 'r+'); IO.copy_stream(f1, f2); p f2.eof?, f2.pos"
true
24619

I believe this is actually a bug in MRI.

@headius
Copy link
Member

headius commented Mar 29, 2015

Filed as https://bugs.ruby-lang.org/issues/11015 so we'll see what MRI says.

@janko
Copy link
Author

janko commented Mar 30, 2015

They seem to have fixed it. Thanks!

@janko janko closed this as completed Mar 30, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants