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

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

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

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


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

Branch: refs/heads/master
Commit: 0cbc03342b48f3807ef5e9f70dfc88c0fc14a541
Parents: ed653a0
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Wed Jul 5 15:22:02 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:33 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/Makefile.am              |  2 +
 3rdparty/stout/include/stout/os/getcwd.hpp      | 35 ++------------
 .../stout/include/stout/os/posix/getcwd.hpp     | 49 +++++++++++++++++++
 .../stout/include/stout/os/windows/getcwd.hpp   | 50 ++++++++++++++++++++
 3rdparty/stout/include/stout/windows.hpp        |  7 ---
 5 files changed, 106 insertions(+), 37 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0cbc0334/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/Makefile.am b/3rdparty/stout/include/Makefile.am
index f05e968..5c0f9f8 100644
--- a/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/stout/include/Makefile.am
@@ -125,6 +125,7 @@ nobase_include_HEADERS =			\
   stout/os/posix/fork.hpp			\
   stout/os/posix/fsync.hpp			\
   stout/os/posix/ftruncate.hpp			\
+  stout/os/posix/getcwd.hpp			\
   stout/os/posix/getenv.hpp			\
   stout/os/posix/kill.hpp			\
   stout/os/posix/killtree.hpp			\
@@ -159,6 +160,7 @@ nobase_include_HEADERS =			\
   stout/os/windows/fork.hpp			\
   stout/os/windows/fsync.hpp			\
   stout/os/windows/ftruncate.hpp		\
+  stout/os/windows/getcwd.hpp			\
   stout/os/windows/getenv.hpp			\
   stout/os/windows/kill.hpp			\
   stout/os/windows/killtree.hpp			\

http://git-wip-us.apache.org/repos/asf/mesos/blob/0cbc0334/3rdparty/stout/include/stout/os/getcwd.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/getcwd.hpp b/3rdparty/stout/include/stout/os/getcwd.hpp
index 63ecc98..2d439e9 100644
--- a/3rdparty/stout/include/stout/os/getcwd.hpp
+++ b/3rdparty/stout/include/stout/os/getcwd.hpp
@@ -13,39 +13,14 @@
 #ifndef __STOUT_OS_GETCWD_HPP__
 #define __STOUT_OS_GETCWD_HPP__
 
-#include <stout/try.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> // To be certain we're using the right `getcwd`.
+#include <stout/os/windows/getcwd.hpp>
+#else
+#include <stout/os/posix/getcwd.hpp>
 #endif // __WINDOWS__
 
 
-namespace os {
-
-inline std::string getcwd()
-{
-  size_t size = 100;
-
-  while (true) {
-    char* temp = new char[size];
-    if (::getcwd(temp, size) == temp) {
-      std::string result(temp);
-      delete[] temp;
-      return result;
-    } else {
-      if (errno != ERANGE) {
-        delete[] temp;
-        return std::string();
-      }
-      size *= 2;
-      delete[] temp;
-    }
-  }
-
-  return std::string();
-}
-
-} // namespace os {
-
-
 #endif // __STOUT_OS_GETCWD_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/0cbc0334/3rdparty/stout/include/stout/os/posix/getcwd.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/getcwd.hpp b/3rdparty/stout/include/stout/os/posix/getcwd.hpp
new file mode 100644
index 0000000..9b438c8
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/posix/getcwd.hpp
@@ -0,0 +1,49 @@
+// 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_GETCWD_HPP__
+#define __STOUT_OS_POSIX_GETCWD_HPP__
+
+#include <string>
+
+#include <stout/try.hpp>
+
+
+namespace os {
+
+inline std::string getcwd()
+{
+  size_t size = 100;
+
+  while (true) {
+    char* temp = new char[size];
+    if (::getcwd(temp, size) == temp) {
+      std::string result(temp);
+      delete[] temp;
+      return result;
+    } else {
+      if (errno != ERANGE) {
+        delete[] temp;
+        return std::string();
+      }
+      size *= 2;
+      delete[] temp;
+    }
+  }
+
+  return std::string();
+}
+
+} // namespace os {
+
+
+#endif // __STOUT_OS_POSIX_GETCWD_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/0cbc0334/3rdparty/stout/include/stout/os/windows/getcwd.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/getcwd.hpp b/3rdparty/stout/include/stout/os/windows/getcwd.hpp
new file mode 100644
index 0000000..f316d61
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/windows/getcwd.hpp
@@ -0,0 +1,50 @@
+// 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_GETCWD_HPP__
+#define __STOUT_OS_WINDOWS_GETCWD_HPP__
+
+#include <stout/check.hpp>
+#include <stout/error.hpp>
+#include <stout/stringify.hpp>
+#include <stout/try.hpp>
+#include <stout/windows.hpp>
+
+#include <stout/internal/windows/longpath.hpp>
+
+
+namespace os {
+
+// TODO(josephw): Consider changing the return type to a `Try<std::string>`
+// so that we do not CHECK-fail upon error.
+inline std::string getcwd()
+{
+  // First query for the buffer size required.
+  DWORD length = ::GetCurrentDirectoryW(0, nullptr);
+  CHECK(length != 0) << "Failed to retrieve current directory buffer size";
+
+  std::vector<wchar_t> buffer;
+  buffer.reserve(static_cast<size_t>(length));
+
+  DWORD result = ::GetCurrentDirectoryW(length, buffer.data());
+  CHECK(result != 0) << "Failed to determine current directory";
+
+  return strings::remove(
+      stringify(std::wstring(buffer.data())),
+      os::LONGPATH_PREFIX,
+      strings::Mode::PREFIX);
+}
+
+} // namespace os {
+
+
+#endif // __STOUT_OS_WINDOWS_GETCWD_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/0cbc0334/3rdparty/stout/include/stout/windows.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows.hpp b/3rdparty/stout/include/stout/windows.hpp
index 6aa0d53..a2b13c3 100644
--- a/3rdparty/stout/include/stout/windows.hpp
+++ b/3rdparty/stout/include/stout/windows.hpp
@@ -352,13 +352,6 @@ decltype(_chdir(path))
 }
 
 
-inline char* getcwd(char* path, size_t maxlen)
-{
-  CHECK_LE(maxlen, INT_MAX);
-  return _getcwd(path, static_cast<int>(maxlen));
-}
-
-
 inline auto mktemp(char* path) ->
 decltype(_mktemp(path))
 {