apache/openwhisk-runtime-ruby

Zip files without explicit directories entries fails to extract.

jthomas opened this issue · 0 comments

I've discovered a bug that deploying actions from a zip file fails to extract unless the zip files contain all the explicit directory entries for all sub-directories for files.

Here's the content of a zip file that fails to extract.

$ unzip -l minimal.zip
Archive:  minimal.zip
  Length      Date    Time    Name
---------  ---------- -----   ----
      310  01-01-1980 00:00   bundle/bundler/setup.rb
    28160  01-01-1980 00:00   bundle/ruby/2.5.0/cache/betterlorem-0.1.2.gem
    15009  01-01-1980 00:00   bundle/ruby/2.5.0/gems/betterlorem-0.1.2/doc/BetterLorem.html
      246  01-01-1980 00:00   bundle/ruby/2.5.0/gems/betterlorem-0.1.2/doc/created.rid
     2340  01-01-1980 00:00   bundle/ruby/2.5.0/gems/betterlorem-0.1.2/doc/index.html
    23653  01-01-1980 00:00   bundle/ruby/2.5.0/gems/betterlorem-0.1.2/doc/lorem_txt.html
     9608  01-01-1980 00:00   bundle/ruby/2.5.0/gems/betterlorem-0.1.2/doc/rdoc.css
     2032  01-01-1980 00:00   bundle/ruby/2.5.0/gems/betterlorem-0.1.2/doc/table_of_contents.html
     3567  01-01-1980 00:00   bundle/ruby/2.5.0/gems/betterlorem-0.1.2/lib/betterlorem.rb
    21288  01-01-1980 00:00   bundle/ruby/2.5.0/gems/betterlorem-0.1.2/lib/lorem.txt
      657  01-01-1980 00:00   bundle/ruby/2.5.0/gems/betterlorem-0.1.2/spec/betterlorem_spec.rb
      736  01-01-1980 00:00   bundle/ruby/2.5.0/gems/betterlorem-0.1.2/spec/spec_helper.rb
      778  01-01-1980 00:00   bundle/ruby/2.5.0/specifications/betterlorem-0.1.2.gemspec
      243  10-26-2018 14:47   main.rb
---------                     -------
   108627                     14 files

This fails when on this line because the sub-directory bundle/bundler/ does not exist. Zip archives do not have to contain the subdirectory entries for files.

There's a relatively easy fix for this... Change the extraction code to make sure all sub-dirs exist.

zip.each do |file|
          f_path = "output/" + file.name
          FileUtils.mkdir_p(File.dirname(f_path))
          zip.extract(file, f_path)
end

I'll work on a PR next week....