You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@openwhisk.apache.org by GitBox <gi...@apache.org> on 2018/11/01 14:54:19 UTC

[GitHub] jthomas closed pull request #15: Fixes #14 - Support zip files without dir entries

jthomas closed pull request #15: Fixes #14 - Support zip files without dir entries
URL: https://github.com/apache/incubator-openwhisk-runtime-ruby/pull/15
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/.gitignore b/.gitignore
index ed2c749..0c3444f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -69,4 +69,5 @@ ansible/roles/nginx/files/*cert.pem
 !tests/dat/actions/python3_virtualenv.zip
 !tests/dat/actions/python_virtualenv_dir.zip
 !tests/dat/actions/python_virtualenv_name.zip
-!tests/dat/actions/zippedaction.zip
\ No newline at end of file
+!tests/dat/actions/zippedaction.zip
+!tests/dat/without_dir_entries.zip
diff --git a/core/ruby2.5Action/rackapp/init.rb b/core/ruby2.5Action/rackapp/init.rb
index eee1767..caefe52 100644
--- a/core/ruby2.5Action/rackapp/init.rb
+++ b/core/ruby2.5Action/rackapp/init.rb
@@ -84,7 +84,9 @@ def valid_code?(path)
     def unzip(zipfile_path, destination_folder)
       Zip::File.open(zipfile_path) do |zip|
         zip.each do |file|
-          zip.extract(file, destination_folder + file.name)
+          f_path = destination_folder + file.name
+          FileUtils.mkdir_p(File.dirname(f_path))
+          zip.extract(file, f_path)
         end
       end
       true
diff --git a/tests/dat/without_dir_entries.zip b/tests/dat/without_dir_entries.zip
new file mode 100644
index 0000000..224a5f9
Binary files /dev/null and b/tests/dat/without_dir_entries.zip differ
diff --git a/tests/src/test/scala/actionContainers/Ruby25ActionContainerTests.scala b/tests/src/test/scala/actionContainers/Ruby25ActionContainerTests.scala
index 1090c14..68146bd 100644
--- a/tests/src/test/scala/actionContainers/Ruby25ActionContainerTests.scala
+++ b/tests/src/test/scala/actionContainers/Ruby25ActionContainerTests.scala
@@ -23,6 +23,8 @@ import common.WskActorSystem
 import actionContainers.{ActionContainer, BasicActionRunnerTests}
 import actionContainers.ActionContainer.withContainer
 import actionContainers.ResourceHelpers.ZipBuilder
+import actionContainers.ResourceHelpers
+import java.nio.file.FileSystems;
 import spray.json._
 
 @RunWith(classOf[JUnitRunner])
@@ -329,6 +331,21 @@ class Ruby25ActionContainerTests extends BasicActionRunnerTests with WskActorSys
     }
   }
 
+  it should "support zip-encoded packages without directory entries" in {
+    val path = FileSystems.getDefault().getPath("dat", "without_dir_entries.zip");
+    val code = ResourceHelpers.readAsBase64(path)
+
+    val (out, err) = withRuby25Container { c =>
+      c.init(initPayload(code))._1 should be(200)
+
+      val (runCode, runRes) = c.run(runPayload(JsObject()))
+
+      runCode should be(200)
+      runRes.get.fields.get("greeting") shouldBe defined
+      runRes.get.fields.get("greeting") shouldBe Some(JsString("Hello stranger!"))
+    }
+  }
+
   it should "fail gracefully on invalid zip files" in {
     // Some text-file encoded to base64.
     val code = "Q2VjaSBuJ2VzdCBwYXMgdW4gemlwLgo="


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services