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

if zipfile is a Pathname, tempfiles get created in unexpected places #328

Closed
aelkiss opened this issue May 4, 2017 · 3 comments
Closed

Comments

@aelkiss
Copy link

aelkiss commented May 4, 2017

Passing Zip::File#open a Pathname can lead to unexpected behavior because of the use if is_a?(String) here:

https://github.com/rubyzip/rubyzip/blob/master/lib/zip/streamable_stream.rb#L5

In particular, if zipfile is not a String in that function, temp files can be created in places the user may not expect and lead to errors if the process doesn't have permission to write to the current directory.

It's unclear to me what the use cases would be where zipfile there isn't an actual path name - it seems like StreamableStream is only used at https://github.com/rubyzip/rubyzip/blob/master/lib/zip/file.rb#L252 -- but if there are valid use cases there, a better default might be to use Dir.tmpdir() rather than the current working directory.

In any case, there are a few possible options here:

  • support Pathname directly
  • In Zip::File#initialize, do @name = file_name.to_s
  • Document that if you pass a filename to Zip::File#initialize, it should be a String rather than something stringlike.

Happy to submit a PR if anyone has a suggestion about the best thing to do here.

@aelkiss
Copy link
Author

aelkiss commented May 4, 2017

Relates to #325

@philliplongman
Copy link

+1

Just ran into this. When passing in a Pathname my temp files were all located in the root directory.

Would love to see a fix. Likewise happy to submit a PR.

@hainesr
Copy link
Member

hainesr commented May 29, 2021

I think this was fixed by #411. Please shout if not.

@hainesr hainesr closed this as completed May 29, 2021
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

No branches or pull requests

3 participants