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 2018/05/02 01:38:17 UTC

[17/31] mesos git commit: Added overloads for `int_fd` to `os::stat::isdir()` and `size()`.

Added overloads for `int_fd` to `os::stat::isdir()` and `size()`.

These should be refactored to share the common code, and the
additional overloads added to the other APIs too. However, it is not
currently necessary, and would go unused.

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


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

Branch: refs/heads/master
Commit: cf6c3324203d3ca67d7c24469046f964f5fc0e6e
Parents: 90f488c
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Tue Mar 20 20:15:30 2018 -0700
Committer: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Committed: Tue May 1 18:36:04 2018 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/os/posix/stat.hpp  | 31 ++++++++++++++++++++
 .../stout/include/stout/os/windows/stat.hpp     | 27 +++++++++++++++++
 2 files changed, 58 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/cf6c3324/3rdparty/stout/include/stout/os/posix/stat.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/stat.hpp b/3rdparty/stout/include/stout/os/posix/stat.hpp
index 5835374..8bb8e2c 100644
--- a/3rdparty/stout/include/stout/os/posix/stat.hpp
+++ b/3rdparty/stout/include/stout/os/posix/stat.hpp
@@ -62,6 +62,17 @@ inline Try<struct ::stat> stat(
   UNREACHABLE();
 }
 
+
+inline Try<struct ::stat> stat(const int_fd fd)
+{
+  struct ::stat s;
+
+  if (::fstat(fd, &s) < 0) {
+    return ErrnoError();
+  }
+  return s;
+}
+
 } // namespace internal {
 
 inline bool islink(const std::string& path)
@@ -84,6 +95,14 @@ inline bool isdir(
 }
 
 
+// TODO(andschwa): Share logic with other overload.
+inline bool isdir(const int_fd fd)
+{
+  Try<struct ::stat> s = internal::stat(fd);
+  return s.isSome() && S_ISDIR(s->st_mode);
+}
+
+
 inline bool isfile(
     const std::string& path,
     const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
@@ -110,6 +129,18 @@ inline Try<Bytes> size(
 }
 
 
+// TODO(andschwa): Share logic with other overload.
+inline Try<Bytes> size(const int_fd fd)
+{
+  Try<struct ::stat> s = internal::stat(fd);
+  if (s.isError()) {
+    return Error(s.error());
+  }
+
+  return Bytes(s->st_size);
+}
+
+
 inline Try<long> mtime(
     const std::string& path,
     const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)

http://git-wip-us.apache.org/repos/asf/mesos/blob/cf6c3324/3rdparty/stout/include/stout/os/windows/stat.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/stat.hpp b/3rdparty/stout/include/stout/os/windows/stat.hpp
index c04953e..93bc949 100644
--- a/3rdparty/stout/include/stout/os/windows/stat.hpp
+++ b/3rdparty/stout/include/stout/os/windows/stat.hpp
@@ -20,6 +20,8 @@
 #include <stout/unreachable.hpp>
 #include <stout/windows.hpp>
 
+#include <stout/os/int_fd.hpp>
+
 #include <stout/internal/windows/attributes.hpp>
 #include <stout/internal/windows/longpath.hpp>
 #include <stout/internal/windows/reparsepoint.hpp>
@@ -57,6 +59,19 @@ inline bool isdir(
 }
 
 
+// TODO(andschwa): Refactor `GetFileInformationByHandle` into its own function.
+inline bool isdir(const int_fd& fd)
+{
+  BY_HANDLE_FILE_INFORMATION info;
+  const BOOL result = ::GetFileInformationByHandle(fd, &info);
+  if (result == FALSE) {
+    return false;
+  }
+
+  return info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
+}
+
+
 inline bool isfile(
     const std::string& path,
     const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
@@ -117,6 +132,18 @@ inline Try<Bytes> size(
 }
 
 
+inline Try<Bytes> size(const int_fd& fd)
+{
+  LARGE_INTEGER file_size;
+
+  if (::GetFileSizeEx(fd, &file_size) == 0) {
+    return WindowsError();
+  }
+
+  return Bytes(file_size.QuadPart);
+}
+
+
 // TODO(andschwa): Replace `::_stat`. See MESOS-8275.
 inline Try<long> mtime(
     const std::string& path,