You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by me...@apache.org on 2014/10/02 02:34:25 UTC
git commit: Switched path::join() to be variadic
Repository: mesos
Updated Branches:
refs/heads/master 602e40c8c -> b08fccf8f
Switched path::join() to be variadic
Review: https://reviews.apache.org/r/25818
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/b08fccf8
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/b08fccf8
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/b08fccf8
Branch: refs/heads/master
Commit: b08fccf8f5ea325b8c38055b5f2c03509744dd9b
Parents: 602e40c
Author: Cody Maloney <co...@mesosphere.io>
Authored: Wed Oct 1 17:10:03 2014 -0700
Committer: Adam B <ad...@mesosphere.io>
Committed: Wed Oct 1 17:10:03 2014 -0700
----------------------------------------------------------------------
3rdparty/libprocess/3rdparty/Makefile.am | 1 +
3rdparty/libprocess/3rdparty/stout/Makefile.am | 1 +
.../3rdparty/stout/include/stout/path.hpp | 77 ++++++++------------
.../3rdparty/stout/include/stout/strings.hpp | 6 ++
.../3rdparty/stout/tests/path_tests.cpp | 39 ++++++++++
5 files changed, 79 insertions(+), 45 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/b08fccf8/3rdparty/libprocess/3rdparty/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/Makefile.am b/3rdparty/libprocess/3rdparty/Makefile.am
index bd1dc8d..256df0b 100644
--- a/3rdparty/libprocess/3rdparty/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/Makefile.am
@@ -162,6 +162,7 @@ stout_tests_SOURCES = \
$(STOUT)/tests/none_tests.cpp \
$(STOUT)/tests/option_tests.cpp \
$(STOUT)/tests/os_tests.cpp \
+ $(STOUT)/tests/path_tests.cpp \
$(STOUT)/tests/protobuf_tests.cpp \
$(STOUT)/tests/protobuf_tests.pb.cc \
$(STOUT)/tests/protobuf_tests.pb.h \
http://git-wip-us.apache.org/repos/asf/mesos/blob/b08fccf8/3rdparty/libprocess/3rdparty/stout/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/Makefile.am b/3rdparty/libprocess/3rdparty/stout/Makefile.am
index 2ee5a0b..125b3fa 100644
--- a/3rdparty/libprocess/3rdparty/stout/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/Makefile.am
@@ -29,6 +29,7 @@ EXTRA_DIST = \
tests/net_tests.cpp \
tests/none_tests.cpp \
tests/option_tests.cpp \
+ tests/path_tests.cpp \
tests/os_tests.cpp \
tests/os/sendfile_tests.cpp \
tests/os/setns_tests.cpp \
http://git-wip-us.apache.org/repos/asf/mesos/blob/b08fccf8/3rdparty/libprocess/3rdparty/stout/include/stout/path.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/path.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/path.hpp
index bc6920a..63433ef 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/path.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/path.hpp
@@ -15,59 +15,34 @@
#define __STOUT_PATH_HPP__
#include <string>
+#include <utility>
#include <vector>
#include "strings.hpp"
namespace path {
-inline std::string join(const std::string& path1, const std::string& path2)
-{
- return
- strings::remove(path1, "/", strings::SUFFIX) + "/" +
- strings::remove(path2, "/", strings::PREFIX);
-}
-
-
-inline std::string join(
- const std::string& path1,
- const std::string& path2,
- const std::string& path3)
-{
- return join(path1, join(path2, path3));
-}
-
-
-inline std::string join(
- const std::string& path1,
- const std::string& path2,
- const std::string& path3,
- const std::string& path4)
-{
- return join(path1, join(path2, path3, path4));
-}
-
-inline std::string join(
- const std::string& path1,
- const std::string& path2,
- const std::string& path3,
- const std::string& path4,
- const std::string& path5)
+template<typename ...T>
+std::string join(const std::string& path, T&&... tail)
{
- return join(path1, join(path2, join(path3, join(path4, path5))));
-}
-
+ std::string tailJoined = strings::join(
+ "/",
+ strings::trim(std::forward<T>(tail), "/")...);
+
+ // The first path chunk is special in that if it starts with a '/',
+ // we want to keep that.
+ if (path.empty()) {
+ return tailJoined;
+ }
-inline std::string join(
- const std::string& path1,
- const std::string& path2,
- const std::string& path3,
- const std::string& path4,
- const std::string& path5,
- const std::string& path6)
-{
- return join(path1, join(path2, path3, path4, path5, path6));
+ // If the first chunk ends with a '/', don't append another using
+ // join. This also handles the case with the first path part is just
+ // '/'.
+ if (path.back() == '/') {
+ return path + tailJoined;
+ }
+ return strings::join("/", path, tailJoined);
}
@@ -79,7 +54,19 @@ inline std::string join(const std::vector<std::string>& paths)
std::string result = paths[0];
for (size_t i = 1; i < paths.size(); ++i) {
- result = join(result, paths[i]);
+ const std::string &path = paths[i];
+
+ // Don't insert extra '/' for empty paths.
+ if (path.empty()) {
+ continue;
+ }
+
+ // If result is empty, fill it.
+ if (result.empty()) {
+ result = path;
+ continue;
+ }
+ result = join(result, path);
}
return result;
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/b08fccf8/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
index 14567f1..01e47ff 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/strings.hpp
@@ -286,6 +286,12 @@ std::string join(
}
+// Ensure std::string doesn't fall into the iterable case
+inline std::string join(const std::string &seperator, const std::string &str) {
+ return str;
+}
+
+
// Use duck-typing to join any iterable.
template <typename Iterable>
inline std::string join(const std::string& separator, const Iterable& i)
http://git-wip-us.apache.org/repos/asf/mesos/blob/b08fccf8/3rdparty/libprocess/3rdparty/stout/tests/path_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/path_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/path_tests.cpp
new file mode 100644
index 0000000..aedf935
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/tests/path_tests.cpp
@@ -0,0 +1,39 @@
+/**
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+#include <gtest/gtest.h>
+
+#include <string>
+#include <vector>
+
+#include <stout/path.hpp>
+
+using std::string;
+using std::vector;
+
+
+TEST(PathTest, Join)
+{
+ EXPECT_EQ("a/b/c", path::join("a", "b", "c"));
+ EXPECT_EQ("a/b/c", path::join(string("a"), string("b"), string("c")));
+ EXPECT_EQ("a/b/c", path::join(string("a"), "b", string("c")));
+ EXPECT_EQ("a/b/c", path::join(vector<string>({"a", "b", "c"})));
+ EXPECT_EQ("", path::join(vector<string>()));
+ EXPECT_EQ("", path::join(vector<string>({"", "", ""})));
+ EXPECT_EQ("/asdf", path::join("/", "asdf"));
+ EXPECT_EQ("/", path::join("", "/", ""));
+ EXPECT_EQ("a/b/c", path::join("a/", "b/", "c/"));
+ EXPECT_EQ("/a/b/c", path::join("/a", "/b", "/c"));
+ EXPECT_EQ("/a/b/c", path::join("/a/", "/b/", "/c/"));
+ EXPECT_EQ("a/b/c", path::join("a/", "/b/", "/c/"));
+}