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-m opened this Issue Mar 26, 2015 · 4 comments

Comments

Projects
None yet
2 participants
@janko-m

janko-m 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

This comment has been minimized.

Show comment
Hide comment
@headius

headius Mar 29, 2015

Member

Thanks for the report!

Member

headius commented Mar 29, 2015

Thanks for the report!

@headius

This comment has been minimized.

Show comment
Hide comment
@headius

headius Mar 29, 2015

Member

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.

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

This comment has been minimized.

Show comment
Hide comment
@headius

headius Mar 29, 2015

Member

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

Member

headius commented Mar 29, 2015

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

@janko-m

This comment has been minimized.

Show comment
Hide comment
@janko-m

janko-m Mar 30, 2015

They seem to have fixed it. Thanks!

janko-m commented Mar 30, 2015

They seem to have fixed it. Thanks!

@janko-m janko-m closed this Mar 30, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment