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:54 UTC

[08/50] mesos git commit: Windows: Updated `os::realpath()` to support long paths.

Windows: Updated `os::realpath()` to support long paths.

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


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

Branch: refs/heads/master
Commit: dd87bd416e9529380dc3546d780c6bd8477dc846
Parents: 4c939b6
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Tue Jun 27 17:28:33 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:32 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/Makefile.am              |  2 +
 .../stout/include/stout/os/posix/realpath.hpp   | 40 ++++++++++++++
 3rdparty/stout/include/stout/os/realpath.hpp    | 26 ++-------
 .../stout/include/stout/os/windows/realpath.hpp | 58 ++++++++++++++++++++
 3rdparty/stout/include/stout/windows.hpp        |  7 ---
 5 files changed, 106 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/dd87bd41/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/Makefile.am b/3rdparty/stout/include/Makefile.am
index d5d209b..9087ff1 100644
--- a/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/stout/include/Makefile.am
@@ -132,6 +132,7 @@ nobase_include_HEADERS =			\
   stout/os/posix/pagesize.hpp			\
   stout/os/posix/pipe.hpp			\
   stout/os/posix/read.hpp			\
+  stout/os/posix/realpath.hpp			\
   stout/os/posix/rename.hpp			\
   stout/os/posix/rm.hpp				\
   stout/os/posix/rmdir.hpp			\
@@ -164,6 +165,7 @@ nobase_include_HEADERS =			\
   stout/os/windows/pagesize.hpp			\
   stout/os/windows/pipe.hpp			\
   stout/os/windows/read.hpp			\
+  stout/os/windows/realpath.hpp			\
   stout/os/windows/rename.hpp			\
   stout/os/windows/rm.hpp			\
   stout/os/windows/rmdir.hpp			\

http://git-wip-us.apache.org/repos/asf/mesos/blob/dd87bd41/3rdparty/stout/include/stout/os/posix/realpath.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/realpath.hpp b/3rdparty/stout/include/stout/os/posix/realpath.hpp
new file mode 100644
index 0000000..31352ce
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/posix/realpath.hpp
@@ -0,0 +1,40 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_POSIX_REALPATH_HPP__
+#define __STOUT_OS_POSIX_REALPATH_HPP__
+
+#include <string>
+
+#include <stout/error.hpp>
+#include <stout/result.hpp>
+
+
+namespace os {
+
+inline Result<std::string> realpath(const std::string& path)
+{
+  char temp[PATH_MAX];
+  if (::realpath(path.c_str(), temp) == nullptr) {
+    if (errno == ENOENT || errno == ENOTDIR) {
+      return None();
+    }
+
+    return ErrnoError();
+  }
+
+  return std::string(temp);
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_POSIX_REALPATH_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/dd87bd41/3rdparty/stout/include/stout/os/realpath.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/realpath.hpp b/3rdparty/stout/include/stout/os/realpath.hpp
index 22a8cb7..c2099c0 100644
--- a/3rdparty/stout/include/stout/os/realpath.hpp
+++ b/3rdparty/stout/include/stout/os/realpath.hpp
@@ -14,27 +14,13 @@
 #define __STOUT_OS_REALPATH_HPP__
 
 
-#include <stout/result.hpp>
-
+// For readability, we minimize the number of #ifdef blocks in the code by
+// splitting platform specific system calls into separate directories.
 #ifdef __WINDOWS__
-#include <stout/windows.hpp>
-#endif
-
-
-namespace os {
-
-inline Result<std::string> realpath(const std::string& path)
-{
-  char temp[PATH_MAX];
-  if (::realpath(path.c_str(), temp) == nullptr) {
-    if (errno == ENOENT || errno == ENOTDIR) {
-      return None();
-    }
-    return ErrnoError();
-  }
-  return std::string(temp);
-}
+#include <stout/os/windows/realpath.hpp>
+#else
+#include <stout/os/posix/realpath.hpp>
+#endif // __WINDOWS__
 
-} // namespace os {
 
 #endif // __STOUT_OS_REALPATH_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/dd87bd41/3rdparty/stout/include/stout/os/windows/realpath.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/realpath.hpp b/3rdparty/stout/include/stout/os/windows/realpath.hpp
new file mode 100644
index 0000000..81a33bd
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/windows/realpath.hpp
@@ -0,0 +1,58 @@
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+//  http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+#ifndef __STOUT_OS_WINDOWS_REALPATH_HPP__
+#define __STOUT_OS_WINDOWS_REALPATH_HPP__
+
+
+#include <stout/error.hpp>
+#include <stout/result.hpp>
+#include <stout/stringify.hpp>
+#include <stout/strings.hpp>
+
+#include <stout/internal/windows/longpath.hpp>
+
+
+namespace os {
+
+inline Result<std::string> realpath(const std::string& path)
+{
+  // TODO(andschwa): Test the existence of `path` to be consistent with POSIX
+  // `::realpath`.
+
+  std::wstring longpath = ::internal::windows::longpath(path);
+
+  // First query for the buffer size required.
+  DWORD length = GetFullPathNameW(longpath.data(), 0, nullptr, nullptr);
+  if (length == 0) {
+    return WindowsError("Failed to retrieve realpath buffer size");
+  }
+
+  std::vector<wchar_t> buffer;
+  buffer.reserve(static_cast<size_t>(length));
+
+  DWORD result =
+    GetFullPathNameW(longpath.data(), length, buffer.data(), nullptr);
+
+  if (result == 0) {
+    return WindowsError("Failed to determine realpath");
+  }
+
+  return strings::remove(
+      stringify(std::wstring(buffer.data())),
+      os::LONGPATH_PREFIX,
+      strings::Mode::PREFIX);
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_WINDOWS_REALPATH_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/dd87bd41/3rdparty/stout/include/stout/windows.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows.hpp b/3rdparty/stout/include/stout/windows.hpp
index 2fcf27f..0cd22d5 100644
--- a/3rdparty/stout/include/stout/windows.hpp
+++ b/3rdparty/stout/include/stout/windows.hpp
@@ -393,13 +393,6 @@ decltype(_mktemp_s(path, strlen(path) + 1))
 }
 
 
-inline auto realpath(const char* path, char* resolved) ->
-decltype(_fullpath(resolved, path, PATH_MAX))
-{
-  return _fullpath(resolved, path, PATH_MAX);
-}
-
-
 inline auto access(const char* fileName, int accessMode) ->
 decltype(_access(fileName, accessMode))
 {