You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by an...@apache.org on 2017/12/09 02:36:11 UTC

[09/11] mesos git commit: Fixed bug where we didn't check non-localhost URIs were absolute.

Fixed bug where we didn't check non-localhost URIs were absolute.

The previous change here subtley missed that we check if the path is
absolute if it is a URI, based on `fileUri`, and stopped setting
`fileUri = true` when the path was a `file://` URI, but not
`file://localhost`.

Now we set `fileUri = true` if the URI starts with `file://`, and then
use `path::from_uri()` to strip `file://`, and `strings::remove()` to
strip the remaining `localhost` prefix.


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

Branch: refs/heads/master
Commit: 74d22473bbc644c2aa12977f4eca4176a04f418d
Parents: 245af40
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Fri Dec 8 16:06:42 2017 -0800
Committer: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Committed: Fri Dec 8 16:37:12 2017 -0800

----------------------------------------------------------------------
 src/slave/containerizer/fetcher.cpp | 22 ++++++++--------------
 1 file changed, 8 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/74d22473/src/slave/containerizer/fetcher.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/fetcher.cpp b/src/slave/containerizer/fetcher.cpp
index 3193923..8b26e88 100644
--- a/src/slave/containerizer/fetcher.cpp
+++ b/src/slave/containerizer/fetcher.cpp
@@ -31,6 +31,7 @@
 #include <stout/net.hpp>
 #include <stout/path.hpp>
 #include <stout/strings.hpp>
+#include <stout/uri.hpp>
 #ifdef __WINDOWS__
 #include <stout/windows.hpp>
 #endif // __WINDOWS__
@@ -70,9 +71,6 @@ namespace mesos {
 namespace internal {
 namespace slave {
 
-static const string FILE_URI_PREFIX = "file://";
-static const string FILE_URI_LOCALHOST = "file://localhost";
-
 static const string CACHE_FILE_NAME_PREFIX = "c";
 
 
@@ -191,20 +189,16 @@ Result<string> Fetcher::uriToLocalPath(
     const string& uri,
     const Option<string>& frameworksHome)
 {
-  if (!strings::startsWith(uri, FILE_URI_PREFIX) &&
-      strings::contains(uri, "://")) {
-    return None();
-  }
+  const bool fileUri = strings::startsWith(uri, uri::FILE_PREFIX);
 
-  string path = uri;
-  bool fileUri = false;
-
-  if (strings::startsWith(path, FILE_URI_LOCALHOST)) {
-    path = path.substr(FILE_URI_LOCALHOST.size());
-    fileUri = true;
+  if (!fileUri && strings::contains(uri, "://")) {
+    return None();
   }
 
-  path = path::from_uri(path);
+  // TODO(andschwa): Fix `path::from_uri` to remove hostname component, which it
+  // currently does not do, so we remove `localhost` manually here.
+  string path =
+    strings::remove(path::from_uri(uri), "localhost", strings::PREFIX);
 
   if (!path::absolute(path)) {
     if (fileUri) {