You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by id...@apache.org on 2015/03/11 01:24:46 UTC

[04/10] mesos git commit: Move stat related functions to os/stat.hpp.

Move stat related functions to os/stat.hpp.

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


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

Branch: refs/heads/master
Commit: 3c13532fd9aaffc8a99c4d5802e85f594d76c349
Parents: da1b716
Author: Ian Downes <id...@twitter.com>
Authored: Tue Mar 3 14:39:24 2015 -0800
Committer: Ian Downes <id...@twitter.com>
Committed: Tue Mar 10 17:18:25 2015 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/3rdparty/stout/README.md    |  4 +-
 .../3rdparty/stout/include/Makefile.am          |  1 +
 .../3rdparty/stout/include/stout/os.hpp         | 53 +-------------
 .../3rdparty/stout/include/stout/os/stat.hpp    | 74 ++++++++++++++++++++
 4 files changed, 80 insertions(+), 52 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/3c13532f/3rdparty/libprocess/3rdparty/stout/README.md
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/README.md b/3rdparty/libprocess/3rdparty/stout/README.md
index 62a4051..587f015 100644
--- a/3rdparty/libprocess/3rdparty/stout/README.md
+++ b/3rdparty/libprocess/3rdparty/stout/README.md
@@ -246,7 +246,7 @@ To make reading and writing from files easier there are implementations of `os::
 
 #### Files
 
-Most of the ways to get or set information about files requires complicated calls using the `stat` family of functions. We provide simple wrappers around `stat` via things like `os::exists`, `os::isdir`, `os::isfile`, and `os::islink`.
+Most of the ways to get or set information about files requires complicated calls using the `stat` family of functions. We provide simple wrappers around `stat` via things like `os::exists`, `os::stat::isdir`, `os::stat::isfile`, and `os::stat::islink`.
 
 #### Processes
 
@@ -557,4 +557,4 @@ bottleneck, and if it is we'd love to hear from you!
 
 The library WILL NEVER throw exceptions and will attempt to capture
 any exceptions thrown by underlying C++ functions and convert them
-into an [Error](#error).
\ No newline at end of file
+into an [Error](#error).

http://git-wip-us.apache.org/repos/asf/mesos/blob/3c13532f/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
index ac2bbed..e2e0971 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/libprocess/3rdparty/stout/include/Makefile.am
@@ -56,6 +56,7 @@ nobase_include_HEADERS =		\
   stout/os/sendfile.hpp			\
   stout/os/shell.hpp			\
   stout/os/signals.hpp			\
+  stout/os/stat.hpp			\
   stout/os/permissions.hpp		\
   stout/os/pstree.hpp			\
   stout/os/sysctl.hpp			\

http://git-wip-us.apache.org/repos/asf/mesos/blob/3c13532f/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
index d28f3f7..c13680b 100644
--- a/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os.hpp
@@ -38,8 +38,6 @@
 #include <linux/version.h>
 #endif // __linux__
 
-#include <sys/stat.h>
-#include <sys/statvfs.h>
 #ifdef __linux__
 #include <sys/sysinfo.h>
 #endif // __linux__
@@ -86,6 +84,7 @@
 #include <stout/os/sendfile.hpp>
 #include <stout/os/shell.hpp>
 #include <stout/os/signals.hpp>
+#include <stout/os/stat.hpp>
 #ifdef __APPLE__
 #include <stout/os/sysctl.hpp>
 #endif // __APPLE__
@@ -369,52 +368,6 @@ inline Result<std::string> realpath(const std::string& path)
 }
 
 
-inline bool isdir(const std::string& path)
-{
-  struct stat s;
-
-  if (::stat(path.c_str(), &s) < 0) {
-    return false;
-  }
-  return S_ISDIR(s.st_mode);
-}
-
-
-inline bool isfile(const std::string& path)
-{
-  struct stat s;
-
-  if (::stat(path.c_str(), &s) < 0) {
-    return false;
-  }
-  return S_ISREG(s.st_mode);
-}
-
-
-inline bool islink(const std::string& path)
-{
-  struct stat s;
-
-  if (::lstat(path.c_str(), &s) < 0) {
-    return false;
-  }
-  return S_ISLNK(s.st_mode);
-}
-
-
-// TODO(benh): Put this in the 'paths' or 'files' or 'fs' namespace.
-inline Try<long> mtime(const std::string& path)
-{
-  struct stat s;
-
-  if (::lstat(path.c_str(), &s) < 0) {
-    return ErrnoError("Error invoking stat for '" + path + "'");
-  }
-
-  return s.st_mtime;
-}
-
-
 inline Try<Nothing> mkdir(const std::string& directory, bool recursive = true)
 {
   if (!recursive) {
@@ -793,7 +746,7 @@ inline Try<std::list<std::string> > find(
 {
   std::list<std::string> results;
 
-  if (!isdir(directory)) {
+  if (!stat::isdir(directory)) {
     return Error("'" + directory + "' is not a directory");
   }
 
@@ -802,7 +755,7 @@ inline Try<std::list<std::string> > find(
     foreach (const std::string& entry, entries.get()) {
       std::string path = path::join(directory, entry);
       // If it's a directory, recurse.
-      if (isdir(path) && !islink(path)) {
+      if (stat::isdir(path) && !stat::islink(path)) {
         Try<std::list<std::string> > matches = find(path, pattern);
         if (matches.isError()) {
           return matches;

http://git-wip-us.apache.org/repos/asf/mesos/blob/3c13532f/3rdparty/libprocess/3rdparty/stout/include/stout/os/stat.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/3rdparty/stout/include/stout/os/stat.hpp b/3rdparty/libprocess/3rdparty/stout/include/stout/os/stat.hpp
new file mode 100644
index 0000000..17bfc6f
--- /dev/null
+++ b/3rdparty/libprocess/3rdparty/stout/include/stout/os/stat.hpp
@@ -0,0 +1,74 @@
+/**
+ * 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.
+ */
+#ifndef __STOUT_OS_STAT_HPP__
+#define __STOUT_OS_STAT_HPP__
+
+#include <sys/stat.h>
+#include <sys/statvfs.h>
+
+#include <string>
+
+#include <stout/try.hpp>
+
+namespace os {
+namespace stat {
+
+inline bool isdir(const std::string& path)
+{
+  struct stat s;
+
+  if (::stat(path.c_str(), &s) < 0) {
+    return false;
+  }
+  return S_ISDIR(s.st_mode);
+}
+
+
+inline bool isfile(const std::string& path)
+{
+  struct stat s;
+
+  if (::stat(path.c_str(), &s) < 0) {
+    return false;
+  }
+  return S_ISREG(s.st_mode);
+}
+
+
+
+inline bool islink(const std::string& path)
+{
+  struct stat s;
+
+  if (::lstat(path.c_str(), &s) < 0) {
+    return false;
+  }
+  return S_ISLNK(s.st_mode);
+}
+
+
+inline Try<long> mtime(const std::string& path)
+{
+  struct stat s;
+
+  if (::lstat(path.c_str(), &s) < 0) {
+    return ErrnoError("Error invoking stat for '" + path + "'");
+  }
+
+  return s.st_mtime;
+}
+
+} // namespace stat {
+} // namespace os {
+#endif // __STOUT_OS_STAT_HPP__