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:38:52 UTC
[06/50] mesos git commit: Windows: Updated `isdir()` and `isfile()`
to support long paths.
Windows: Updated `isdir()` and `isfile()` to support long paths.
Now uses Windows file attributes instead of `::_stat()`.
Review: https://reviews.apache.org/r/60300/
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/6f027334
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/6f027334
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/6f027334
Branch: refs/heads/master
Commit: 6f027334f8e0539c90385bfe3ccd4884fd4a811b
Parents: 4f6719f
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Wed Jul 5 12:12:35 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:32 2017 -0700
----------------------------------------------------------------------
.../stout/include/stout/os/windows/stat.hpp | 24 +++++++++++++-------
1 file changed, 16 insertions(+), 8 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/6f027334/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 b2ff436..b22ae80 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/internal/windows/attributes.hpp>
+#include <stout/internal/windows/longpath.hpp>
#include <stout/internal/windows/reparsepoint.hpp>
#include <stout/internal/windows/symlink.hpp>
@@ -38,19 +40,20 @@ inline bool isdir(
const std::string& path,
const FollowSymlink follow = FOLLOW_SYMLINK)
{
- struct _stat s;
-
// A symlink itself is not a directory.
// If it's not a link, we ignore `follow`.
if (follow == DO_NOT_FOLLOW_SYMLINK && islink(path)) {
return false;
}
- if (::_stat(path.c_str(), &s) < 0) {
+ const Try<DWORD> attributes = ::internal::windows::get_file_attributes(
+ ::internal::windows::longpath(path));
+
+ if (attributes.isError()) {
return false;
}
- return S_ISDIR(s.st_mode);
+ return attributes.get() & FILE_ATTRIBUTE_DIRECTORY;
}
@@ -58,8 +61,6 @@ inline bool isfile(
const std::string& path,
const FollowSymlink follow = FOLLOW_SYMLINK)
{
- struct _stat s;
-
// 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.
@@ -68,11 +69,18 @@ inline bool isfile(
return false;
}
- if (::_stat(path.c_str(), &s) < 0) {
+ const Try<DWORD> attributes = ::internal::windows::get_file_attributes(
+ ::internal::windows::longpath(path));
+
+ if (attributes.isError()) {
return false;
}
- return S_ISREG(s.st_mode);
+ // NOTE: Windows files attributes do not define a flag for "regular"
+ // files. Instead, this call will only return successfully iff the
+ // given file or directory exists. Checking against the directory
+ // flag determines if the path is a file or directory.
+ return !(attributes.get() & FILE_ATTRIBUTE_DIRECTORY);
}