You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by jo...@apache.org on 2017/07/11 01:39:00 UTC
[14/50] mesos git commit: Refactored `enum FollowSymlink` to an `enum
class FollowSymlink`.
Refactored `enum FollowSymlink` to an `enum class FollowSymlink`.
Using `enum class` is preferred as it provides stronger type-safety.
The `enum class FollowSymlink` definition is moved into
the POSIX `stat.hpp` and Windows `reparsepoint.hpp` headers
to avoid a circular dependency.
Review: https://reviews.apache.org/r/60308/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/841f8793
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/841f8793
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/841f8793
Branch: refs/heads/master
Commit: 841f879375b32989193ed7ac86ae3341e5a57468
Parents: d107bb7
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Fri Jul 7 12:00:53 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:33 2017 -0700
----------------------------------------------------------------------
.../stout/internal/windows/reparsepoint.hpp | 18 ++++++
3rdparty/stout/include/stout/os/posix/stat.hpp | 38 ++++++++-----
3rdparty/stout/include/stout/os/stat.hpp | 18 ------
.../stout/include/stout/os/windows/stat.hpp | 30 +++++-----
3rdparty/stout/tests/os_tests.cpp | 60 +++++++++++++-------
5 files changed, 97 insertions(+), 67 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/841f8793/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp b/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
index 3a1ea16..dcadfed 100644
--- a/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
+++ b/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
@@ -27,6 +27,24 @@
#include <stout/internal/windows/attributes.hpp>
#include <stout/internal/windows/longpath.hpp>
+
+namespace os {
+namespace stat {
+
+// Specify whether symlink path arguments should be followed or
+// not. APIs in the os::stat family that take a FollowSymlink
+// argument all provide FollowSymlink::FOLLOW_SYMLINK as the default value,
+// so they will follow symlinks unless otherwise specified.
+enum class FollowSymlink
+{
+ DO_NOT_FOLLOW_SYMLINK,
+ FOLLOW_SYMLINK
+};
+
+} // namespace stat {
+} // namespace os {
+
+
// We pass this struct to `DeviceIoControl` to get information about a reparse
// point (including things like whether it's a symlink). It is normally part of
// the Device Driver Kit (DDK), specifically `nitfs.h`, but rather than taking
http://git-wip-us.apache.org/repos/asf/mesos/blob/841f8793/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 2762c41..5835374 100644
--- a/3rdparty/stout/include/stout/os/posix/stat.hpp
+++ b/3rdparty/stout/include/stout/os/posix/stat.hpp
@@ -27,6 +27,17 @@ namespace os {
namespace stat {
+// Specify whether symlink path arguments should be followed or
+// not. APIs in the os::stat family that take a FollowSymlink
+// argument all provide FollowSymlink::FOLLOW_SYMLINK as the default value,
+// so they will follow symlinks unless otherwise specified.
+enum class FollowSymlink
+{
+ DO_NOT_FOLLOW_SYMLINK,
+ FOLLOW_SYMLINK
+};
+
+
namespace internal {
inline Try<struct ::stat> stat(
@@ -36,12 +47,12 @@ inline Try<struct ::stat> stat(
struct ::stat s;
switch (follow) {
- case DO_NOT_FOLLOW_SYMLINK:
+ case FollowSymlink::DO_NOT_FOLLOW_SYMLINK:
if (::lstat(path.c_str(), &s) < 0) {
return ErrnoError("Failed to lstat '" + path + "'");
}
return s;
- case FOLLOW_SYMLINK:
+ case FollowSymlink::FOLLOW_SYMLINK:
if (::stat(path.c_str(), &s) < 0) {
return ErrnoError("Failed to stat '" + path + "'");
}
@@ -55,17 +66,18 @@ inline Try<struct ::stat> stat(
inline bool islink(const std::string& path)
{
- // By definition, you don't followsymlinks when trying
+ // By definition, you don't follow symlinks when trying
// to find whether a path is a link. If you followed it,
// it wouldn't ever be a link.
- Try<struct ::stat> s = internal::stat(path, DO_NOT_FOLLOW_SYMLINK);
+ Try<struct ::stat> s = internal::stat(
+ path, FollowSymlink::DO_NOT_FOLLOW_SYMLINK);
return s.isSome() && S_ISLNK(s->st_mode);
}
inline bool isdir(
const std::string& path,
- const FollowSymlink follow = FOLLOW_SYMLINK)
+ const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
{
Try<struct ::stat> s = internal::stat(path, follow);
return s.isSome() && S_ISDIR(s->st_mode);
@@ -74,7 +86,7 @@ inline bool isdir(
inline bool isfile(
const std::string& path,
- const FollowSymlink follow = FOLLOW_SYMLINK)
+ const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
{
Try<struct ::stat> s = internal::stat(path, follow);
return s.isSome() && S_ISREG(s->st_mode);
@@ -87,7 +99,7 @@ inline bool isfile(
// name (strlen).
inline Try<Bytes> size(
const std::string& path,
- const FollowSymlink follow = FOLLOW_SYMLINK)
+ const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
{
Try<struct ::stat> s = internal::stat(path, follow);
if (s.isError()) {
@@ -100,7 +112,7 @@ inline Try<Bytes> size(
inline Try<long> mtime(
const std::string& path,
- const FollowSymlink follow = FOLLOW_SYMLINK)
+ const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
{
Try<struct ::stat> s = internal::stat(path, follow);
if (s.isError()) {
@@ -113,7 +125,7 @@ inline Try<long> mtime(
inline Try<mode_t> mode(
const std::string& path,
- const FollowSymlink follow = FOLLOW_SYMLINK)
+ const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
{
Try<struct ::stat> s = internal::stat(path, follow);
if (s.isError()) {
@@ -126,7 +138,7 @@ inline Try<mode_t> mode(
inline Try<dev_t> dev(
const std::string& path,
- const FollowSymlink follow = FOLLOW_SYMLINK)
+ const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
{
Try<struct ::stat> s = internal::stat(path, follow);
if (s.isError()) {
@@ -139,7 +151,7 @@ inline Try<dev_t> dev(
inline Try<dev_t> rdev(
const std::string& path,
- const FollowSymlink follow = FOLLOW_SYMLINK)
+ const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
{
Try<struct ::stat> s = internal::stat(path, follow);
if (s.isError()) {
@@ -156,7 +168,7 @@ inline Try<dev_t> rdev(
inline Try<ino_t> inode(
const std::string& path,
- const FollowSymlink follow = FOLLOW_SYMLINK)
+ const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
{
Try<struct ::stat> s = internal::stat(path, follow);
if (s.isError()) {
@@ -169,7 +181,7 @@ inline Try<ino_t> inode(
inline Try<uid_t> uid(
const std::string& path,
- const FollowSymlink follow = FOLLOW_SYMLINK)
+ const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
{
Try<struct ::stat> s = internal::stat(path, follow);
if (s.isError()) {
http://git-wip-us.apache.org/repos/asf/mesos/blob/841f8793/3rdparty/stout/include/stout/os/stat.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/stat.hpp b/3rdparty/stout/include/stout/os/stat.hpp
index d002c98..f4f76c7 100644
--- a/3rdparty/stout/include/stout/os/stat.hpp
+++ b/3rdparty/stout/include/stout/os/stat.hpp
@@ -13,24 +13,6 @@
#ifndef __STOUT_OS_STAT_HPP__
#define __STOUT_OS_STAT_HPP__
-namespace os {
-
-namespace stat {
-
-// Specify whether symlink path arguments should be followed or
-// not. APIs in the os::stat family that take a FollowSymlink
-// argument all provide FOLLOW_SYMLINK as the default value,
-// so they will follow symlinks unless otherwise specified.
-enum FollowSymlink
-{
- DO_NOT_FOLLOW_SYMLINK,
- FOLLOW_SYMLINK
-};
-
-} // namespace stat {
-
-} // namespace os {
-
// For readability, we minimize the number of #ifdef blocks in the code by
// splitting platform specific system calls into separate directories.
#ifdef __WINDOWS__
http://git-wip-us.apache.org/repos/asf/mesos/blob/841f8793/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 b22ae80..0db6d48 100644
--- a/3rdparty/stout/include/stout/os/windows/stat.hpp
+++ b/3rdparty/stout/include/stout/os/windows/stat.hpp
@@ -38,11 +38,11 @@ inline bool islink(const std::string& path);
inline bool isdir(
const std::string& path,
- const FollowSymlink follow = FOLLOW_SYMLINK)
+ const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
{
// A symlink itself is not a directory.
// If it's not a link, we ignore `follow`.
- if (follow == DO_NOT_FOLLOW_SYMLINK && islink(path)) {
+ if (follow == FollowSymlink::DO_NOT_FOLLOW_SYMLINK && islink(path)) {
return false;
}
@@ -59,13 +59,13 @@ inline bool isdir(
inline bool isfile(
const std::string& path,
- const FollowSymlink follow = FOLLOW_SYMLINK)
+ const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
{
// A symlink itself is a file, but not a regular file.
// On POSIX, this check is done with `S_IFREG`, which
// returns false for symbolic links.
// If it's not a link, we ignore `follow`.
- if (follow == DO_NOT_FOLLOW_SYMLINK && islink(path)) {
+ if (follow == FollowSymlink::DO_NOT_FOLLOW_SYMLINK && islink(path)) {
return false;
}
@@ -99,10 +99,10 @@ inline bool islink(const std::string& path)
// name (strlen).
inline Try<Bytes> size(
const std::string& path,
- const FollowSymlink follow = FOLLOW_SYMLINK)
+ const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
{
switch (follow) {
- case DO_NOT_FOLLOW_SYMLINK: {
+ case FollowSymlink::DO_NOT_FOLLOW_SYMLINK: {
Try<::internal::windows::SymbolicLink> symlink =
::internal::windows::query_symbolic_link_data(path);
@@ -113,7 +113,7 @@ inline Try<Bytes> size(
}
break;
}
- case FOLLOW_SYMLINK: {
+ case FollowSymlink::FOLLOW_SYMLINK: {
struct _stat s;
if (::_stat(path.c_str(), &s) < 0) {
@@ -131,9 +131,9 @@ inline Try<Bytes> size(
inline Try<long> mtime(
const std::string& path,
- const FollowSymlink follow = FOLLOW_SYMLINK)
+ const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
{
- if (follow == DO_NOT_FOLLOW_SYMLINK) {
+ if (follow == FollowSymlink::DO_NOT_FOLLOW_SYMLINK) {
Try<::internal::windows::SymbolicLink> symlink =
::internal::windows::query_symbolic_link_data(path);
@@ -163,11 +163,11 @@ inline Try<long> mtime(
inline Try<mode_t> mode(
const std::string& path,
- const FollowSymlink follow = FOLLOW_SYMLINK)
+ const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
{
struct _stat s;
- if (follow == DO_NOT_FOLLOW_SYMLINK && islink(path)) {
+ if (follow == FollowSymlink::DO_NOT_FOLLOW_SYMLINK && islink(path)) {
return Error("lstat not supported for symlink '" + path + "'");
}
@@ -181,11 +181,11 @@ inline Try<mode_t> mode(
inline Try<dev_t> dev(
const std::string& path,
- const FollowSymlink follow = FOLLOW_SYMLINK)
+ const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
{
struct _stat s;
- if (follow == DO_NOT_FOLLOW_SYMLINK && islink(path)) {
+ if (follow == FollowSymlink::DO_NOT_FOLLOW_SYMLINK && islink(path)) {
return Error("lstat not supported for symlink '" + path + "'");
}
@@ -199,11 +199,11 @@ inline Try<dev_t> dev(
inline Try<ino_t> inode(
const std::string& path,
- const FollowSymlink follow = FOLLOW_SYMLINK)
+ const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
{
struct _stat s;
- if (follow == DO_NOT_FOLLOW_SYMLINK) {
+ if (follow == FollowSymlink::DO_NOT_FOLLOW_SYMLINK) {
return Error("Non-following stat not supported for '" + path + "'");
}
http://git-wip-us.apache.org/repos/asf/mesos/blob/841f8793/3rdparty/stout/tests/os_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/os_tests.cpp b/3rdparty/stout/tests/os_tests.cpp
index 7f785b0..b6491c4 100644
--- a/3rdparty/stout/tests/os_tests.cpp
+++ b/3rdparty/stout/tests/os_tests.cpp
@@ -39,15 +39,18 @@
#include <stout/hashset.hpp>
#include <stout/numify.hpp>
#include <stout/os.hpp>
+#include <stout/stopwatch.hpp>
+#include <stout/strings.hpp>
+#include <stout/try.hpp>
+#include <stout/uuid.hpp>
+
#include <stout/os/environment.hpp>
#include <stout/os/int_fd.hpp>
#include <stout/os/kill.hpp>
#include <stout/os/killtree.hpp>
+#include <stout/os/stat.hpp>
+#include <stout/os/stat.hpp>
#include <stout/os/write.hpp>
-#include <stout/stopwatch.hpp>
-#include <stout/strings.hpp>
-#include <stout/try.hpp>
-#include <stout/uuid.hpp>
#if defined(__APPLE__) || defined(__FreeBSD__)
#include <stout/os/sysctl.hpp>
@@ -62,6 +65,8 @@ using os::Fork;
using os::Process;
using os::ProcessTree;
+using os::stat::FollowSymlink;
+
using std::list;
using std::set;
using std::string;
@@ -222,8 +227,10 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(OsTest, SYMLINK_Size)
// The reported file size should be the same whether following links
// or not, given that the input parameter is not a link.
- EXPECT_SOME_EQ(size, os::stat::size(file, os::stat::FOLLOW_SYMLINK));
- EXPECT_SOME_EQ(size, os::stat::size(file, os::stat::DO_NOT_FOLLOW_SYMLINK));
+ EXPECT_SOME_EQ(size,
+ os::stat::size(file, FollowSymlink::FOLLOW_SYMLINK));
+ EXPECT_SOME_EQ(size,
+ os::stat::size(file, FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
EXPECT_ERROR(os::stat::size("aFileThatDoesNotExist"));
@@ -232,11 +239,11 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(OsTest, SYMLINK_Size)
ASSERT_SOME(fs::symlink(file, link));
// Following links we expect the file's size, not the link's.
- EXPECT_SOME_EQ(size, os::stat::size(link, os::stat::FOLLOW_SYMLINK));
+ EXPECT_SOME_EQ(size, os::stat::size(link, FollowSymlink::FOLLOW_SYMLINK));
// Not following links, we expect the string length of the linked path.
EXPECT_SOME_EQ(Bytes(file.size()),
- os::stat::size(link, os::stat::DO_NOT_FOLLOW_SYMLINK));
+ os::stat::size(link, FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
}
@@ -756,8 +763,6 @@ TEST_F(OsTest, User)
TEST_F(OsTest, SYMLINK_Chown)
{
- using os::stat::DO_NOT_FOLLOW_SYMLINK;
-
Result<uid_t> uid = os::getuid();
ASSERT_SOME(uid);
@@ -783,33 +788,46 @@ TEST_F(OsTest, SYMLINK_Chown)
// symlink does not chown that subtree.
EXPECT_SOME(fs::symlink("chown/one/two", "two.link"));
EXPECT_SOME(os::chown(9, 9, "two.link", true));
- EXPECT_SOME_EQ(9u, os::stat::uid("two.link", DO_NOT_FOLLOW_SYMLINK));
- EXPECT_SOME_EQ(0u, os::stat::uid("chown", DO_NOT_FOLLOW_SYMLINK));
+ EXPECT_SOME_EQ(9u,
+ os::stat::uid("two.link", FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
+ EXPECT_SOME_EQ(0u,
+ os::stat::uid("chown", FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
EXPECT_SOME_EQ(0u,
- os::stat::uid("chown/one/two/three/file", DO_NOT_FOLLOW_SYMLINK));
+ os::stat::uid("chown/one/two/three/file",
+ FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
// Recursively chown the whole tree.
EXPECT_SOME(os::chown(9, 9, "chown", true));
- EXPECT_SOME_EQ(9u, os::stat::uid("chown", DO_NOT_FOLLOW_SYMLINK));
EXPECT_SOME_EQ(9u,
- os::stat::uid("chown/one/two/three/file", DO_NOT_FOLLOW_SYMLINK));
+ os::stat::uid("chown", FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
EXPECT_SOME_EQ(9u,
- os::stat::uid("chown/one/two/three/link", DO_NOT_FOLLOW_SYMLINK));
+ os::stat::uid("chown/one/two/three/file",
+ FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
+ EXPECT_SOME_EQ(9u,
+ os::stat::uid("chown/one/two/three/link",
+ FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
// Chown the subtree with the embedded link back and verify that it
// doesn't follow back to the top of the tree.
EXPECT_SOME(os::chown(0, 0, "chown/one/two/three", true));
- EXPECT_SOME_EQ(9u, os::stat::uid("chown", DO_NOT_FOLLOW_SYMLINK));
+ EXPECT_SOME_EQ(9u,
+ os::stat::uid("chown", FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
EXPECT_SOME_EQ(0u,
- os::stat::uid("chown/one/two/three", DO_NOT_FOLLOW_SYMLINK));
+ os::stat::uid("chown/one/two/three",
+ FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
EXPECT_SOME_EQ(0u,
- os::stat::uid("chown/one/two/three/link", DO_NOT_FOLLOW_SYMLINK));
+ os::stat::uid("chown/one/two/three/link",
+ FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
// Verify that non-recursive chown changes the directory and not
// its contents.
EXPECT_SOME(os::chown(0, 0, "chown/one", false));
- EXPECT_SOME_EQ(0u, os::stat::uid("chown/one", DO_NOT_FOLLOW_SYMLINK));
- EXPECT_SOME_EQ(9u, os::stat::uid("chown/one/file", DO_NOT_FOLLOW_SYMLINK));
+ EXPECT_SOME_EQ(0u,
+ os::stat::uid("chown/one",
+ FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
+ EXPECT_SOME_EQ(9u,
+ os::stat::uid("chown/one/file",
+ FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
}