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 2017/11/30 03:28:31 UTC
[12/13] mesos git commit: Windows: Cleaned up `os::exists`.
Windows: Cleaned up `os::exists`.
More const, RAII, and comments.
Review: https://reviews.apache.org/r/64182
Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/adad9948
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/adad9948
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/adad9948
Branch: refs/heads/master
Commit: adad99482cb565fd7cd10e710ed7355b7569ef23
Parents: 1f37e11
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Wed Nov 29 14:18:25 2017 -0800
Committer: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Committed: Wed Nov 29 19:24:11 2017 -0800
----------------------------------------------------------------------
.../stout/include/stout/os/windows/exists.hpp | 18 ++++++++----------
1 file changed, 8 insertions(+), 10 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/mesos/blob/adad9948/3rdparty/stout/include/stout/os/windows/exists.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/exists.hpp b/3rdparty/stout/include/stout/os/windows/exists.hpp
index 7c8c85c..50bb92a 100644
--- a/3rdparty/stout/include/stout/os/windows/exists.hpp
+++ b/3rdparty/stout/include/stout/os/windows/exists.hpp
@@ -37,12 +37,15 @@ inline bool exists(const std::string& path)
::internal::windows::longpath(path).data());
if (attributes == INVALID_FILE_ATTRIBUTES) {
- DWORD error = GetLastError();
+ const DWORD error = ::GetLastError();
if (error == ERROR_FILE_NOT_FOUND || error == ERROR_PATH_NOT_FOUND) {
return false;
}
}
+ // Note that `ERROR_ACCESS_DENIED` etc. indicates the path does exist, but
+ // `INVALID_FILE_ATTRIBUTES` would still be returned.
+
return true;
}
@@ -52,16 +55,11 @@ inline bool exists(const std::string& path)
// os::process(pid) to get details of a process.
inline bool exists(pid_t pid)
{
- HANDLE handle = OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid);
-
- bool has_handle = false;
-
- if (handle != nullptr) {
- has_handle = true;
- CloseHandle(handle);
- }
+ SharedHandle handle(
+ ::OpenProcess(PROCESS_QUERY_LIMITED_INFORMATION, FALSE, pid),
+ ::CloseHandle);
- return has_handle;
+ return handle.get_handle() != nullptr;
}