You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by mp...@apache.org on 2016/01/30 03:45:40 UTC

[1/2] mesos git commit: Windows:[1/2] Replace `os::glob()` with `fs::list()` in stout.

Repository: mesos
Updated Branches:
  refs/heads/master 21e080c5a -> a0aee4f6c


Windows:[1/2] Replace `os::glob()` with `fs::list()` in stout.

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


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

Branch: refs/heads/master
Commit: 4ad7d2f3ccc4f1d515ed19137a6addad310349bc
Parents: 21e080c
Author: Alex Naparu <al...@microsoft.com>
Authored: Wed Nov 25 13:20:24 2015 -0800
Committer: Michael Park <mp...@apache.org>
Committed: Fri Jan 29 18:41:55 2016 -0800

----------------------------------------------------------------------
 .../3rdparty/stout/include/stout/posix/fs.hpp   | 17 +++++++++
 .../3rdparty/stout/include/stout/windows/fs.hpp | 40 ++++++++++++++++++++
 .../stout/tests/os/filesystem_tests.cpp         | 30 +++++++++++++++
 3 files changed, 87 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/4ad7d2f3/3rdparty/libprocess/3rdparty/stout/include/stout/posix/fs.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/posix/fs.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/posix/fs.hpp
index b8c5731..269a4f5 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/posix/fs.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/posix/fs.hpp
@@ -21,6 +21,7 @@
 #include <stout/bytes.hpp>
 #include <stout/error.hpp>
 #include <stout/nothing.hpp>
+#include <stout/os.hpp>
 #include <stout/try.hpp>
 
 // TODO(bmahler): Merge available() and usage() into df() that returns
@@ -60,6 +61,22 @@ inline Try<Nothing> symlink(
   return Nothing();
 }
 
+
+// Returns a list of all files matching the given pattern. On POSIX builds this
+// is just a wrapper on os::glob().
+//
+// This function was added is because glob() is not available on Windows, and we
+// are not making use of any of the heavyweight features of ::glob() anyway.
+//
+// list() is meant to be a lightweight alternative to glob() - the only
+// wildcards it should be used with are `?` and `*`, and only when they appear
+// at the tail end of `pattern` (e.g. `/root/dir/subdir/*.txt` or
+// `/root/dir/subdir/file?.txt`.
+inline Try<std::list<std::string>> list(const std::string& pattern)
+{
+  return os::glob(pattern);
+}
+
 } // namespace fs {
 
 #endif // __STOUT_POSIX_FS_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/4ad7d2f3/3rdparty/libprocess/3rdparty/stout/include/stout/windows/fs.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/fs.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/fs.hpp
index 61bc0ce..7dace7d 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/windows/fs.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/windows/fs.hpp
@@ -81,6 +81,46 @@ inline Try<Nothing> symlink(
   return internal::windows::create_symbolic_link(original, link);
 }
 
+
+// Returns a list of all files matching the given pattern. This is meant to
+// be a lightweight alternative to glob() - the only supported wildcards are
+// `?` and `*`, and only when they appear at the tail end of `pattern` (e.g.
+// `/root/dir/subdir/*.txt` or `/root/dir/subdir/file?.txt`.
+inline Try<std::list<std::string>> list(const std::string& pattern)
+{
+  WIN32_FIND_DATA find_data;
+  const HANDLE search_handle = ::FindFirstFile(pattern.c_str(), &find_data);
+  if (search_handle == INVALID_HANDLE_VALUE) {
+    return WindowsError(
+        "'fs::list' failed when searching for files with pattern '" +
+        pattern + "'");
+  }
+
+  std::list<std::string> found_files;
+
+  do {
+    const std::string current_file(find_data.cFileName);
+
+    // Ignore `.` and `..` entries
+    if (current_file.compare(".") != 0 && current_file.compare("..") != 0) {
+      found_files.push_back(current_file);
+    }
+  } while (::FindNextFile(search_handle, &find_data));
+
+  // Cache `FindNextFile` error, `FindClose` will overwrite it
+  const DWORD error = ::GetLastError();
+  ::FindClose(search_handle);
+
+  if (error != ERROR_NO_MORE_FILES) {
+    ::SetLastError(error);
+    return WindowsError(
+        "'fs::list': 'FindNextFile' failed when searching for files with "
+        "'pattern '" + pattern + "'");
+  }
+
+  return found_files;
+}
+
 } // namespace fs {
 
 #endif // __STOUT_WINDOWS_FS_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/4ad7d2f3/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp b/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
index 4c72e18..01e4b2f 100644
--- a/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
+++ b/3rdparty/libprocess/3rdparty/stout/tests/os/filesystem_tests.cpp
@@ -159,3 +159,33 @@ TEST_F(FsTest, Symlink)
   // Test symlink
   EXPECT_TRUE(os::stat::islink(link));
 }
+
+
+TEST_F(FsTest, List)
+{
+  const string testdir = path::join(os::getcwd(), UUID::random().toString());
+  ASSERT_SOME(os::mkdir(testdir)); // Create the directories.
+
+  // Now write some files.
+  const string file1 = testdir + "/file1.txt";
+  const string file2 = testdir + "/file2.txt";
+  const string file3 = testdir + "/file3.jpg";
+
+  ASSERT_SOME(os::touch(file1));
+  ASSERT_SOME(os::touch(file2));
+  ASSERT_SOME(os::touch(file3));
+
+  // Search all files in folder
+  Try<std::list<std::string>> allFiles = fs::list(path::join(testdir, "*"));
+  ASSERT_TRUE(allFiles.get().size() == 3);
+
+  // Search .jpg files in folder
+  Try<std::list<std::string>> jpgFiles = fs::list(path::join(testdir, "*.jpg"));
+  ASSERT_TRUE(jpgFiles.get().size() == 1);
+
+  // Search test*.txt files in folder
+  Try<std::list<std::string>> testTxtFiles =
+    fs::list(path::join(testdir, "*.txt"));
+
+  ASSERT_TRUE(testTxtFiles.get().size() == 2);
+}


[2/2] mesos git commit: Windows:[2/2] Removed references to `os::glob()` from mesos.

Posted by mp...@apache.org.
Windows:[2/2] Removed references to `os::glob()` from mesos.

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


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

Branch: refs/heads/master
Commit: a0aee4f6c016c7d2ca2034a87a3fe819b1535b98
Parents: 4ad7d2f
Author: Alex Naparu <al...@outlook.com>
Authored: Fri Jan 29 18:10:04 2016 -0800
Committer: Michael Park <mp...@apache.org>
Committed: Fri Jan 29 18:42:20 2016 -0800

----------------------------------------------------------------------
 src/cli/mesos.cpp       | 3 ++-
 src/slave/paths.cpp     | 8 ++++----
 src/tests/zookeeper.cpp | 3 ++-
 3 files changed, 8 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/a0aee4f6/src/cli/mesos.cpp
----------------------------------------------------------------------
diff --git a/src/cli/mesos.cpp b/src/cli/mesos.cpp
index bd06653..f76d3ed 100644
--- a/src/cli/mesos.cpp
+++ b/src/cli/mesos.cpp
@@ -19,6 +19,7 @@
 #include <iostream>
 #include <list>
 
+#include <stout/fs.hpp>
 #include <stout/option.hpp>
 #include <stout/os.hpp>
 #include <stout/path.hpp>
@@ -41,7 +42,7 @@ void usage(const char* argv0)
 
   if (PATH.isSome()) {
     foreach (const string& path, strings::split(PATH.get(), ":")) {
-      Try<list<string> > matches = os::glob(path::join(path, "mesos-*"));
+      Try<list<string> > matches = fs::list(path::join(path, "mesos-*"));
       if (matches.isSome()) {
         foreach (const string& match, matches.get()) {
           Try<bool> access = os::access(match, X_OK);

http://git-wip-us.apache.org/repos/asf/mesos/blob/a0aee4f6/src/slave/paths.cpp
----------------------------------------------------------------------
diff --git a/src/slave/paths.cpp b/src/slave/paths.cpp
index 5c650c6..77e86a0 100644
--- a/src/slave/paths.cpp
+++ b/src/slave/paths.cpp
@@ -111,7 +111,7 @@ Try<list<string>> getFrameworkPaths(
     const string& rootDir,
     const SlaveID& slaveId)
 {
-  return os::glob(
+  return fs::list(
       path::join(getSlavePath(rootDir, slaveId), "frameworks", "*"));
 }
 
@@ -151,7 +151,7 @@ Try<list<string>> getExecutorPaths(
     const SlaveID& slaveId,
     const FrameworkID& frameworkId)
 {
-  return os::glob(path::join(
+  return fs::list(path::join(
       getFrameworkPath(rootDir, slaveId, frameworkId),
       "executors",
       "*"));
@@ -189,7 +189,7 @@ Try<list<string>> getExecutorRunPaths(
     const FrameworkID& frameworkId,
     const ExecutorID& executorId)
 {
-  return os::glob(path::join(
+  return fs::list(path::join(
       getExecutorPath(rootDir, slaveId, frameworkId, executorId),
       "runs",
       "*"));
@@ -304,7 +304,7 @@ Try<list<string>> getTaskPaths(
     const ExecutorID& executorId,
     const ContainerID& containerId)
 {
-  return os::glob(path::join(
+  return fs::list(path::join(
       getExecutorRunPath(
           rootDir,
           slaveId,

http://git-wip-us.apache.org/repos/asf/mesos/blob/a0aee4f6/src/tests/zookeeper.cpp
----------------------------------------------------------------------
diff --git a/src/tests/zookeeper.cpp b/src/tests/zookeeper.cpp
index 520a300..d29b100 100644
--- a/src/tests/zookeeper.cpp
+++ b/src/tests/zookeeper.cpp
@@ -28,6 +28,7 @@
 #include <jvm/org/apache/log4j.hpp>
 
 #include <stout/check.hpp>
+#include <stout/fs.hpp>
 #include <stout/lambda.hpp>
 #include <stout/path.hpp>
 #include <stout/os.hpp>
@@ -60,7 +61,7 @@ void ZooKeeperTest::SetUpTestCase()
       path::join(zkHome, "zookeeper-" ZOOKEEPER_VERSION ".jar");
 
     // Now add all the libraries in 'lib' too.
-    Try<list<string> > jars = os::glob(path::join(zkHome, "lib", "*.jar"));
+    Try<list<string> > jars = fs::list(path::join(zkHome, "lib", "*.jar"));
 
     CHECK_SOME(jars);