You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2018/06/05 00:01:26 UTC

[3/4] mesos git commit: Modified the fetcher to use libarchive for extraction.

Modified the fetcher to use libarchive for extraction.

This replaces the fetcher's behavior of shelling out to
`tar -C <destination> -xf <source>` to extract most archive types.
The end result should be identical.

This patch enables the extraction of these formats on Windows.

Review: https://reviews.apache.org/r/67066/


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/2198b961
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/2198b961
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/2198b961

Branch: refs/heads/master
Commit: 2198b961d24b788564d36490cf52f78d7ec07655
Parents: 894d06e
Author: John Kordich <jo...@microsoft.com>
Authored: Mon Jun 4 14:12:00 2018 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jun 4 15:50:56 2018 -0700

----------------------------------------------------------------------
 src/launcher/fetcher.cpp    | 28 ++++++++++++----------------
 src/tests/fetcher_tests.cpp | 26 --------------------------
 2 files changed, 12 insertions(+), 42 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/2198b961/src/launcher/fetcher.cpp
----------------------------------------------------------------------
diff --git a/src/launcher/fetcher.cpp b/src/launcher/fetcher.cpp
index 4cff727..ef8d7eb 100644
--- a/src/launcher/fetcher.cpp
+++ b/src/launcher/fetcher.cpp
@@ -20,6 +20,7 @@
 #include <process/owned.hpp>
 #include <process/subprocess.hpp>
 
+#include <stout/archiver.hpp>
 #include <stout/json.hpp>
 #include <stout/net.hpp>
 #include <stout/option.hpp>
@@ -80,9 +81,18 @@ static Try<bool> extract(
       strings::endsWith(sourcePath, ".tbz2") ||
       strings::endsWith(sourcePath, ".tar.bz2") ||
       strings::endsWith(sourcePath, ".txz") ||
-      strings::endsWith(sourcePath, ".tar.xz")) {
-    command = {"tar", "-C", destinationDirectory, "-xf", sourcePath};
+      strings::endsWith(sourcePath, ".tar.xz") ||
+      strings::endsWith(sourcePath, ".zip")) {
+    Try<Nothing> result = archiver::extract(sourcePath, destinationDirectory);
+    if (result.isError()) {
+      return Error(
+          "Failed to extract archive '" + sourcePath +
+          "' to '" + destinationDirectory + "': " + result.error());
+    }
+    return true;
   } else if (strings::endsWith(sourcePath, ".gz")) {
+    // Unfortunately, libarchive can't extract bare files, so leave this to
+    // the 'gunzip' program, if it exists.
     string pathWithoutExtension = sourcePath.substr(0, sourcePath.length() - 3);
     string filename = Path(pathWithoutExtension).basename();
     string destinationPath = path::join(destinationDirectory, filename);
@@ -90,20 +100,6 @@ static Try<bool> extract(
     command = {"gunzip", "-d", "-c"};
     in = Subprocess::PATH(sourcePath);
     out = Subprocess::PATH(destinationPath);
-  } else if (strings::endsWith(sourcePath, ".zip")) {
-#ifdef __WINDOWS__
-    command = {"powershell",
-               "-NoProfile",
-               "-Command",
-               "Expand-Archive",
-               "-Force",
-               "-Path",
-               sourcePath,
-               "-DestinationPath",
-               destinationDirectory};
-#else
-    command = {"unzip", "-o", "-d", destinationDirectory, sourcePath};
-#endif // __WINDOWS__
   } else {
     return false;
   }

http://git-wip-us.apache.org/repos/asf/mesos/blob/2198b961/src/tests/fetcher_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/fetcher_tests.cpp b/src/tests/fetcher_tests.cpp
index 8c353f2..5e6a1c3 100644
--- a/src/tests/fetcher_tests.cpp
+++ b/src/tests/fetcher_tests.cpp
@@ -1000,33 +1000,7 @@ TEST_F(FetcherTest, UNZIP_ExtractInvalidFile)
       os::getcwd(),
       None());
 
-#ifdef __WINDOWS__
-  // On Windows, PowerShell doesn't consider a CRC error to be an error,
-  // so it succeeds, whereas the zip utility errors.
-  //
-  // TODO(coffler): When we move to programmatically dealing with various
-  // data files (tar, gzip, zip, etc), we should be able to resolve this.
-  // See MESOS-7740 for further details.
-  AWAIT_READY(fetch);
-#else
   AWAIT_FAILED(fetch);
-#endif // __WINDOWS__
-
-  string extractedFile = path::join(os::getcwd(), "world");
-  ASSERT_TRUE(os::exists(extractedFile));
-
-  ASSERT_SOME_EQ("hello hello\n", os::read(extractedFile));
-
-#ifdef __WINDOWS__
-  // TODO(coffler): Eliminate with programmatic decoding of container files.
-  // See MESOS-7740 for further details.
-  //
-  // On Windows, PowerShell doesn't consider a CRC error to be an error.
-  // Adjust metrics appropriately to not expect an error back.
-  verifyMetrics(1, 0);
-#else
-  verifyMetrics(0, 1);
-#endif // __WINDOWS__
 }