Repository: mesos Updated Branches: refs/heads/master 00d4fa0b1 -> 5f159cdcb
Added the `FollowSymlink` argument for `os::stat` on Windows. Review: https://reviews.apache.org/r/56028/ Project: http://git-wip-us.apache.org/repos/asf/mesos/repo Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/5f159cdc Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/5f159cdc Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/5f159cdc Branch: refs/heads/master Commit: 5f159cdcbe07ce453cc9b0ecc8834a8551a19f10 Parents: 39b34d6 Author: James Peach <[email protected]> Authored: Wed Mar 22 17:53:34 2017 -0700 Committer: Michael Park <[email protected]> Committed: Thu Mar 23 09:42:18 2017 -0700 ---------------------------------------------------------------------- .../stout/include/stout/os/windows/stat.hpp | 73 ++++++++++++++------ 1 file changed, 51 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/mesos/blob/5f159cdc/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 e7f471b..38b9fe8 100644 --- a/3rdparty/stout/include/stout/os/windows/stat.hpp +++ b/3rdparty/stout/include/stout/os/windows/stat.hpp @@ -31,10 +31,16 @@ namespace os { namespace stat { -inline bool isdir(const std::string& path) +inline bool isdir( + const std::string& path, + const FollowSymlink follow = FOLLOW_SYMLINK) { struct _stat s; + if (follow == DO_NOT_FOLLOW_SYMLINK) { + return Error("Non-following stat not supported for '" + path + "'"); + } + if (::_stat(path.c_str(), &s) < 0) { return false; } @@ -43,10 +49,16 @@ inline bool isdir(const std::string& path) } -inline bool isfile(const std::string& path) +inline bool isfile( + const std::string& path, + const FollowSymlink follow = FOLLOW_SYMLINK) { struct _stat s; + if (follow == DO_NOT_FOLLOW_SYMLINK) { + return Error("Non-following stat not supported for '" + path + "'"); + } + if (::_stat(path.c_str(), &s) < 0) { return false; } @@ -64,15 +76,6 @@ inline bool islink(const std::string& path) } -// Describes the different semantics supported for the implementation -// of `size` defined below. -enum FollowSymlink -{ - DO_NOT_FOLLOW_SYMLINK, - FOLLOW_SYMLINK -}; - - // Returns the size in Bytes of a given file system entry. When // applied to a symbolic link with `follow` set to // `DO_NOT_FOLLOW_SYMLINK`, this will return the length of the entry @@ -109,15 +112,19 @@ inline Try<Bytes> size( } -inline Try<long> mtime(const std::string& path) +inline Try<long> mtime( + const std::string& path, + const FollowSymlink follow = FOLLOW_SYMLINK) { - Try<::internal::windows::SymbolicLink> symlink = - ::internal::windows::query_symbolic_link_data(path); - - if (symlink.isSome()) { - return Error( - "Requested mtime for '" + path + - "', but symbolic links don't have an mtime on Windows"); + if (follow == DO_NOT_FOLLOW_SYMLINK) { + Try<::internal::windows::SymbolicLink> symlink = + ::internal::windows::query_symbolic_link_data(path); + + if (symlink.isSome()) { + return Error( + "Requested mtime for '" + path + + "', but symbolic links don't have an mtime on Windows"); + } } struct _stat s; @@ -137,10 +144,16 @@ inline Try<long> mtime(const std::string& path) } -inline Try<mode_t> mode(const std::string& path) +inline Try<mode_t> mode( + const std::string& path, + const FollowSymlink follow = FOLLOW_SYMLINK) { struct _stat s; + if (follow == DO_NOT_FOLLOW_SYMLINK) { + return Error("Non-following stat not supported for '" + path + "'"); + } + if (::_stat(path.c_str(), &s) < 0) { return ErrnoError("Error invoking stat for '" + path + "'"); } @@ -149,10 +162,18 @@ inline Try<mode_t> mode(const std::string& path) } -inline Try<dev_t> dev(const std::string& path) +inline Try<dev_t> dev( + const std::string& path, + const FollowSymlink follow = FOLLOW_SYMLINK) { struct _stat s; + if (follow == DO_NOT_FOLLOW_SYMLINK) { + return WindowsError( + ERROR_NOT_SUPPORTED, + "Error invoking stat for '" + path + "'"); + } + if (::_stat(path.c_str(), &s) < 0) { return ErrnoError("Error invoking stat for '" + path + "'"); } @@ -161,10 +182,18 @@ inline Try<dev_t> dev(const std::string& path) } -inline Try<ino_t> inode(const std::string& path) +inline Try<ino_t> inode( + const std::string& path, + const FollowSymlink follow = FOLLOW_SYMLINK) { struct _stat s; + if (follow == DO_NOT_FOLLOW_SYMLINK) { + return WindowsError( + ERROR_NOT_SUPPORTED, + "Error invoking stat for '" + path + "'"); + } + if (::_stat(path.c_str(), &s) < 0) { return ErrnoError("Error invoking stat for '" + path + "'"); }
