Repository: rubyzip/rubyzip (ruby)

Issue:
Tempfile problems on Windows
The same code used on Windows and Linux behaves differently.
Everything works fine on Linux, but on Windows I get errors when trying to open a stream from a zip file that includes a folder/directory name.

        10: from P:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rubyzip-2.0.0/lib/zip/filesystem.rb:246:in `open'

         9: from P:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rubyzip-2.0.0/lib/zip/filesystem.rb:573:in `get_output_stream'

         8: from P:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rubyzip-2.0.0/lib/zip/file.rb:265:in `get_output_stream'

         7: from P:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rubyzip-2.0.0/lib/zip/file.rb:265:in `new'

         6: from P:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rubyzip-2.0.0/lib/zip/streamable_stream.rb:10:in `initialize'

         5: from P:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rubyzip-2.0.0/lib/zip/streamable_stream.rb:10:in `new'

         4: from P:/Ruby26-x64/lib/ruby/2.6.0/tempfile.rb:131:in `initialize'

         3: from P:/Ruby26-x64/lib/ruby/2.6.0/tmpdir.rb:135:in `create'

         2: from P:/Ruby26-x64/lib/ruby/2.6.0/tempfile.rb:133:in `block in initialize'

         1: from P:/Ruby26-x64/lib/ruby/2.6.0/tempfile.rb:133:in `open'

P:/Ruby26-x64/lib/ruby/2.6.0/tempfile.rb:133:in `initialize': No such file or directory @ rb_sysopen - dvlp/proxy.local__PROJECT$h595f5a46$h4bbd$h4126$h86a6$hec01f155cb67_resource_com$dnomagic$dmagicdraw$duml_umodel$dshared_umodel$dsnapshot20190927-27860-1nww0sq (Errno::ENOENT)

If I alter line 6 in streamable_stream.rb to:
                  nil ##::File.dirname(zipfile)
Which in effect enables Tempfile to use the Dir.tempdir for temporary file location everything seems to work fine.

I would like to understand why the temporary file for Streamable objects is being placed it a local folder instead of just using the Dir.tempdir folder.
Tempfile problems on Windows
The same code used on Windows and Linux behaves differently.
Everything works fine on Linux, but on Windows I get errors when trying to open a stream from a zip file that includes a folder/directory name.

        10: from P:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rubyzip-2.0.0/lib/zip/filesystem.rb:246:in `open'

         9: from P:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rubyzip-2.0.0/lib/zip/filesystem.rb:573:in `get_output_stream'

         8: from P:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rubyzip-2.0.0/lib/zip/file.rb:265:in `get_output_stream'

         7: from P:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rubyzip-2.0.0/lib/zip/file.rb:265:in `new'

         6: from P:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rubyzip-2.0.0/lib/zip/streamable_stream.rb:10:in `initialize'

         5: from P:/Ruby26-x64/lib/ruby/gems/2.6.0/gems/rubyzip-2.0.0/lib/zip/streamable_stream.rb:10:in `new'

         4: from P:/Ruby26-x64/lib/ruby/2.6.0/tempfile.rb:131:in `initialize'

         3: from P:/Ruby26-x64/lib/ruby/2.6.0/tmpdir.rb:135:in `create'

         2: from P:/Ruby26-x64/lib/ruby/2.6.0/tempfile.rb:133:in `block in initialize'

         1: from P:/Ruby26-x64/lib/ruby/2.6.0/tempfile.rb:133:in `open'

P:/Ruby26-x64/lib/ruby/2.6.0/tempfile.rb:133:in `initialize': No such file or directory @ rb_sysopen - dvlp/proxy.local__PROJECT$h595f5a46$h4bbd$h4126$h86a6$hec01f155cb67_resource_com$dnomagic$dmagicdraw$duml_umodel$dshared_umodel$dsnapshot20190927-27860-1nww0sq (Errno::ENOENT)

If I alter line 6 in streamable_stream.rb to:
                  nil ##::File.dirname(zipfile)
Which in effect enables Tempfile to use the Dir.tempdir for temporary file location everything seems to work fine.

I would like to understand why the temporary file for Streamable objects is being placed it a local folder instead of just using the Dir.tempdir folder.


Discussion:
This does seem a bit odd. I'll have a think about this and work up a fix if I can't see any reason why this is currently set up the way that it is.

@jdleesmiller you can assign this to me if you like.
This does seem a bit odd. I'll have a think about this and work up a fix if I can't see any reason why this is currently set up the way that it is.

@jdleesmiller you can assign this to me if you like.

Patch:
diff --git a/lib/zip.rb b/lib/zip.rb
--- a/lib/zip.rb
+++ b/lib/zip.rb
@@ -1,7 +1,6 @@
 require 'delegate'
 require 'singleton'
 require 'tempfile'
-require 'tmpdir'
 require 'fileutils'
 require 'stringio'
 require 'zlib'
diff --git a/lib/zip/streamable_stream.rb b/lib/zip/streamable_stream.rb
--- a/lib/zip/streamable_stream.rb
+++ b/lib/zip/streamable_stream.rb
@@ -2,12 +2,7 @@ module Zip
   class StreamableStream < DelegateClass(Entry) # nodoc:all
     def initialize(entry)
       super(entry)
-      dirname = if zipfile.is_a?(::String)
-                  ::File.dirname(zipfile)
-                else
-                  nil
-                end
-      @temp_file = Tempfile.new(::File.basename(name), dirname)
+      @temp_file = Tempfile.new(::File.basename(name))
       @temp_file.binmode
     end
 


Test patch:
diff --git a/test/test_helper.rb b/test/test_helper.rb
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -2,6 +2,7 @@
 require 'minitest/autorun'
 require 'minitest/unit'
 require 'fileutils'
+require 'tmpdir'
 require 'digest/sha1'
 require 'zip'
 require 'gentestfiles'