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

[01/50] mesos git commit: Windows: Added `os::LONGPATH_PREFIX` constant.

Repository: mesos
Updated Branches:
  refs/heads/master edd8453c7 -> edba29265


Windows: Added `os::LONGPATH_PREFIX` constant.

The string `\\?\` is the prefix used by Windows to indicate the path may
be longer than `MAX_PATH`.

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


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

Branch: refs/heads/master
Commit: 4892a8f1e68e86498f87139e1d86f9d349030b88
Parents: a4bfabf
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Tue Jun 27 13:55:21 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 15:55:09 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/os/constants.hpp | 9 +++++++++
 1 file changed, 9 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/4892a8f1/3rdparty/stout/include/stout/os/constants.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/constants.hpp b/3rdparty/stout/include/stout/os/constants.hpp
index f20041c..f81dbb3 100644
--- a/3rdparty/stout/include/stout/os/constants.hpp
+++ b/3rdparty/stout/include/stout/os/constants.hpp
@@ -32,6 +32,15 @@ constexpr char DEV_NULL[] = "/dev/null";
 constexpr char DEV_NULL[] = "NUL";
 #endif // __WINDOWS__
 
+#ifdef __WINDOWS__
+// This prefix is prepended to absolute paths on Windows to indicate the path
+// may be greater than 255 characters.
+//
+// NOTE: We do not use a R"raw string" here because syntax highlighters do not
+// handle mismatched backslashes well.
+constexpr char LONGPATH_PREFIX[] = "\\\\?\\";
+#endif // __WINDOWS__
+
 } // namespace os {
 
 #endif // __STOUT_OS_CONSTANTS_HPP__


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

Posted by jo...@apache.org.
Windows: Updated `os::mkdir()` to support long paths.

This commit fixes some long path problems on Windows by replacing the
use of the deprecated POSIX function `mkdir` with the explicit Unicode
function `CreateDirectoryW` on Windows. Paths are resolved to be be
absolute and then prepended with `\\?\`, which forces long path support
without requiring a registry or group policy setting.

Because `CreateDirectory` will fail with "permission denied" on paths
such as `C:\`, `os::exists` is used to check if the path exists before
attempting to create it.

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


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

Branch: refs/heads/master
Commit: ed653a0fafb2233644cdf753abddfc743cba61e7
Parents: 6f02733
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Wed Jul 5 13:15:38 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:32 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/Makefile.am              |  2 +
 3rdparty/stout/include/stout/os/mkdir.hpp       | 53 ++-------------
 3rdparty/stout/include/stout/os/posix/mkdir.hpp | 63 +++++++++++++++++
 .../stout/include/stout/os/windows/mkdir.hpp    | 71 ++++++++++++++++++++
 3rdparty/stout/include/stout/windows.hpp        |  7 --
 5 files changed, 141 insertions(+), 55 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ed653a0f/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/Makefile.am b/3rdparty/stout/include/Makefile.am
index 9087ff1..f05e968 100644
--- a/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/stout/include/Makefile.am
@@ -128,6 +128,7 @@ nobase_include_HEADERS =			\
   stout/os/posix/getenv.hpp			\
   stout/os/posix/kill.hpp			\
   stout/os/posix/killtree.hpp			\
+  stout/os/posix/mkdir.hpp			\
   stout/os/posix/mkdtemp.hpp			\
   stout/os/posix/pagesize.hpp			\
   stout/os/posix/pipe.hpp			\
@@ -161,6 +162,7 @@ nobase_include_HEADERS =			\
   stout/os/windows/getenv.hpp			\
   stout/os/windows/kill.hpp			\
   stout/os/windows/killtree.hpp			\
+  stout/os/windows/mkdir.hpp			\
   stout/os/windows/mkdtemp.hpp			\
   stout/os/windows/pagesize.hpp			\
   stout/os/windows/pipe.hpp			\

http://git-wip-us.apache.org/repos/asf/mesos/blob/ed653a0f/3rdparty/stout/include/stout/os/mkdir.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/mkdir.hpp b/3rdparty/stout/include/stout/os/mkdir.hpp
index b384391..b877d7d 100644
--- a/3rdparty/stout/include/stout/os/mkdir.hpp
+++ b/3rdparty/stout/include/stout/os/mkdir.hpp
@@ -13,57 +13,14 @@
 #ifndef __STOUT_OS_MKDIR_HPP__
 #define __STOUT_OS_MKDIR_HPP__
 
-#ifndef __WINDOWS__
-#include <sys/stat.h>
-#endif // __WINDOWS__
-
-#include <string>
-#include <vector>
-
-#include <stout/error.hpp>
-#include <stout/nothing.hpp>
-#include <stout/strings.hpp>
-#include <stout/try.hpp>
-
-#include <stout/os/constants.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 `mkdir`.
+#include <stout/os/windows/mkdir.hpp>
+#else
+#include <stout/os/posix/mkdir.hpp>
 #endif // __WINDOWS__
 
 
-namespace os {
-
-inline Try<Nothing> mkdir(const std::string& directory, bool recursive = true)
-{
-  if (!recursive) {
-    if (::mkdir(directory.c_str(), 0755) < 0) {
-      return ErrnoError();
-    }
-  } else {
-    std::vector<std::string> tokens =
-      strings::tokenize(directory, stringify(os::PATH_SEPARATOR));
-
-    std::string path;
-
-    // We got an absolute path, so keep the leading slash.
-    if (directory.find_first_of(stringify(os::PATH_SEPARATOR)) == 0) {
-      path = os::PATH_SEPARATOR;
-    }
-
-    foreach (const std::string& token, tokens) {
-      path += token;
-      if (::mkdir(path.c_str(), 0755) < 0 && errno != EEXIST) {
-        return ErrnoError();
-      }
-
-      path += os::PATH_SEPARATOR;
-    }
-  }
-
-  return Nothing();
-}
-
-} // namespace os {
-
 #endif // __STOUT_OS_MKDIR_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/ed653a0f/3rdparty/stout/include/stout/os/posix/mkdir.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/mkdir.hpp b/3rdparty/stout/include/stout/os/posix/mkdir.hpp
new file mode 100644
index 0000000..418db9a
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/posix/mkdir.hpp
@@ -0,0 +1,63 @@
+// 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_MKDIR_HPP__
+#define __STOUT_OS_POSIX_MKDIR_HPP__
+
+#include <sys/stat.h>
+
+#include <string>
+#include <vector>
+
+#include <stout/error.hpp>
+#include <stout/nothing.hpp>
+#include <stout/strings.hpp>
+#include <stout/try.hpp>
+
+#include <stout/os/constants.hpp>
+
+
+namespace os {
+
+inline Try<Nothing> mkdir(const std::string& directory, bool recursive = true)
+{
+  if (!recursive) {
+    if (::mkdir(directory.c_str(), 0755) < 0) {
+      return ErrnoError();
+    }
+  } else {
+    std::vector<std::string> tokens =
+      strings::tokenize(directory, stringify(os::PATH_SEPARATOR));
+
+    std::string path;
+
+    // We got an absolute path, so keep the leading slash.
+    if (directory.find_first_of(stringify(os::PATH_SEPARATOR)) == 0) {
+      path = os::PATH_SEPARATOR;
+    }
+
+    foreach (const std::string& token, tokens) {
+      path += token;
+      if (::mkdir(path.c_str(), 0755) < 0 && errno != EEXIST) {
+        return ErrnoError();
+      }
+
+      path += os::PATH_SEPARATOR;
+    }
+  }
+
+  return Nothing();
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_POSIX_MKDIR_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/ed653a0f/3rdparty/stout/include/stout/os/windows/mkdir.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/mkdir.hpp b/3rdparty/stout/include/stout/os/windows/mkdir.hpp
new file mode 100644
index 0000000..8d8d80b
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/windows/mkdir.hpp
@@ -0,0 +1,71 @@
+// 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_MKDIR_HPP__
+#define __STOUT_OS_WINDOWS_MKDIR_HPP__
+
+#include <string>
+#include <vector>
+
+#include <stout/error.hpp>
+#include <stout/nothing.hpp>
+#include <stout/strings.hpp>
+#include <stout/try.hpp>
+#include <stout/windows.hpp>
+
+#include <stout/os/exists.hpp>
+#include <stout/os/constants.hpp>
+
+#include <stout/internal/windows/longpath.hpp>
+
+
+namespace os {
+
+inline Try<Nothing> mkdir(const std::string& directory, bool recursive = true)
+{
+  if (!recursive) {
+    // NOTE: We check for existence because parts of certain directories
+    // like `C:\` will return an error if passed to `CreateDirectory`,
+    // even though the drive may already exist.
+    if (os::exists(directory)) {
+      return Nothing();
+    }
+
+    std::wstring longpath = ::internal::windows::longpath(directory);
+    if (::CreateDirectoryW(longpath.data(), nullptr) == 0) {
+      return WindowsError("Failed to create directory: " + directory);
+    }
+  } else {
+    // Remove the long path prefix, if it already exists, otherwise the
+    // tokenizer includes the long path prefix (`\\?\`) as the first part
+    // of the path.
+    std::vector<std::string> tokens = strings::tokenize(
+        strings::remove(directory, os::LONGPATH_PREFIX, strings::Mode::PREFIX),
+        stringify(os::PATH_SEPARATOR));
+
+    std::string path;
+
+    foreach (const std::string& token, tokens) {
+      path += token + os::PATH_SEPARATOR;
+      Try<Nothing> result = mkdir(path, false);
+      if (result.isError()) {
+        return result;
+      }
+    }
+  }
+
+  return Nothing();
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_WINDOWS_MKDIR_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/ed653a0f/3rdparty/stout/include/stout/windows.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows.hpp b/3rdparty/stout/include/stout/windows.hpp
index 0cd22d5..6aa0d53 100644
--- a/3rdparty/stout/include/stout/windows.hpp
+++ b/3rdparty/stout/include/stout/windows.hpp
@@ -359,13 +359,6 @@ inline char* getcwd(char* path, size_t maxlen)
 }
 
 
-inline auto mkdir(const char* path, mode_t mode) ->
-decltype(_mkdir(path))
-{
-  return _mkdir(path);
-}
-
-
 inline auto mktemp(char* path) ->
 decltype(_mktemp(path))
 {


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

Posted by jo...@apache.org.
Windows: Updated `os::rm()` to support long paths.

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


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

Branch: refs/heads/master
Commit: f2db53f28d36a368e200f19436ac346465553f2c
Parents: 06162f6
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Fri Jul 7 14:45:48 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:34 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/os/windows/rm.hpp | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/f2db53f2/3rdparty/stout/include/stout/os/windows/rm.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/rm.hpp b/3rdparty/stout/include/stout/os/windows/rm.hpp
index 6460b52..73ebcec 100644
--- a/3rdparty/stout/include/stout/os/windows/rm.hpp
+++ b/3rdparty/stout/include/stout/os/windows/rm.hpp
@@ -23,6 +23,8 @@
 
 #include <stout/os/stat.hpp>
 
+#include <stout/internal/windows/longpath.hpp>
+
 
 namespace os {
 
@@ -43,8 +45,10 @@ inline Try<Nothing> rm(const std::string& path)
   // [2] https://msdn.microsoft.com/en-us/library/windows/desktop/aa365682(v=vs.85).aspx#deletefile_and_deletefiletransacted
   // [3] http://pubs.opengroup.org/onlinepubs/009695399/functions/remove.html
   // [4] http://pubs.opengroup.org/onlinepubs/009695399/functions/rmdir.html
-  const BOOL result = os::stat::isdir(path) ? ::RemoveDirectory(path.c_str())
-                                            : ::DeleteFile(path.c_str());
+  const std::wstring longpath = ::internal::windows::longpath(path);
+  const BOOL result = os::stat::isdir(path)
+      ? ::RemoveDirectoryW(longpath.data())
+      : ::DeleteFileW(longpath.data());
 
   if (!result) {
     return WindowsError("`os::rm` could not remove '" + path + "'");


[03/50] mesos git commit: Windows: Added a `wstring wide_stringify(string)` helper.

Posted by jo...@apache.org.
Windows: Added a `wstring wide_stringify(string)` helper.

When dealing with Windows APIs, often `string` -> `wstring` conversions
are required. This addition makes the process cleaner.

Also added explicit errors messages, which are written to the buffer
instead of throwing an exception if an error occurs.

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


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

Branch: refs/heads/master
Commit: 0f6c21201bf4180fa049bc53f49cc67bdd66533d
Parents: edd8453
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Tue Jun 27 13:34:39 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 15:55:09 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/stringify.hpp | 18 +++++++++++++++++-
 1 file changed, 17 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0f6c2120/3rdparty/stout/include/stout/stringify.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/stringify.hpp b/3rdparty/stout/include/stout/stringify.hpp
index 44da506..49bf684 100644
--- a/3rdparty/stout/include/stout/stringify.hpp
+++ b/3rdparty/stout/include/stout/stringify.hpp
@@ -57,9 +57,25 @@ inline std::string stringify(const std::string& str)
 inline std::string stringify(const std::wstring& str)
 {
   // Convert UTF-16 `wstring` to UTF-8 `string`.
-  std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter;
+  static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>
+    converter(
+        "UTF-16 to UTF-8 conversion failed",
+        L"UTF-16 to UTF-8 conversion failed");
+
   return converter.to_bytes(str);
 }
+
+
+inline std::wstring wide_stringify(const std::string& str)
+{
+  // Convert UTF-8 `string` to UTF-16 `wstring`.
+  static std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t>
+    converter(
+        "UTF-8 to UTF-16 conversion failed",
+        L"UTF-8 to UTF-16 conversion failed");
+
+  return converter.from_bytes(str);
+}
 #endif // __WINDOWS__
 
 


[27/50] mesos git commit: Windows: Added `create_process()` wrapper to `shell.hpp`.

Posted by jo...@apache.org.
Windows: Added `create_process()` wrapper to `shell.hpp`.

This removes the use of unsupported CRT functions from the `os::`
namespace, and reimplements them using `CreateProcess()`.

The CRT APIs behave unpredictably in the context of long paths, and are
not necessary. Furthermore, it is not possible to use the Visual Studio
Child Process Debugger for processes spawned by any API other than
`CreateProcess()`.

Some unused functions were explicitly deleted to avoid future bugs.

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


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

Branch: refs/heads/master
Commit: c200bece74602733f0b7a467611870f90d632a82
Parents: 92ab328
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 13:31:42 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:36 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/cmake/StoutConfigure.cmake       |   1 +
 .../stout/include/stout/os/windows/shell.hpp    | 410 +++++++++++++------
 3rdparty/stout/tests/os/process_tests.cpp       |  32 +-
 3rdparty/stout/tests/os_tests.cpp               |   7 +-
 4 files changed, 302 insertions(+), 148 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/c200bece/3rdparty/stout/cmake/StoutConfigure.cmake
----------------------------------------------------------------------
diff --git a/3rdparty/stout/cmake/StoutConfigure.cmake b/3rdparty/stout/cmake/StoutConfigure.cmake
index 6b1d27f..69474a8 100644
--- a/3rdparty/stout/cmake/StoutConfigure.cmake
+++ b/3rdparty/stout/cmake/StoutConfigure.cmake
@@ -134,6 +134,7 @@ if (WIN32)
     ws2_32
     Mswsock
     Secur32
+    Userenv
     )
 else ()
   set(STOUT_LIBS

http://git-wip-us.apache.org/repos/asf/mesos/blob/c200bece/3rdparty/stout/include/stout/os/windows/shell.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/shell.hpp b/3rdparty/stout/include/stout/os/windows/shell.hpp
index b93f337..0d8d45b 100644
--- a/3rdparty/stout/include/stout/os/windows/shell.hpp
+++ b/3rdparty/stout/include/stout/os/windows/shell.hpp
@@ -16,156 +16,131 @@
 #include <process.h>
 #include <stdarg.h> // For va_list, va_start, etc.
 
+#include <algorithm>
+#include <map>
 #include <ostream>
 #include <string>
+#include <tuple>
+#include <vector>
 
+#include <stout/error.hpp>
+#include <stout/foreach.hpp>
+#include <stout/option.hpp>
+#include <stout/os.hpp>
+#include <stout/os/int_fd.hpp>
 #include <stout/try.hpp>
+#include <stout/unimplemented.hpp>
 
-#include <stout/os/raw/argv.hpp>
+#include <stout/windows.hpp>
 
-namespace os {
-
-namespace Shell {
-
-  // Canonical constants used as platform-dependent args to `exec` calls.
-  // `name` is the command name, `arg0` is the first argument received
-  // by the callee, usually the command name and `arg1` is the second
-  // command argument received by the callee.
-  constexpr const char* name = "cmd.exe";
-  constexpr const char* arg0 = "cmd";
-  constexpr const char* arg1 = "/c";
+namespace internal {
 
-} // namespace Shell {
+namespace windows {
 
-/**
- * Runs a shell command with optional arguments.
- *
- * This assumes that a successful execution will result in the exit code
- * for the command to be `EXIT_SUCCESS`; in this case, the contents
- * of the `Try` will be the contents of `stdout`.
- *
- * If the exit code is non-zero or the process was signaled, we will
- * return an appropriate error message; but *not* `stderr`.
- *
- * If the caller needs to examine the contents of `stderr` it should
- * be redirected to `stdout` (using, e.g., "2>&1 || true" in the command
- * string).  The `|| true` is required to obtain a success exit
- * code in case of errors, and still obtain `stderr`, as piped to
- * `stdout`.
- *
- * @param fmt the formatting string that contains the command to execute
- *   in the underlying shell.
- * @param t optional arguments for `fmt`.
- *
- * @return the output from running the specified command with the shell; or
- *   an error message if the command's exit code is non-zero.
- */
-template <typename... T>
-Try<std::string> shell(const std::string& fmt, const T&... t)
+// Retrieves system environment in a `std::map`, ignoring
+// the current process's environment variables.
+inline Option<std::map<std::wstring, std::wstring>> get_system_env()
 {
-  const Try<std::string> command = strings::internal::format(fmt, t...);
-  if (command.isError()) {
-    return Error(command.error());
+  std::map<std::wstring, std::wstring> system_env;
+  wchar_t* env_entry = nullptr;
+
+  // Get the system environment.
+  // The third parameter (bool) tells the function *not* to inherit
+  // variables from the current process.
+  if (!::CreateEnvironmentBlock((LPVOID*)&env_entry, nullptr, FALSE)) {
+    return None();
   }
 
-  FILE* file;
-  std::ostringstream stdoutstr;
+  // Save the environment block in order to destroy it later.
+  wchar_t* env_block = env_entry;
 
-  if ((file = _popen(command.get().c_str(), "r")) == nullptr) {
-    return Error("Failed to run '" + command.get() + "'");
-  }
+  while (*env_entry != L'\0') {
+    // Each environment block contains the environment variables as follows:
+    // Var1=Value1\0
+    // Var2=Value2\0
+    // Var3=Value3\0
+    // ...
+    // VarN=ValueN\0\0
+    // The name of an environment variable cannot include an equal sign (=).
 
-  char line[1024];
-  // NOTE(vinod): Ideally the if and while loops should be interchanged. But
-  // we get a broken pipe error if we don't read the output and simply close.
-  while (fgets(line, sizeof(line), file) != nullptr) {
-    stdoutstr << line;
-  }
+    // Construct a string from the pointer up to the first '\0',
+    // e.g. "Var1=Value1\0", then split into name and value.
+    std::wstring entry(env_entry);
+    std::wstring::size_type separator = entry.find(L"=");
+    std::wstring var_name(entry.substr(0, separator));
+    std::wstring varVal(entry.substr(separator + 1));
 
-  if (ferror(file) != 0) {
-    _pclose(file); // Ignoring result since we already have an error.
-    return Error("Error reading output of '" + command.get() + "'");
-  }
+    // Mesos variables are upper case. Convert system variables to
+    // match the name provided by the scheduler in case of a collision.
+    // This is safe because Windows environment variables are case insensitive.
+    std::transform(
+        var_name.begin(), var_name.end(), var_name.begin(), ::towupper);
 
-  int status;
-  if ((status = _pclose(file)) == -1) {
-    return Error("Failed to get status of '" + command.get() + "'");
+    // The system environment has priority.
+    system_env.insert_or_assign(var_name.data(), varVal.data());
+
+    // Advance the pointer the length of the entry string plus the '\0'.
+    env_entry += entry.length() + 1;
   }
 
-  return stdoutstr.str();
+  ::DestroyEnvironmentBlock(env_block);
+
+  return system_env;
 }
 
 
-// Executes a command by calling "cmd /c <command>", and returns
-// after the command has been completed. Returns 0 if succeeds, and
-// return -1 on error.
+// Creates a null-terminated array of null-terminated strings that will be
+// passed to `CreateProcessW` as the `lpEnvironment` argument, as described by
+// MSDN[1]. This array needs to be sorted in alphabetical order, but the `map`
+// already takes care of that. Note that this function explicitly handles
+// UTF-16 environments, so it must be used in conjunction with the
+// `CREATE_UNICODE_ENVIRONMENT` flag.
 //
-// The returned value from `_spawnlp` represents child exit code when
-// `_P_WAIT` is used.
+// NOTE: This function will add the system's environment variables into
+// the returned string. These variables take precedence over the provided
+// `env` and are generally necessary in order to launch things on Windows.
 //
-// Note: Be cautious about shell injection
-// (https://en.wikipedia.org/wiki/Code_injection#Shell_injection)
-// when using this method and use proper validation and sanitization
-// on the `command`. For this reason in general `os::spawn` is
-// preferred if a shell is not required.
-inline int system(const std::string& command)
+// [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx
+inline Option<std::wstring> create_process_env(
+    const Option<std::map<std::string, std::string>>& env)
 {
-  return static_cast<int>(::_spawnlp(
-    _P_WAIT, Shell::name, Shell::arg0, Shell::arg1, command.c_str(), nullptr));
-}
+  if (env.isNone() || (env.isSome() && env.get().size() == 0)) {
+    return None();
+  }
 
+  Option<std::map<std::wstring, std::wstring>> system_env = get_system_env();
 
-// Executes a command by calling "<command> <arguments...>", and
-// returns after the command has been completed. Returns 0 if
-// succeeds, and -1 on error.
-inline int spawn(
-    const std::string& command,
-    const std::vector<std::string>& arguments)
-{
-  return static_cast<int>(
-      ::_spawnvp(_P_WAIT, command.c_str(), os::raw::Argv(arguments)));
-}
+  // The system environment must be non-empty.
+  // No subprocesses will be able to launch if the system environment is blank.
+  CHECK(system_env.isSome() && system_env.get().size() > 0);
 
-// On Windows, the `_spawnlp` call creates a new process.
-// In order to emulate the semantics of `execlp`, we spawn with `_P_WAIT`,
-// which forces the parent process to block on the child. When the child exits,
-// the exit code is propagated back through the parent via `exit()`.
-//
-// The returned value from `_spawnlp` represents child exit code when
-// `_P_WAIT` is used.
-template<typename... T>
-inline int execlp(const char* file, T... t)
-{
-  exit(static_cast<int>(::_spawnlp(_P_WAIT, file, t...)));
-  return 0;
-}
+  std::map<std::wstring, std::wstring> combined_env;
 
+  // Populate the combined environment first with the given environment
+  // converted to UTF-16 for Windows.
+  foreachpair (const std::string& key,
+               const std::string& value,
+               env.get()) {
+    combined_env[wide_stringify(key)] = wide_stringify(value);
+  }
 
-// On Windows, the `_spawnvp` call creates a new process.
-// In order to emulate the semantics of `execvp`, we spawn with `_P_WAIT`,
-// which forces the parent process to block on the child. When the child exits,
-// the exit code is propagated back through the parent via `exit()`.
-//
-// The returned value from `_spawnlp` represents child exit code when
-// `_P_WAIT` is used.
-inline int execvp(const char* file, char* const argv[])
-{
-  exit(static_cast<int>(::_spawnvp(_P_WAIT, file, argv)));
-  return 0;
-}
+  // Add the system environment variables, overwriting the previous.
+  foreachpair (const std::wstring& key,
+               const std::wstring& value,
+               system_env.get()) {
+    combined_env[key] = value;
+  }
 
+  std::wstring env_string;
+  foreachpair (const std::wstring& key,
+               const std::wstring& value,
+               combined_env) {
+    env_string += key + L'=' + value + L'\0';
+  }
 
-// On Windows, the `_spawnvpe` call creates a new process.
-// In order to emulate the semantics of `execvpe`, we spawn with `_P_WAIT`,
-// which forces the parent process to block on the child. When the child exits,
-// the exit code is propagated back through the parent via `exit()`.
-//
-// The returned value from `_spawnvpe` represents child exit code when
-// `_P_WAIT` is used.
-inline int execvpe(const char* file, char* const argv[], char* const envp[])
-{
-  exit(static_cast<int>(::_spawnvpe(_P_WAIT, file, argv, envp)));
-  return 0;
+  // Append final null terminating character.
+  env_string.push_back(L'\0');
+  return env_string;
 }
 
 
@@ -188,10 +163,9 @@ inline int execvpe(const char* file, char* const argv[], char* const envp[])
 // NOLINT(whitespace/line_length)
 inline std::wstring stringify_args(const std::vector<std::string>& argv)
 {
-  std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter;
   std::wstring command;
   for (auto argit = argv.cbegin(); argit != argv.cend(); ++argit) {
-    std::wstring arg = converter.from_bytes(*argit);
+    std::wstring arg = wide_stringify(*argit);
     // Don't quote empty arguments or those without troublesome characters.
     if (!arg.empty() && arg.find_first_of(L" \t\n\v\"") == arg.npos) {
       command.append(arg);
@@ -235,6 +209,198 @@ inline std::wstring stringify_args(const std::vector<std::string>& argv)
   return command;
 }
 
+struct ProcessData {
+  SharedHandle process_handle;
+  SharedHandle thread_handle;
+  pid_t pid;
+};
+
+// Provides an interface for creating a child process on Windows.
+//
+// The `command` argument is given for compatibility, and is ignored. This is
+// because the `CreateProcess` will use `argv[0]` as the command to be executed,
+// and will perform a `PATH` lookup. If `command` were to be used instead,
+// `CreateProcess` would require an absolute path.
+//
+// If `create_suspended` is `true`, the process will not be started, and the
+// caller must use `ResumeThread` to start the process.
+//
+// The caller can specify explicit `stdin`, `stdout`, and `stderr` handles,
+// in that order, for the process via the `pipes` argument.
+//
+// The return value is a `ProcessData` struct, with the process and thread
+// handles each saved in a `SharedHandle`, ensuring they are closed when struct
+// goes out of scope.
+inline Try<ProcessData> create_process(
+    const std::string& command,
+    const std::vector<std::string>& argv,
+    const Option<std::map<std::string, std::string>>& environment,
+    const bool create_suspended = false,
+    const Option<std::tuple<int_fd, int_fd, int_fd>> pipes = None())
+{
+  // TODO(andschwa): Assert that `command` and `argv[0]` are the same.
+  std::wstring arg_string = stringify_args(argv);
+  std::vector<wchar_t> arg_buffer(arg_string.begin(), arg_string.end());
+  arg_buffer.push_back(L'\0');
+
+  // Create the process with a Unicode environment.
+  DWORD creation_flags = CREATE_UNICODE_ENVIRONMENT;
+  if (create_suspended) {
+    creation_flags |= CREATE_SUSPENDED;
+  }
+
+  // Construct the environment that will be passed to `::CreateProcessW`.
+  Option<std::wstring> env_string = create_process_env(environment);
+  std::vector<wchar_t> env_buffer;
+  if (env_string.isSome()) {
+    // This string contains the necessary null characters.
+    env_buffer.assign(env_string.get().begin(), env_string.get().end());
+  }
+
+  wchar_t* process_env = env_buffer.empty() ? nullptr : env_buffer.data();
+
+  PROCESS_INFORMATION process_info;
+  memset(&process_info, 0, sizeof(PROCESS_INFORMATION));
+
+  STARTUPINFOW startup_info;
+  memset(&startup_info, 0, sizeof(STARTUPINFOW));
+  startup_info.cb = sizeof(STARTUPINFOW);
+
+  // Hook up the stdin/out/err pipes and use the `STARTF_USESTDHANDLES`
+  // flag to instruct the child to use them [1].
+  // A more user-friendly example can be found in [2].
+  //
+  // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms686331(v=vs.85).aspx
+  // [2] https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspx
+  if (pipes.isSome()) {
+    startup_info.hStdInput = std::get<0>(pipes.get());
+    startup_info.hStdOutput = std::get<1>(pipes.get());
+    startup_info.hStdError = std::get<2>(pipes.get());
+    startup_info.dwFlags |= STARTF_USESTDHANDLES;
+  }
+
+  BOOL create_process_result = ::CreateProcessW(
+      // This is replaced by the first token of `arg_buffer` string.
+      static_cast<LPCWSTR>(nullptr),
+      static_cast<LPWSTR>(arg_buffer.data()),
+      static_cast<LPSECURITY_ATTRIBUTES>(nullptr),
+      static_cast<LPSECURITY_ATTRIBUTES>(nullptr),
+      TRUE, // Inherited parent process handles.
+      creation_flags,
+      static_cast<LPVOID>(process_env),
+      static_cast<LPCWSTR>(nullptr), // Inherited working directory.
+      &startup_info,
+      &process_info);
+
+  if (!create_process_result) {
+    return WindowsError(
+        "Failed to call `CreateProcess`: " + stringify(arg_buffer));
+  }
+
+  return ProcessData{
+    SharedHandle{process_info.hProcess, ::CloseHandle},
+    SharedHandle{process_info.hThread, ::CloseHandle},
+    static_cast<pid_t>(process_info.dwProcessId)};
+}
+
+} // namespace windows {
+
+} // namespace internal {
+
+namespace os {
+
+namespace Shell {
+
+// Canonical constants used as platform-dependent args to `exec` calls.
+// `name` is the command name, `arg0` is the first argument received
+// by the callee, usually the command name and `arg1` is the second
+// command argument received by the callee.
+constexpr const char* name = "cmd.exe";
+constexpr const char* arg0 = "cmd.exe";
+constexpr const char* arg1 = "/c";
+
+} // namespace Shell {
+
+template <typename... T>
+Try<std::string> shell(const std::string& fmt, const T&... t) = delete;
+
+
+template<typename... T>
+inline int execlp(const char* file, T... t) = delete;
+
+
+// Executes a command by calling "<command> <arguments...>", and
+// returns after the command has been completed. Returns process exit code if
+// succeeds, and -1 on error.
+inline int spawn(
+    const std::string& command,
+    const std::vector<std::string>& arguments,
+    const Option<std::map<std::string, std::string>>& environment = None())
+{
+  Try<::internal::windows::ProcessData> process_data =
+    ::internal::windows::create_process(command, arguments, environment);
+
+  if (process_data.isError()) {
+    LOG(WARNING) << process_data.error();
+    return -1;
+  }
+
+  // Wait for the process synchronously.
+  ::WaitForSingleObject(
+      process_data.get().process_handle.get_handle(), INFINITE);
+
+  int status;
+  if (!::GetExitCodeProcess(
+           process_data.get().process_handle.get_handle(),
+           &static_cast<DWORD>(status))) {
+    LOG(WARNING) << "Failed to `GetExitCodeProcess`: " << command;
+    return -1;
+  }
+
+  // Return the child exit code.
+  return status;
+}
+
+
+// Executes a command by calling "cmd /c <command>", and returns
+// after the command has been completed. Returns exit code if succeeds, and
+// return -1 on error.
+//
+// Note: Be cautious about shell injection
+// (https://en.wikipedia.org/wiki/Code_injection#Shell_injection)
+// when using this method and use proper validation and sanitization
+// on the `command`. For this reason in general `os::spawn` is
+// preferred if a shell is not required.
+inline int system(const std::string& command)
+{
+  return os::spawn(Shell::name, {Shell::arg0, Shell::arg1, command});
+}
+
+
+// In order to emulate the semantics of `execvp`, `os::spawn` waits for the new
+// process to exit, and returns its error code, which is propogated back to the
+// parent via `exit` here.
+inline int execvp(
+    const std::string& command,
+    const std::vector<std::string>& argv)
+{
+  exit(os::spawn(command, argv));
+  return -1;
+}
+
+
+// NOTE: This function can accept `Argv` and `Envp` constructs through their
+// explicit type conversions, but unlike the POSIX implementations, it cannot
+// accept the raw forms.
+inline int execvpe(
+    const std::string& command,
+    const std::vector<std::string>& argv,
+    const std::map<std::string, std::string>& envp)
+{
+  exit(os::spawn(command, argv, envp));
+  return -1;
+}
+
 } // namespace os {
 
 #endif // __STOUT_OS_WINDOWS_SHELL_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/c200bece/3rdparty/stout/tests/os/process_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/os/process_tests.cpp b/3rdparty/stout/tests/os/process_tests.cpp
index 09f7495..4b5c257 100644
--- a/3rdparty/stout/tests/os/process_tests.cpp
+++ b/3rdparty/stout/tests/os/process_tests.cpp
@@ -215,28 +215,12 @@ TEST_F(ProcessTest, Pstree)
               1u == total_children) << stringify(tree.get());
   const bool conhost_spawned = total_children == 1;
 
-  // Windows has no `sleep` command, so we fake it with `ping`.
-  const string command = "ping 127.0.0.1 -n 2";
-
-  STARTUPINFO si;
-  PROCESS_INFORMATION pi;
-  ZeroMemory(&si, sizeof(si));
-  si.cb = sizeof(si);
-  ZeroMemory(&pi, sizeof(pi));
-
-  // Create new process that "sleeps".
-  BOOL created = CreateProcess(
-      nullptr,                // No module name (use command line).
-      (LPSTR)command.c_str(),
-      nullptr,                // Process handle not inheritable.
-      nullptr,                // Thread handle not inheritable.
-      FALSE,                  // Set handle inheritance to FALSE.
-      0,                      // No creation flags.
-      nullptr,                // Use parent's environment block.
-      nullptr,                // Use parent's starting directory.
-      &si,
-      &pi);
-  ASSERT_TRUE(created == TRUE);
+  Try<internal::windows::ProcessData> process_data =
+    internal::windows::create_process(
+        "powershell",
+        {"powershell", "-NoProfile", "-Command", "Start-Sleep", "2"},
+        None());
+  ASSERT_SOME(process_data);
 
   Try<ProcessTree> tree_after_spawn = os::pstree(getpid());
   ASSERT_SOME(tree_after_spawn);
@@ -248,7 +232,9 @@ TEST_F(ProcessTest, Pstree)
               (conhost_spawned && 2u == children_after_span)
               ) << stringify(tree_after_spawn.get());
 
-  WaitForSingleObject(pi.hProcess, INFINITE);
+  // Wait for the process synchronously.
+  ::WaitForSingleObject(
+      process_data.get().process_handle.get_handle(), INFINITE);
 }
 #else
 TEST_F(ProcessTest, Pstree)

http://git-wip-us.apache.org/repos/asf/mesos/blob/c200bece/3rdparty/stout/tests/os_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/os_tests.cpp b/3rdparty/stout/tests/os_tests.cpp
index b6491c4..e8ecece 100644
--- a/3rdparty/stout/tests/os_tests.cpp
+++ b/3rdparty/stout/tests/os_tests.cpp
@@ -925,9 +925,9 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(OsTest, Libraries)
 }
 
 
-// TODO(hausdorff): Port this test to Windows; these shell commands as they
-// exist now don't make much sense to the Windows cmd prompt. See MESOS-3441.
-TEST_F_TEMP_DISABLED_ON_WINDOWS(OsTest, Shell)
+// NOTE: `os::shell()` is explicitly disallowed on Windows.
+#ifndef __WINDOWS__
+TEST_F(OsTest, Shell)
 {
   Try<string> result = os::shell("echo %s", "hello world");
   EXPECT_SOME_EQ("hello world\n", result);
@@ -952,6 +952,7 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(OsTest, Shell)
   EXPECT_SOME_EQ("", result);
   EXPECT_FALSE(os::exists("/tmp/os_tests.txt"));
 }
+#endif // __WINDOWS__
 
 
 // NOTE: Disabled on Windows because `mknod` does not exist.


[37/50] mesos git commit: Windows: Disable code using `os::shell()`.

Posted by jo...@apache.org.
Windows: Disable code using `os::shell()`.

The disabled tests were already disabled, but at runtime instead of
compile time. Deleting `os::shell()` forces us to temporarily disable
the IP discovery command flag until we can move the implementation of
`subprocess()` into stout.

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


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

Branch: refs/heads/master
Commit: 129d431c0635d5f2412d13bf38e929dfbdd000a5
Parents: 3ec06c6
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 14:39:46 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:37 2017 -0700

----------------------------------------------------------------------
 src/slave/main.cpp          | 10 ++++++++++
 src/tests/fetcher_tests.cpp | 24 ++++++++++++++++++++----
 2 files changed, 30 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/129d431c/src/slave/main.cpp
----------------------------------------------------------------------
diff --git a/src/slave/main.cpp b/src/slave/main.cpp
index 578f7c8..a4a8ced 100644
--- a/src/slave/main.cpp
+++ b/src/slave/main.cpp
@@ -302,6 +302,7 @@ int main(int argc, char** argv)
   }
 
   if (flags.ip_discovery_command.isSome()) {
+#ifndef __WINDOWS__
     Try<string> ipAddress = os::shell(flags.ip_discovery_command.get());
 
     if (ipAddress.isError()) {
@@ -309,17 +310,26 @@ int main(int argc, char** argv)
     }
 
     os::setenv("LIBPROCESS_IP", strings::trim(ipAddress.get()));
+#else
+    EXIT(EXIT_FAILURE)
+      << "The `--ip_discovery_command` is not yet supported on Windows";
+#endif // __WINDOWS__
   } else if (flags.ip.isSome()) {
     os::setenv("LIBPROCESS_IP", flags.ip.get());
   }
 
   if (flags.ip6_discovery_command.isSome()) {
+#ifndef __WINDOWS__
     Try<string> ip6Address = os::shell(flags.ip6_discovery_command.get());
     if (ip6Address.isError()) {
       EXIT(EXIT_FAILURE) << ip6Address.error();
     }
 
     os::setenv("LIBPROCESS_IP6", strings::trim(ip6Address.get()));
+#else
+    EXIT(EXIT_FAILURE)
+      << "The `--ip6_discovery_command` is not yet supported on Windows";
+#endif // __WINDOWS__
   } else if (flags.ip6.isSome()) {
     os::setenv("LIBPROCESS_IP6", flags.ip6.get());
   }

http://git-wip-us.apache.org/repos/asf/mesos/blob/129d431c/src/tests/fetcher_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/fetcher_tests.cpp b/src/tests/fetcher_tests.cpp
index 99149ba..01da9fe 100644
--- a/src/tests/fetcher_tests.cpp
+++ b/src/tests/fetcher_tests.cpp
@@ -657,7 +657,9 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(FetcherTest, NoExtractExecutable)
 }
 
 
-TEST_F_TEMP_DISABLED_ON_WINDOWS(FetcherTest, ExtractNotExecutable)
+// NOTE: This is disabled on Windows because `os::shell()` is deleted.
+#ifndef __WINDOWS__
+TEST_F(FetcherTest, ExtractNotExecutable)
 {
   // First construct a temporary file that can be fetched and archived with tar
   // gzip.
@@ -709,10 +711,13 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(FetcherTest, ExtractNotExecutable)
 
   verifyMetrics(1, 0);
 }
+#endif // __WINDOWS__
 
 
 // Tests extracting tar file with extension .tar.
-TEST_F_TEMP_DISABLED_ON_WINDOWS(FetcherTest, ExtractTar)
+// NOTE: This is disabled on Windows because `os::shell()` is deleted.
+#ifndef __WINDOWS__
+TEST_F(FetcherTest, ExtractTar)
 {
   // First construct a temporary file that can be fetched and archived with
   // tar.
@@ -755,9 +760,12 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(FetcherTest, ExtractTar)
 
   verifyMetrics(1, 0);
 }
+#endif // __WINDOWS__
 
 
-TEST_F_TEMP_DISABLED_ON_WINDOWS(FetcherTest, ExtractGzipFile)
+// NOTE: This is disabled on Windows because `os::shell()` is deleted.
+#ifndef __WINDOWS__
+TEST_F(FetcherTest, ExtractGzipFile)
 {
   // First construct a temporary file that can be fetched and archived with
   // gzip.
@@ -795,6 +803,7 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(FetcherTest, ExtractGzipFile)
 
   verifyMetrics(1, 0);
 }
+#endif // __WINDOWS__
 
 
 TEST_F_TEMP_DISABLED_ON_WINDOWS(FetcherTest, UNZIP_ExtractFile)
@@ -999,6 +1008,8 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(FetcherTest, UseCustomOutputFile)
 }
 
 
+// NOTE: This is disabled on Windows because `os::shell()` is deleted.
+#ifndef __WINDOWS__
 TEST_F_TEMP_DISABLED_ON_WINDOWS(FetcherTest, CustomGzipOutputFile)
 {
   // First construct a temporary file that can be fetched.
@@ -1038,6 +1049,7 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(FetcherTest, CustomGzipOutputFile)
 
   verifyMetrics(1, 0);
 }
+#endif // __WINDOWS__
 
 
 // TODO(hausdorff): `os::chmod` does not exist on Windows.
@@ -1138,7 +1150,10 @@ TEST_F(FetcherTest, HdfsURI)
 // agent towards the fetcher. By supplying an invalid SSL setup, we
 // force the fetcher to fail if the parent process does not filter
 // them out.
-TEST_F_TEMP_DISABLED_ON_WINDOWS(FetcherTest, SSLEnvironmentSpillover)
+//
+// NOTE: This is disabled on Windows because `os::shell()` is deleted.
+#ifndef __WINDOWS__
+TEST_F(FetcherTest, SSLEnvironmentSpillover)
 {
   // Patch some critical libprocess environment variables into the
   // parent process of the mesos-fetcher. We expect this test to fail
@@ -1192,6 +1207,7 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(FetcherTest, SSLEnvironmentSpillover)
     os::setenv("LIBPROCESS_SSL_KEY_FILE", key);
   }
 }
+#endif // __WINDOWS__
 
 } // namespace tests {
 } // namespace internal {


[41/50] mesos git commit: Windows: Made environment abstractions use Unicode.

Posted by jo...@apache.org.
Windows: Made environment abstractions use Unicode.

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


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

Branch: refs/heads/master
Commit: 0f2bfe7623c1df62b6ac7fc9cfe7733b021b001f
Parents: 498c530
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 15:14:08 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:38 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/os/windows/environment.hpp | 12 +++++++-----
 3rdparty/stout/include/stout/os/windows/getenv.hpp      | 12 ++++++++----
 3rdparty/stout/include/stout/windows/os.hpp             |  7 ++++---
 3 files changed, 19 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0f2bfe76/3rdparty/stout/include/stout/os/windows/environment.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/environment.hpp b/3rdparty/stout/include/stout/os/windows/environment.hpp
index 96f0eb4..f79cbfa 100644
--- a/3rdparty/stout/include/stout/os/windows/environment.hpp
+++ b/3rdparty/stout/include/stout/os/windows/environment.hpp
@@ -15,6 +15,7 @@
 
 #include <map>
 #include <string>
+#include <stout/stringify.hpp>
 
 
 namespace os {
@@ -28,21 +29,22 @@ inline std::map<std::string, std::string> environment()
   // Var3=Value3\0
   // ...
   // VarN=ValueN\0\0
-  char* env = GetEnvironmentStrings();
+  wchar_t* env = ::GetEnvironmentStringsW();
   std::map<std::string, std::string> result;
 
-  for (size_t i = 0; env[i] != '\0' && env[i+1] != '\0';) {
-    std::string entry(env + i);
+  for (size_t i = 0; env[i] != L'\0' && env[i+1] != L'\0';) {
+    std::wstring entry(env + i);
 
     // Increment past the current environment string and null terminator.
     i = i + entry.size() + 1;
 
-    size_t position = entry.find_first_of('=');
+    size_t position = entry.find_first_of(L'=');
     if (position == std::string::npos) {
       continue; // Skip malformed environment entries.
     }
 
-    result[entry.substr(0, position)] = entry.substr(position + 1);
+    result[stringify(entry.substr(0, position))] =
+      stringify(entry.substr(position + 1));
   }
 
   return result;

http://git-wip-us.apache.org/repos/asf/mesos/blob/0f2bfe76/3rdparty/stout/include/stout/os/windows/getenv.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/getenv.hpp b/3rdparty/stout/include/stout/os/windows/getenv.hpp
index 2200f85..27a0e87 100644
--- a/3rdparty/stout/include/stout/os/windows/getenv.hpp
+++ b/3rdparty/stout/include/stout/os/windows/getenv.hpp
@@ -18,6 +18,7 @@
 
 #include <stout/none.hpp>
 #include <stout/option.hpp>
+#include <stout/stringify.hpp>
 #include <stout/windows.hpp>
 
 
@@ -28,20 +29,23 @@ namespace os {
 // variable matching key is found, None() is returned.
 inline Option<std::string> getenv(const std::string& key)
 {
+  std::wstring wide_key = wide_stringify(key);
+
   // NOTE: The double-call to `::GetEnvironmentVariable` here uses the first
   // call to get the size of the variable's value, and then again to retrieve
   // the value itself. It is possible to have `::GetEnvironmentVariable`
   // allocate the space for this, but we explicitly do it this way to avoid
   // that.
-  DWORD buffer_size = ::GetEnvironmentVariable(key.c_str(), nullptr, 0);
+  DWORD buffer_size = ::GetEnvironmentVariableW(wide_key.data(), nullptr, 0);
   if (buffer_size == 0) {
     return None();
   }
 
-  std::unique_ptr<char[]> environment(new char[buffer_size]);
+  std::vector<wchar_t> environment;
+  environment.reserve(static_cast<size_t>(buffer_size));
 
   DWORD value_size =
-    ::GetEnvironmentVariable(key.c_str(), environment.get(), buffer_size);
+    ::GetEnvironmentVariableW(wide_key.data(), environment.data(), buffer_size);
 
   if (value_size == 0) {
     // If `value_size == 0` here, that probably means the environment variable
@@ -50,7 +54,7 @@ inline Option<std::string> getenv(const std::string& key)
     return None();
   }
 
-  return std::string(environment.get());
+  return stringify(std::wstring(environment.data()));
 }
 
 } // namespace os {

http://git-wip-us.apache.org/repos/asf/mesos/blob/0f2bfe76/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/os.hpp b/3rdparty/stout/include/stout/windows/os.hpp
index 42fda71..e24022e 100644
--- a/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/stout/include/stout/windows/os.hpp
@@ -209,13 +209,14 @@ inline void setenv(
   //
   // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms683188(v=vs.85).aspx
   if (!overwrite &&
-      ::GetEnvironmentVariable(key.c_str(), nullptr, 0) != 0 &&
+      ::GetEnvironmentVariableW(wide_stringify(key).data(), nullptr, 0) != 0 &&
       ::GetLastError() == ERROR_ENVVAR_NOT_FOUND) {
     return;
   }
 
   // `SetEnvironmentVariable` returns an error code, but we can't act on it.
-  ::SetEnvironmentVariable(key.c_str(), value.c_str());
+  ::SetEnvironmentVariableW(
+      wide_stringify(key).data(), wide_stringify(value).data());
 }
 
 
@@ -225,7 +226,7 @@ inline void unsetenv(const std::string& key)
 {
   // Per MSDN documentation[1], passing `nullptr` as the value will cause
   // `SetEnvironmentVariable` to delete the key from the process's environment.
-  ::SetEnvironmentVariable(key.c_str(), nullptr);
+  ::SetEnvironmentVariableW(wide_stringify(key).data(), nullptr);
 }
 
 


[10/50] mesos git commit: Windows: Added `get_file_attributes()` helper.

Posted by jo...@apache.org.
Windows: Added `get_file_attributes()` helper.

This wraps `::GetFileAttributesW()` into a `Try<DWORD>`, with error
handling, for easy reuse.

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


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

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

----------------------------------------------------------------------
 3rdparty/stout/include/Makefile.am              |  1 +
 .../stout/internal/windows/attributes.hpp       | 39 ++++++++++++++++++++
 2 files changed, 40 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/4c939b6d/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/Makefile.am b/3rdparty/stout/include/Makefile.am
index 8e1799b..d5d209b 100644
--- a/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/stout/include/Makefile.am
@@ -39,6 +39,7 @@ nobase_include_HEADERS =			\
   stout/gzip.hpp				\
   stout/hashmap.hpp				\
   stout/hashset.hpp				\
+  stout/internal/windows/attributes.hpp		\
   stout/internal/windows/dirent.hpp		\
   stout/internal/windows/grp.hpp		\
   stout/internal/windows/longpath.hpp		\

http://git-wip-us.apache.org/repos/asf/mesos/blob/4c939b6d/3rdparty/stout/include/stout/internal/windows/attributes.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/internal/windows/attributes.hpp b/3rdparty/stout/include/stout/internal/windows/attributes.hpp
new file mode 100644
index 0000000..673b744
--- /dev/null
+++ b/3rdparty/stout/include/stout/internal/windows/attributes.hpp
@@ -0,0 +1,39 @@
+// 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_INTERNAL_WINDOWS_ATTRIBUTES_HPP__
+#define __STOUT_INTERNAL_WINDOWS_ATTRIBUTES_HPP__
+
+#include <string>
+
+#include <stout/error.hpp>
+#include <stout/stringify.hpp>
+#include <stout/try.hpp>
+#include <stout/windows.hpp>
+
+
+namespace internal {
+namespace windows {
+
+inline Try<DWORD> get_file_attributes(const std::wstring& path) {
+  const DWORD attributes = ::GetFileAttributesW(path.data());
+  if (attributes == INVALID_FILE_ATTRIBUTES) {
+    return WindowsError(
+        "Failed to get attributes for file '" + stringify(path) + "'");
+  }
+  return attributes;
+}
+
+} // namespace windows {
+} // namespace internal {
+
+#endif // __STOUT_INTERNAL_WINDOWS_ATTRIBUTES_HPP__


[34/50] mesos git commit: Windows: Implemented `os::ls()` without `dirent.hpp`.

Posted by jo...@apache.org.
Windows: Implemented `os::ls()` without `dirent.hpp`.

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


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

Branch: refs/heads/master
Commit: bb52f6c2cf1a13ad64645595f9cdb12aa305a7f0
Parents: 3ebe54d
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 14:45:59 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:37 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/Makefile.am              |   3 +-
 .../include/stout/internal/windows/dirent.hpp   | 228 -------------------
 3rdparty/stout/include/stout/os/ls.hpp          |  56 +----
 3rdparty/stout/include/stout/os/posix/ls.hpp    |  67 ++++++
 3rdparty/stout/include/stout/os/windows/ls.hpp  |  71 ++++++
 5 files changed, 145 insertions(+), 280 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/bb52f6c2/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/Makefile.am b/3rdparty/stout/include/Makefile.am
index 4068f0e..80724f4 100644
--- a/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/stout/include/Makefile.am
@@ -40,7 +40,6 @@ nobase_include_HEADERS =			\
   stout/hashmap.hpp				\
   stout/hashset.hpp				\
   stout/internal/windows/attributes.hpp		\
-  stout/internal/windows/dirent.hpp		\
   stout/internal/windows/grp.hpp		\
   stout/internal/windows/longpath.hpp		\
   stout/internal/windows/pwd.hpp		\
@@ -130,6 +129,7 @@ nobase_include_HEADERS =			\
   stout/os/posix/getenv.hpp			\
   stout/os/posix/kill.hpp			\
   stout/os/posix/killtree.hpp			\
+  stout/os/posix/ls.hpp				\
   stout/os/posix/mkdir.hpp			\
   stout/os/posix/mkdtemp.hpp			\
   stout/os/posix/mktemp.hpp			\
@@ -167,6 +167,7 @@ nobase_include_HEADERS =			\
   stout/os/windows/getenv.hpp			\
   stout/os/windows/kill.hpp			\
   stout/os/windows/killtree.hpp			\
+  stout/os/windows/ls.hpp			\
   stout/os/windows/mkdir.hpp			\
   stout/os/windows/mktemp.hpp			\
   stout/os/windows/mkdtemp.hpp			\

http://git-wip-us.apache.org/repos/asf/mesos/blob/bb52f6c2/3rdparty/stout/include/stout/internal/windows/dirent.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/internal/windows/dirent.hpp b/3rdparty/stout/include/stout/internal/windows/dirent.hpp
deleted file mode 100644
index 7dbdb10..0000000
--- a/3rdparty/stout/include/stout/internal/windows/dirent.hpp
+++ /dev/null
@@ -1,228 +0,0 @@
-// 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_INTERNAL_WINDOWS_DIRENT_HPP__
-#define __STOUT_INTERNAL_WINDOWS_DIRENT_HPP__
-
-#include <assert.h>
-#include <malloc.h>
-
-#include <stout/windows.hpp>
-
-
-// Abbreviated version of the POSIX `dirent` struct. cf. specification[1].
-//
-// [1] http://www.gnu.org/software/libc/manual/html_node/Directory-Entries.html
-struct dirent
-{
-  char d_name[MAX_PATH];
-  unsigned short d_namlen;
-};
-
-
-// `DIR` is normally an opaque struct in the standard, we expose the
-// implementation here because this header is intended for internal use only.
-struct DIR
-{
-  struct dirent curr;
-  char *d_name;
-  WIN32_FIND_DATA fd;
-  HANDLE handle;
-};
-
-
-// Avoid the C++-style name-mangling linkage, and use C-style instead to give
-// the appearance that this code is part of the real C standard library.
-extern "C" {
-namespace internal {
-
-void free_dir(DIR* directory);
-
-bool open_dir_stream(DIR* directory);
-
-bool reentrant_advance_dir_stream(DIR* directory);
-
-} // namespace internal {
-
-
-// Windows implementation of POSIX standard `opendir`. cf. specification[1].
-//
-// [1] http://www.gnu.org/software/libc/manual/html_node/Opening-a-Directory.html#Opening-a-Directory
-inline DIR* opendir(const char* path)
-{
-  if (path == nullptr) {
-    errno = ENOTDIR;
-    return nullptr;
-  }
-
-  const size_t path_size = strlen(path);
-
-  if (path_size == 0 || path_size >= MAX_PATH) {
-    errno = ENOENT;
-    return nullptr;
-  }
-
-  const char windows_folder_separator = '\\';
-  const char windows_drive_separator = ':';
-  const char wildcard[] = "*";
-  const char dir_separator_and_wildcard[] = "\\*";
-
-  // Allocate space for directory. Be sure to leave room at the end of
-  // `directory->d_name` for a directory separator and a wildcard.
-  DIR* directory = (DIR*) malloc(sizeof(DIR));
-
-  if (directory == nullptr) {
-    errno = ENOMEM;
-    return nullptr;
-  }
-
-  directory->d_name =
-    (char*) malloc(path_size + strlen(dir_separator_and_wildcard) + 1);
-
-  if (directory->d_name == nullptr) {
-    errno = ENOMEM;
-    free(directory);
-    return nullptr;
-  }
-
-  // Copy path over and append the appropriate postfix.
-  strcpy(directory->d_name, path);
-
-  const size_t last_char_in_name =
-    directory->d_name[strlen(directory->d_name) - 1];
-
-  if (last_char_in_name != windows_folder_separator &&
-      last_char_in_name != windows_drive_separator) {
-    strcat(directory->d_name, dir_separator_and_wildcard);
-  } else {
-    strcat(directory->d_name, wildcard);
-  }
-
-  if (!internal::open_dir_stream(directory)) {
-    internal::free_dir(directory);
-    return nullptr;
-  }
-
-  return directory;
-}
-
-
-// Implementation of the standard POSIX function. See documentation[1].
-//
-// On success: returns a pointer to the next directory entry, or `nullptr` if
-// we've reached the end of the stream.
-//
-// On failure: returns `nullptr` and sets `errno`.
-//
-// NOTE: as with most POSIX implementations of this function, you must reset
-// `errno` before calling `readdir`.
-//
-// [1] http://www.gnu.org/software/libc/manual/html_node/Reading_002fClosing-Directory.html#Reading_002fClosing-Directory
-inline struct dirent* readdir(DIR* directory)
-{
-  if (directory == nullptr) {
-    errno = EBADF;
-    return nullptr;
-  }
-
-  if (!internal::reentrant_advance_dir_stream(directory)) {
-    return nullptr;
-  }
-
-  return &directory->curr;
-}
-
-
-// Implementation of the standard POSIX function. See documentation[1].
-//
-// On success, return 0; on failure, return -1 and set `errno` appropriately.
-//
-// [1] http://www.gnu.org/software/libc/manual/html_node/Reading_002fClosing-Directory.html#Reading_002fClosing-Directory
-inline int closedir(DIR* directory)
-{
-  if (directory == nullptr) {
-    errno = EBADF;
-    return -1;
-  }
-
-  BOOL search_closed = false;
-
-  if (directory->handle != INVALID_HANDLE_VALUE) {
-    search_closed = FindClose(directory->handle);
-  }
-
-  internal::free_dir(directory);
-
-  return search_closed ? 0 : -1;
-}
-
-namespace internal {
-
-inline void free_dir(DIR* directory)
-{
-  if (directory != nullptr) {
-    free(directory->d_name);
-  }
-
-  free(directory);
-}
-
-
-inline bool open_dir_stream(DIR* directory)
-{
-  assert(directory != nullptr);
-
-  directory->handle = FindFirstFile(directory->d_name, &directory->fd);
-
-  if (directory->handle == INVALID_HANDLE_VALUE) {
-    errno = ENOENT;
-    return false;
-  }
-
-  // NOTE: `d_name` can be a statically-sized array of `MAX_PATH` size because
-  // `cFileName` is. See[1]. This simplifies this copy operation because we
-  // don't have to `malloc`.
-  //
-  // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa365740(v=vs.85).aspx
-  strcpy(directory->curr.d_name, directory->fd.cFileName);
-  directory->curr.d_namlen =
-    static_cast<unsigned short>(strlen(directory->curr.d_name));
-
-  return true;
-}
-
-
-inline bool reentrant_advance_dir_stream(DIR* directory)
-{
-  assert(directory != nullptr);
-
-  if (!FindNextFile(directory->handle, &directory->fd)) {
-    return false;
-  }
-
-  // NOTE: `d_name` can be a statically-sized array of `MAX_PATH` size because
-  // `cFileName` is. See[1]. This simplifies this copy operation because we
-  // don't have to `malloc`.
-  //
-  // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa365740(v=vs.85).aspx
-  strcpy(directory->curr.d_name, directory->fd.cFileName);
-  directory->curr.d_namlen =
-    static_cast<unsigned short>(strlen(directory->curr.d_name));
-
-  return true;
-}
-
-} // namespace internal {
-} // extern "C" {
-
-
-#endif // __STOUT_INTERNAL_WINDOWS_DIRENT_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/bb52f6c2/3rdparty/stout/include/stout/os/ls.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/ls.hpp b/3rdparty/stout/include/stout/os/ls.hpp
index 25e2bec..03e04e2 100644
--- a/3rdparty/stout/include/stout/os/ls.hpp
+++ b/3rdparty/stout/include/stout/os/ls.hpp
@@ -13,60 +13,14 @@
 #ifndef __STOUT_OS_LS_HPP__
 #define __STOUT_OS_LS_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/internal/windows/dirent.hpp>
+#include <stout/os/windows/ls.hpp>
 #else
-#include <dirent.h>
+#include <stout/os/posix/ls.hpp>
 #endif // __WINDOWS__
 
-#include <errno.h>
-#include <stdlib.h>
-
-#include <list>
-#include <string>
-
-#include <stout/error.hpp>
-#include <stout/try.hpp>
-
-
-namespace os {
-
-inline Try<std::list<std::string>> ls(const std::string& directory)
-{
-  DIR* dir = opendir(directory.c_str());
-
-  if (dir == nullptr) {
-    return ErrnoError("Failed to opendir '" + directory + "'");
-  }
-
-  std::list<std::string> result;
-  struct dirent* entry;
-
-  // Zero `errno` before starting to call `readdir`. This is necessary
-  // to allow us to determine when `readdir` returns an error.
-  errno = 0;
-
-  while ((entry = readdir(dir)) != nullptr) {
-    if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
-      continue;
-    }
-    result.push_back(entry->d_name);
-  }
-
-  if (errno != 0) {
-    // Preserve `readdir` error.
-    Error error = ErrnoError("Failed to read directory");
-    closedir(dir);
-    return error;
-  }
-
-  if (closedir(dir) == -1) {
-    return ErrnoError("Failed to close directory");
-  }
-
-  return result;
-}
-
-} // namespace os {
 
 #endif // __STOUT_OS_LS_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/bb52f6c2/3rdparty/stout/include/stout/os/posix/ls.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/ls.hpp b/3rdparty/stout/include/stout/os/posix/ls.hpp
new file mode 100644
index 0000000..6fa1067
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/posix/ls.hpp
@@ -0,0 +1,67 @@
+// 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_LS_HPP__
+#define __STOUT_OS_POSIX_LS_HPP__
+
+#include <dirent.h>
+#include <errno.h>
+#include <stdlib.h>
+
+#include <list>
+#include <string>
+
+#include <stout/error.hpp>
+#include <stout/try.hpp>
+
+
+namespace os {
+
+inline Try<std::list<std::string>> ls(const std::string& directory)
+{
+  DIR* dir = opendir(directory.c_str());
+
+  if (dir == nullptr) {
+    return ErrnoError("Failed to opendir '" + directory + "'");
+  }
+
+  std::list<std::string> result;
+  struct dirent* entry;
+
+  // Zero `errno` before starting to call `readdir`. This is necessary
+  // to allow us to determine when `readdir` returns an error.
+  errno = 0;
+
+  while ((entry = readdir(dir)) != nullptr) {
+    if (strcmp(entry->d_name, ".") == 0 || strcmp(entry->d_name, "..") == 0) {
+      continue;
+    }
+    result.push_back(entry->d_name);
+  }
+
+  if (errno != 0) {
+    // Preserve `readdir` error.
+    Error error = ErrnoError("Failed to read directory");
+    closedir(dir);
+    return error;
+  }
+
+  if (closedir(dir) == -1) {
+    return ErrnoError("Failed to close directory");
+  }
+
+  return result;
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_POSIX_LS_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/bb52f6c2/3rdparty/stout/include/stout/os/windows/ls.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/ls.hpp b/3rdparty/stout/include/stout/os/windows/ls.hpp
new file mode 100644
index 0000000..98fad02
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/windows/ls.hpp
@@ -0,0 +1,71 @@
+// 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_LS_HPP__
+#define __STOUT_OS_LWINDOWS_S_HPP__
+
+#include <list>
+#include <string>
+
+#include <stout/error.hpp>
+#include <stout/try.hpp>
+
+#include <stout/internal/windows/longpath.hpp>
+
+
+namespace os {
+
+inline Try<std::list<std::string>> ls(const std::string& directory)
+{
+  // Ensure the path ends with a backslash.
+  std::string path = directory;
+  if (!strings::endsWith(path, "\\")) {
+    path += "\\";
+  }
+
+  // Get first file matching pattern `X:\path\to\wherever\*`.
+  WIN32_FIND_DATAW found;
+  const std::wstring search_pattern =
+    ::internal::windows::longpath(path) + L"*";
+
+  const SharedHandle search_handle(
+      ::FindFirstFileW(search_pattern.data(), &found),
+      ::FindClose);
+
+  if (search_handle.get() == INVALID_HANDLE_VALUE) {
+    return WindowsError("Failed to search '" + directory + "'");
+  }
+
+  std::list<std::string> result;
+
+  do {
+    // NOTE: do-while is appropriate here because folder is guaranteed to have
+    // at least a file called `.` (and probably also one called `..`).
+    const std::wstring current_file(found.cFileName);
+
+    const bool is_current_directory = current_file.compare(L".") == 0;
+    const bool is_parent_directory = current_file.compare(L"..") == 0;
+
+    // Ignore the `.` and `..` files in the directory.
+    if (is_current_directory || is_parent_directory) {
+      continue;
+    }
+
+    result.push_back(stringify(current_file));
+  } while (::FindNextFileW(search_handle.get(), &found));
+
+  return result;
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_WINDOWS_LS_HPP__


[12/50] mesos git commit: Updated fetcher to use `enum class FollowSymlink`.

Posted by jo...@apache.org.
Updated fetcher to use `enum class FollowSymlink`.

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


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

Branch: refs/heads/master
Commit: 7fdd28ddddc3d3bb2675318066d74b28f4c4306b
Parents: 841f879
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Fri Jul 7 12:41:50 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:33 2017 -0700

----------------------------------------------------------------------
 src/slave/containerizer/fetcher.cpp | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/7fdd28dd/src/slave/containerizer/fetcher.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/fetcher.cpp b/src/slave/containerizer/fetcher.cpp
index 5163ec0..6a664e0 100644
--- a/src/slave/containerizer/fetcher.cpp
+++ b/src/slave/containerizer/fetcher.cpp
@@ -294,7 +294,8 @@ static Try<Bytes> fetchSize(
     return Error(path.error());
   }
   if (path.isSome()) {
-    Try<Bytes> size = os::stat::size(path.get(), os::stat::FOLLOW_SYMLINK);
+    Try<Bytes> size = os::stat::size(
+        path.get(), os::stat::FollowSymlink::FOLLOW_SYMLINK);
     if (size.isError()) {
       return Error("Could not determine file size for: '" + path.get() +
                      "', error: " + size.error());
@@ -1129,7 +1130,7 @@ Try<Nothing> FetcherProcess::Cache::adjust(
 
   Try<Bytes> size = os::stat::size(
       entry.get()->path().string(),
-      os::stat::DO_NOT_FOLLOW_SYMLINK);
+      os::stat::FollowSymlink::DO_NOT_FOLLOW_SYMLINK);
 
   if (size.isSome()) {
     off_t d = delta(size.get(), entry);


[35/50] mesos git commit: Windows: Replaced `CreateProcess()` with `create_process()` helper.

Posted by jo...@apache.org.
Windows: Replaced `CreateProcess()` with `create_process()` helper.

This uses the new `ProcessData create_process()` abstraction added to
stout, reducing the use of the Windows API in libprocess. The
`ProcessData` struct eliminates the need to manually call
`CloseHandle()`.

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


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

Branch: refs/heads/master
Commit: 4b28a28c3a56ea96873df7414216a47702a81b61
Parents: c200bec
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 14:30:16 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:37 2017 -0700

----------------------------------------------------------------------
 .../libprocess/cmake/ProcessConfigure.cmake     |   7 -
 .../include/process/subprocess_base.hpp         |   7 +-
 .../include/process/windows/subprocess.hpp      | 197 ++-----------------
 3rdparty/libprocess/src/subprocess.cpp          |  29 +--
 4 files changed, 36 insertions(+), 204 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/4b28a28c/3rdparty/libprocess/cmake/ProcessConfigure.cmake
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/cmake/ProcessConfigure.cmake b/3rdparty/libprocess/cmake/ProcessConfigure.cmake
index 2c46d43..dd3be57 100755
--- a/3rdparty/libprocess/cmake/ProcessConfigure.cmake
+++ b/3rdparty/libprocess/cmake/ProcessConfigure.cmake
@@ -166,13 +166,6 @@ set(PROCESS_LIBS
   ${HTTP_PARSER_LFLAG}
   )
 
-if (WIN32)
-  set(PROCESS_LIBS
-    ${PROCESS_LIBS}
-    userenv
-    )
-endif ()
-
 if (NOT ENABLE_LIBEVENT)
   set(PROCESS_LIBS ${PROCESS_LIBS} ${LIBEV_LFLAG})
 else ()

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b28a28c/3rdparty/libprocess/include/process/subprocess_base.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/subprocess_base.hpp b/3rdparty/libprocess/include/process/subprocess_base.hpp
index a3edae6..d33be2b 100644
--- a/3rdparty/libprocess/include/process/subprocess_base.hpp
+++ b/3rdparty/libprocess/include/process/subprocess_base.hpp
@@ -318,17 +318,12 @@ private:
       if (in.isSome()) { os::close(in.get()); }
       if (out.isSome()) { os::close(out.get()); }
       if (err.isSome()) { os::close(err.get()); }
-
-#ifdef __WINDOWS__
-      CloseHandle(processInformation.hProcess);
-      CloseHandle(processInformation.hThread);
-#endif // __WINDOWS__
     }
 
     pid_t pid;
 
 #ifdef __WINDOWS__
-    PROCESS_INFORMATION processInformation;
+    Option<::internal::windows::ProcessData> process_data;
 #endif // __WINDOWS__
 
     // The parent side of the pipe for stdin/stdout/stderr. If the

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b28a28c/3rdparty/libprocess/include/process/windows/subprocess.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/windows/subprocess.hpp b/3rdparty/libprocess/include/process/windows/subprocess.hpp
index 5459955..0183bb4 100644
--- a/3rdparty/libprocess/include/process/windows/subprocess.hpp
+++ b/3rdparty/libprocess/include/process/windows/subprocess.hpp
@@ -16,6 +16,7 @@
 #include <signal.h>
 
 #include <string>
+#include <tuple>
 
 #include <glog/logging.h>
 
@@ -38,192 +39,34 @@
 namespace process {
 namespace internal {
 
-// Retrieves system environment in a `std::map`, ignoring
-// the current process's environment variables.
-inline Option<std::map<std::wstring, std::wstring>> getSystemEnvironment()
-{
-  std::map<std::wstring, std::wstring> systemEnvironment;
-  wchar_t* environmentEntry = nullptr;
-
-  // Get the system environment.
-  // The third parameter (bool) tells the function *not* to inherit
-  // variables from the current process.
-  if (!CreateEnvironmentBlock((LPVOID*)&environmentEntry, nullptr, FALSE)) {
-    return None();
-  }
-
-  // Save the environment block in order to destroy it later.
-  wchar_t* environmentBlock = environmentEntry;
-
-  while (*environmentEntry != L'\0') {
-    // Each environment block contains the environment variables as follows:
-    // Var1=Value1\0
-    // Var2=Value2\0
-    // Var3=Value3\0
-    // ...
-    // VarN=ValueN\0\0
-    // The name of an environment variable cannot include an equal sign (=).
-
-    // Construct a string from the pointer up to the first '\0',
-    // e.g. "Var1=Value1\0", then split into name and value.
-    std::wstring entryString(environmentEntry);
-    std::wstring::size_type separator = entryString.find(L"=");
-    std::wstring varName(entryString.substr(0, separator));
-    std::wstring varVal(entryString.substr(separator + 1));
-
-    // Mesos variables are upper case. Convert system variables to
-    // match the name provided by the scheduler in case of a collision.
-    // This is safe because Windows environment variables are case insensitive.
-    std::transform(varName.begin(), varName.end(), varName.begin(), ::towupper);
-
-    // The system environment has priority.
-    systemEnvironment.insert_or_assign(varName.data(), varVal.data());
-
-    // Advance the pointer the length of the entry string plus the '\0'.
-    environmentEntry += entryString.length() + 1;
-  }
-
-  DestroyEnvironmentBlock(environmentBlock);
-
-  return systemEnvironment;
-}
-
-
-// Creates a null-terminated array of null-terminated strings that will be
-// passed to `CreateProcessW` as the `lpEnvironment` argument, as described by
-// MSDN[1]. This array needs to be sorted in alphabetical order, but the `map`
-// already takes care of that. Note that this function explicitly handles
-// UTF-16 environments, so it must be used in conjunction with the
-// `CREATE_UNICODE_ENVIRONMENT` flag.
-//
-// NOTE: This function will add the system's environment variables into
-// the returned string. These variables take precedence over the provided
-// `env` and are generally necessary in order to launch things on Windows.
-//
-// [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx
-inline Option<std::wstring> createProcessEnvironment(
-    const Option<std::map<std::string, std::string>>& env)
-{
-  if (env.isNone() || (env.isSome() && env.get().size() == 0)) {
-    return None();
-  }
-
-  Option<std::map<std::wstring, std::wstring>> systemEnvironment =
-    getSystemEnvironment();
-
-  // The system environment must be non-empty.
-  // No subprocesses will be able to launch if the system environment is blank.
-  CHECK(systemEnvironment.isSome() && systemEnvironment.get().size() > 0);
-
-  std::map<std::wstring, std::wstring> combinedEnvironment;
-
-  // Populate the combined environment first with the given environment
-  // converted to UTF-16 for Windows.
-  std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter;
-  foreachpair (const std::string& key,
-               const std::string& value,
-               env.get()) {
-    combinedEnvironment[converter.from_bytes(key)] =
-      converter.from_bytes(value);
-  }
-
-  // Add the system environment variables, overwriting the previous.
-  foreachpair (const std::wstring& key,
-               const std::wstring& value,
-               systemEnvironment.get()) {
-    combinedEnvironment[key] = value;
-  }
-
-  std::wstring environmentString;
-  foreachpair (const std::wstring& key,
-               const std::wstring& value,
-               combinedEnvironment) {
-    environmentString += key + L'=' + value + L'\0';
-  }
-
-  // Append final null terminating character.
-  environmentString.push_back(L'\0');
-  return environmentString;
-}
-
-
 // NOTE: We are expecting that components of `argv` that need to be quoted
 // (for example, paths with spaces in them like `C:\"Program Files"\foo.exe`)
 // to have been already quoted correctly before we generate `command`.
 // Incorrectly-quoted command arguments will probably lead the child process
 // to terminate with an error. See also NOTE on `process::subprocess`.
-inline Try<PROCESS_INFORMATION> createChildProcess(
+inline Try<::internal::windows::ProcessData> createChildProcess(
     const std::string& path,
     const std::vector<std::string>& argv,
     const Option<std::map<std::string, std::string>>& environment,
+    const std::vector<Subprocess::ParentHook>& parent_hooks,
     const InputFileDescriptors stdinfds,
     const OutputFileDescriptors stdoutfds,
-    const OutputFileDescriptors stderrfds,
-    const std::vector<Subprocess::ParentHook>& parent_hooks)
+    const OutputFileDescriptors stderrfds)
 {
-  // The second argument to `::CreateProcessW` explicitly requries a writable
-  // buffer, so we copy the `wstring` data into this `vector`.
-  std::wstring command = os::stringify_args(argv);
-  std::vector<wchar_t> commandLine(command.begin(), command.end());
-
-  // Create the process suspended and with a Unicode environment.
-  DWORD creationFlags = CREATE_SUSPENDED | CREATE_UNICODE_ENVIRONMENT;
-
-  // Construct the environment that will be passed to `::CreateProcessW`.
-  Option<std::wstring> environmentString =
-    createProcessEnvironment(environment);
-
-  const wchar_t* processEnvironment = environmentString.isNone()
-    ? nullptr
-    : environmentString.get().data();
-
-  STARTUPINFOW startupInfo;
-  PROCESS_INFORMATION processInfo;
-
-  ::ZeroMemory(&startupInfo, sizeof(STARTUPINFOW));
-  ::ZeroMemory(&processInfo, sizeof(PROCESS_INFORMATION));
-
-  // Hook up the `stdin`/`stdout`/`stderr` pipes and use the
-  // `STARTF_USESTDHANDLES` flag to instruct the child to use them[1]. A more
-  // user-friendly example can be found in [2].
-  //
-  // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms686331(v=vs.85).aspx
-  // [2] https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499(v=vs.85).aspx
-  startupInfo.cb = sizeof(STARTUPINFOW);
-  startupInfo.hStdInput = stdinfds.read;
-  startupInfo.hStdOutput = stdoutfds.write;
-  startupInfo.hStdError = stderrfds.write;
-  startupInfo.dwFlags |= STARTF_USESTDHANDLES;
-
-  // TODO(hausdorff): Figure out how to map the `path` and `args` arguments of
-  // this function into a call to `::CreateProcess` that is more general
-  // purpose. In particular, on POSIX, we expect that calls to `subprocess` can
-  // be called with relative `path` (e.g., it could simply be `sh`). However,
-  // on Windows, unlike the calls to (e.g.) `exec`, `::CreateProcessW` will
-  // expect that this argument be a fully-qualified path. In the end, we'd like
-  // the calls to `subprocess` to have similar command formats to minimize
-  // confusion and mistakes.
-  //
-  // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms682425(v=vs.85).aspx
-  BOOL createProcessResult = ::CreateProcessW(
-      nullptr,
-      (LPWSTR)commandLine.data(),
-      nullptr,                 // Default security attributes.
-      nullptr,                 // Default primary thread security attributes.
-      TRUE,                    // Inherited parent process handles.
-      creationFlags,
-      (LPVOID)processEnvironment,
-      nullptr,                 // Use parent's current directory.
-      &startupInfo,            // STARTUPINFO pointer.
-      &processInfo);           // PROCESS_INFORMATION pointer.
-
-  if (!createProcessResult) {
-    return WindowsError(
-        "Failed to call CreateProcess on command '" + stringify(command) + "'");
+  Try<::internal::windows::ProcessData> process_data =
+    ::internal::windows::create_process(
+        path,
+        argv,
+        environment,
+        true, // Create suspended.
+        std::make_tuple(stdinfds.read, stdoutfds.write, stderrfds.write));
+
+  if (process_data.isError()) {
+    return process_data;
   }
 
   // Run the parent hooks.
-  const pid_t pid = processInfo.dwProcessId;
+  const pid_t pid = process_data.get().pid;
   foreach (const Subprocess::ParentHook& hook, parent_hooks) {
     Try<Nothing> parentSetup = hook.parent_setup(pid);
 
@@ -234,23 +77,23 @@ inline Try<PROCESS_INFORMATION> createChildProcess(
       // do not need to kill any descendents. We also can't use `os::kill_job`
       // because this process is not in a Job Object unless one of the parent
       // hooks added it.
-      ::TerminateProcess(processInfo.hProcess, 1);
+      ::TerminateProcess(process_data.get().process_handle.get_handle(), 1);
 
       return Error(
           "Failed to execute Parent Hook in child '" + stringify(pid) +
-          "' with command '" + stringify(command) + "': " +
+          "' with command '" + stringify(argv) + "': " +
           parentSetup.error());
     }
   }
 
   // Start child process.
-  if (::ResumeThread(processInfo.hThread) == -1) {
+  if (::ResumeThread(process_data.get().thread_handle.get_handle()) == -1) {
     return WindowsError(
         "Failed to resume child process with command '" +
-        stringify(command) + "'");
+        stringify(argv) + "'");
   }
 
-  return processInfo;
+  return process_data;
 }
 
 }  // namespace internal {

http://git-wip-us.apache.org/repos/asf/mesos/blob/4b28a28c/3rdparty/libprocess/src/subprocess.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/subprocess.cpp b/3rdparty/libprocess/src/subprocess.cpp
index 0f1532b..d0aa5f8 100644
--- a/3rdparty/libprocess/src/subprocess.cpp
+++ b/3rdparty/libprocess/src/subprocess.cpp
@@ -380,22 +380,23 @@ Try<Subprocess> subprocess(
     process.data->pid = pid.get();
 #else
     // TODO(joerg84): Consider using the childHooks and parentHooks here.
-    Try<PROCESS_INFORMATION> processInformation = internal::createChildProcess(
-        path,
-        argv,
-        environment,
-        stdinfds,
-        stdoutfds,
-        stderrfds,
-        parent_hooks);
-
-    if (processInformation.isError()) {
+    Try<::internal::windows::ProcessData> process_data =
+      internal::createChildProcess(
+          path,
+          argv,
+          environment,
+          parent_hooks,
+          stdinfds,
+          stdoutfds,
+          stderrfds);
+
+    if (process_data.isError()) {
       process::internal::close(stdinfds, stdoutfds, stderrfds);
       return Error(
-          "Could not launch child process: " + processInformation.error());
+          "Could not launch child process: " + process_data.error());
     }
 
-    if (processInformation.get().dwProcessId == -1) {
+    if (process_data.get().pid == -1) {
       // Save the errno as 'close' below might overwrite it.
       ErrnoError error("Failed to clone");
       process::internal::close(stdinfds, stdoutfds, stderrfds);
@@ -408,8 +409,8 @@ Try<Subprocess> subprocess(
     // 'createChildProcess' to be consistent with the posix path.
     internal::close({stdinfds.read, stdoutfds.write, stderrfds.write});
 
-    process.data->processInformation = processInformation.get();
-    process.data->pid = processInformation.get().dwProcessId;
+    process.data->process_data = process_data.get();
+    process.data->pid = process_data.get().pid;
 #endif // __WINDOWS__
   }
 


[02/50] mesos git commit: Windows: Switched from `gethostname` to `GetComputerName`.

Posted by jo...@apache.org.
Windows: Switched from `gethostname` to `GetComputerName`.

The former can inordinately slow on Windows (about 5 seconds),
whereas the latter is guaranteed to return instantly.

Because `os::internal::nodename()` and `net::hostname()` now
implement the exact same feature, we just reuse the first in
the second.

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


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

Branch: refs/heads/master
Commit: a4bfabfdc89a6d597127d3f4e17805911912c535
Parents: 0f6c212
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Tue Jun 27 13:45:37 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 15:55:09 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/net.hpp         | 24 -------------------
 3rdparty/stout/include/stout/posix/net.hpp   | 26 +++++++++++++++++++++
 3rdparty/stout/include/stout/windows/net.hpp | 10 +++++++-
 3rdparty/stout/include/stout/windows/os.hpp  | 28 ++++++++++++++---------
 4 files changed, 52 insertions(+), 36 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/a4bfabfd/3rdparty/stout/include/stout/net.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/net.hpp b/3rdparty/stout/include/stout/net.hpp
index 425544e..f9fbd51 100644
--- a/3rdparty/stout/include/stout/net.hpp
+++ b/3rdparty/stout/include/stout/net.hpp
@@ -206,30 +206,6 @@ inline struct addrinfo createAddrInfo(int socktype, int family, int flags)
 }
 
 
-inline Try<std::string> hostname()
-{
-  char host[512];
-
-  if (gethostname(host, sizeof(host)) < 0) {
-    return ErrnoError();
-  }
-
-  struct addrinfo hints = createAddrInfo(SOCK_STREAM, AF_UNSPEC, AI_CANONNAME);
-  struct addrinfo* result = nullptr;
-
-  int error = getaddrinfo(host, nullptr, &hints, &result);
-
-  if (error != 0) {
-    return Error(gai_strerror(error));
-  }
-
-  std::string hostname = result->ai_canonname;
-  freeaddrinfo(result);
-
-  return hostname;
-}
-
-
 // Returns a Try of the hostname for the provided IP. If the hostname
 // cannot be resolved, then a string version of the IP address is
 // returned.

http://git-wip-us.apache.org/repos/asf/mesos/blob/a4bfabfd/3rdparty/stout/include/stout/posix/net.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/posix/net.hpp b/3rdparty/stout/include/stout/posix/net.hpp
index 59463a0..841d9ca 100644
--- a/3rdparty/stout/include/stout/posix/net.hpp
+++ b/3rdparty/stout/include/stout/posix/net.hpp
@@ -45,6 +45,32 @@ inline Try<std::set<std::string>> links()
 }
 
 
+inline struct addrinfo createAddrInfo(int socktype, int family, int flags);
+
+inline Try<std::string> hostname()
+{
+  char host[512];
+
+  if (gethostname(host, sizeof(host)) < 0) {
+    return ErrnoError();
+  }
+
+  struct addrinfo hints = createAddrInfo(SOCK_STREAM, AF_UNSPEC, AI_CANONNAME);
+  struct addrinfo* result = nullptr;
+
+  int error = getaddrinfo(host, nullptr, &hints, &result);
+
+  if (error != 0) {
+    return Error(gai_strerror(error));
+  }
+
+  std::string hostname = result->ai_canonname;
+  freeaddrinfo(result);
+
+  return hostname;
+}
+
+
 // Returns a `Try` of the result of attempting to set the `hostname`.
 inline Try<Nothing> setHostname(const std::string& hostname)
 {

http://git-wip-us.apache.org/repos/asf/mesos/blob/a4bfabfd/3rdparty/stout/include/stout/windows/net.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/net.hpp b/3rdparty/stout/include/stout/windows/net.hpp
index 987ab70..6df4916 100644
--- a/3rdparty/stout/include/stout/windows/net.hpp
+++ b/3rdparty/stout/include/stout/windows/net.hpp
@@ -23,8 +23,10 @@
 #include <stout/error.hpp>
 #include <stout/foreach.hpp>
 #include <stout/nothing.hpp>
+#include <stout/stringify.hpp>
 #include <stout/try.hpp>
 #include <stout/windows.hpp>
+#include <stout/windows/os.hpp>
 
 
 namespace net {
@@ -64,10 +66,16 @@ inline Try<std::set<std::string>> links()
 }
 
 
+inline Try<std::string> hostname()
+{
+  return os::internal::nodename();
+}
+
+
 // Returns a `Try` of the result of attempting to set the `hostname`.
 inline Try<Nothing> setHostname(const std::string& hostname)
 {
-  if (SetComputerName(hostname.c_str()) == 0) {
+  if (::SetComputerNameW(wide_stringify(hostname).data()) == 0) {
     return WindowsError();
   }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/a4bfabfd/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/os.hpp b/3rdparty/stout/include/stout/windows/os.hpp
index f1722d5..397ea0a 100644
--- a/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/stout/include/stout/windows/os.hpp
@@ -70,23 +70,29 @@ inline Try<OSVERSIONINFOEX> os_version()
 
 inline Try<std::string> nodename()
 {
-  // Get DNS name of the local computer. First, find the size of the output
-  // buffer.
+  // MSDN documentation states "The names are established at system startup,
+  // when the system reads them from the registry." This is akin to the
+  // Linux `gethostname` which calls `uname`, thus avoiding a DNS lookup.
+  // The `net::getHostname` function can be used for an explicit DNS lookup.
+  //
+  // NOTE: This returns the hostname of the local computer, or the local
+  // node if this computer is part of a cluster.
+  COMPUTER_NAME_FORMAT format = ComputerNamePhysicalDnsHostname;
   DWORD size = 0;
-  if (!::GetComputerNameEx(ComputerNameDnsHostname, nullptr, &size) &&
-      ::GetLastError() != ERROR_MORE_DATA) {
-    return WindowsError(
-        "os::internal::nodename: Call to `GetComputerNameEx` failed");
+  if (::GetComputerNameExW(format, nullptr, &size) == 0) {
+    if (GetLastError() != ERROR_MORE_DATA) {
+      return WindowsError();
+    }
   }
 
-  std::unique_ptr<char[]> name(new char[size + 1]);
+  std::vector<wchar_t> buffer;
+  buffer.reserve(size);
 
-  if (!::GetComputerNameEx(ComputerNameDnsHostname, name.get(), &size)) {
-    return WindowsError(
-        "os::internal::nodename: Call to `GetComputerNameEx` failed");
+  if (::GetComputerNameExW(format, buffer.data(), &size) == 0) {
+    return WindowsError();
   }
 
-  return std::string(name.get());
+  return stringify(std::wstring(buffer.data()));
 }
 
 


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

Posted by jo...@apache.org.
Windows: Updated `os::mktemp()` to support long paths.

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


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

Branch: refs/heads/master
Commit: 41debf9714829749d812af63ee2c64cbe608a3e7
Parents: ffe2f2d
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 07:36:43 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:35 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/Makefile.am              |  2 +
 3rdparty/stout/include/stout/os/mktemp.hpp      | 49 ++----------
 .../stout/include/stout/os/posix/mktemp.hpp     | 61 +++++++++++++++
 .../stout/include/stout/os/windows/mktemp.hpp   | 79 ++++++++++++++++++++
 3rdparty/stout/include/stout/windows.hpp        | 34 ---------
 5 files changed, 147 insertions(+), 78 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/41debf97/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/Makefile.am b/3rdparty/stout/include/Makefile.am
index b0c28b2..4068f0e 100644
--- a/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/stout/include/Makefile.am
@@ -132,6 +132,7 @@ nobase_include_HEADERS =			\
   stout/os/posix/killtree.hpp			\
   stout/os/posix/mkdir.hpp			\
   stout/os/posix/mkdtemp.hpp			\
+  stout/os/posix/mktemp.hpp			\
   stout/os/posix/pagesize.hpp			\
   stout/os/posix/pipe.hpp			\
   stout/os/posix/read.hpp			\
@@ -167,6 +168,7 @@ nobase_include_HEADERS =			\
   stout/os/windows/kill.hpp			\
   stout/os/windows/killtree.hpp			\
   stout/os/windows/mkdir.hpp			\
+  stout/os/windows/mktemp.hpp			\
   stout/os/windows/mkdtemp.hpp			\
   stout/os/windows/pagesize.hpp			\
   stout/os/windows/pipe.hpp			\

http://git-wip-us.apache.org/repos/asf/mesos/blob/41debf97/3rdparty/stout/include/stout/os/mktemp.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/mktemp.hpp b/3rdparty/stout/include/stout/os/mktemp.hpp
index 55cf8b8..57cbf7a 100644
--- a/3rdparty/stout/include/stout/os/mktemp.hpp
+++ b/3rdparty/stout/include/stout/os/mktemp.hpp
@@ -13,53 +13,14 @@
 #ifndef __STOUT_OS_MKTEMP_HPP__
 #define __STOUT_OS_MKTEMP_HPP__
 
-#include <stdlib.h>
-#include <string.h>
-
-#include <string>
-
-#include <stout/error.hpp>
-#include <stout/path.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 `mkstemp`.
+#include <stout/os/windows/mktemp.hpp>
+#else
+#include <stout/os/posix/mktemp.hpp>
 #endif // __WINDOWS__
 
-#include <stout/os/close.hpp>
-#include <stout/os/int_fd.hpp>
-#include <stout/os/temp.hpp>
-
-
-namespace os {
-
-// Creates a temporary file using the specified path template. The
-// template may be any path with _6_ `Xs' appended to it, for example
-// /tmp/temp.XXXXXX. The trailing `Xs' are replaced with a unique
-// alphanumeric combination.
-inline Try<std::string> mktemp(
-    const std::string& path = path::join(os::temp(), "XXXXXX"))
-{
-  char* temp = new char[path.size() + 1];
-  ::memcpy(temp, path.c_str(), path.size() + 1);
-
-  int_fd fd = ::mkstemp(temp);
-  if (fd < 0) {
-    delete[] temp;
-    return ErrnoError();
-  }
-
-  // We ignore the return value of close(). This is because users
-  // calling this function are interested in the return value of
-  // mkstemp(). Also an unsuccessful close() doesn't affect the file.
-  os::close(fd);
-
-  std::string result(temp);
-  delete[] temp;
-  return result;
-}
-
-} // namespace os {
-
 
 #endif // __STOUT_OS_MKTEMP_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/41debf97/3rdparty/stout/include/stout/os/posix/mktemp.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/mktemp.hpp b/3rdparty/stout/include/stout/os/posix/mktemp.hpp
new file mode 100644
index 0000000..63b3d1a
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/posix/mktemp.hpp
@@ -0,0 +1,61 @@
+// 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_MKTEMP_HPP__
+#define __STOUT_OS_POSIX_MKTEMP_HPP__
+
+#include <stdlib.h>
+#include <string.h>
+
+#include <string>
+
+#include <stout/error.hpp>
+#include <stout/path.hpp>
+#include <stout/try.hpp>
+
+#include <stout/os/close.hpp>
+#include <stout/os/int_fd.hpp>
+#include <stout/os/temp.hpp>
+
+
+namespace os {
+
+// Creates a temporary file using the specified path template. The
+// template may be any path with _6_ `Xs' appended to it, for example
+// /tmp/temp.XXXXXX. The trailing `Xs' are replaced with a unique
+// alphanumeric combination.
+inline Try<std::string> mktemp(
+    const std::string& path = path::join(os::temp(), "XXXXXX"))
+{
+  char* temp = new char[path.size() + 1];
+  ::memcpy(temp, path.c_str(), path.size() + 1);
+
+  int_fd fd = ::mkstemp(temp);
+  if (fd < 0) {
+    delete[] temp;
+    return ErrnoError();
+  }
+
+  // We ignore the return value of close(). This is because users
+  // calling this function are interested in the return value of
+  // mkstemp(). Also an unsuccessful close() doesn't affect the file.
+  os::close(fd);
+
+  std::string result(temp);
+  delete[] temp;
+  return result;
+}
+
+} // namespace os {
+
+
+#endif // __STOUT_OS_POSIX_MKTEMP_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/41debf97/3rdparty/stout/include/stout/os/windows/mktemp.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/mktemp.hpp b/3rdparty/stout/include/stout/os/windows/mktemp.hpp
new file mode 100644
index 0000000..5c775c4
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/windows/mktemp.hpp
@@ -0,0 +1,79 @@
+// 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_MKTEMP_HPP__
+#define __STOUT_OS_WINDOWS_MKTEMP_HPP__
+
+#include <string>
+#include <vector>
+
+#include <stout/error.hpp>
+#include <stout/path.hpp>
+#include <stout/stringify.hpp>
+#include <stout/try.hpp>
+#include <stout/windows.hpp>
+
+#include <stout/os/close.hpp>
+#include <stout/os/int_fd.hpp>
+#include <stout/os/open.hpp>
+#include <stout/os/temp.hpp>
+
+#include <stout/internal/windows/longpath.hpp>
+
+
+namespace os {
+
+// Creates a temporary file using the specified path template. The
+// template may be any path with _6_ `Xs' appended to it, for example
+// /tmp/temp.XXXXXX. The trailing `Xs' are replaced with a unique
+// alphanumeric combination.
+inline Try<std::string> mktemp(
+    const std::string& path = path::join(os::temp(), "XXXXXX"))
+{
+  const std::wstring longpath = ::internal::windows::longpath(path);
+  std::vector<wchar_t> buffer(longpath.begin(), longpath.end());
+
+  // The range does not include the null terminator, needed to reconstruct
+  // the next string.
+  buffer.push_back(L'\0');
+
+  // NOTE: in the POSIX spec, `mkstemp` will generate a random filename from
+  // the `path` template, `open` that filename, and return the resulting file
+  // descriptor. On Windows, `_mktemp_s` will actually only generate the path,
+  // so here we actually have to call `open` ourselves to get a file descriptor
+  // we can return as a result.
+  if (::_wmktemp_s(buffer.data(), buffer.size()) != 0) {
+    return WindowsError();
+  }
+
+  const std::string temp_file = stringify(std::wstring(buffer.data()));
+
+  // NOTE: We open the file with read/write access for the given user, an
+  // attempt to match POSIX's specification of `mkstemp`. We use `_S_IREAD` and
+  // `_S_IWRITE` here instead of the POSIX equivalents. On Windows the file is
+  // is not present, we use `_O_CREAT` option when opening the file.
+  Try<int_fd> fd = os::open(temp_file, _O_CREAT, _S_IREAD | _S_IWRITE);
+  if (fd.isError()) {
+    return Error(fd.error());
+  }
+
+  // We ignore the return value of close(). This is because users
+  // calling this function are interested in the return value of
+  // mkstemp(). Also an unsuccessful close() doesn't affect the file.
+  os::close(fd.get());
+
+  return strings::remove(temp_file, os::LONGPATH_PREFIX, strings::Mode::PREFIX);
+}
+
+} // namespace os {
+
+#endif // __STOUT_OS_WINDOWS_MKTEMP_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/41debf97/3rdparty/stout/include/stout/windows.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows.hpp b/3rdparty/stout/include/stout/windows.hpp
index 34273dc..6f5b323 100644
--- a/3rdparty/stout/include/stout/windows.hpp
+++ b/3rdparty/stout/include/stout/windows.hpp
@@ -338,40 +338,6 @@ decltype(strerror_s(buffer, length, errnum))
 }
 
 
-// File I/O function aliases.
-//
-// NOTE: The use of `auto` and the trailing return type in the following
-// functions are meant to make it easier for Linux developers to use and
-// maintain the code. It is an explicit marker that we are using the compiler
-// to guarantee that the return type is identical to whatever is in the Windows
-// implementation of the standard.
-inline auto mktemp(char* path) ->
-decltype(_mktemp(path))
-{
-  return _mktemp(path);
-}
-
-
-inline auto mkstemp(char* path) ->
-decltype(_mktemp_s(path, strlen(path) + 1))
-{
-  // NOTE: in the POSIX spec, `mkstemp` will generate a random filename from
-  // the `path` template, `open` that filename, and return the resulting file
-  // descriptor. On Windows, `_mktemp_s` will actually only generate the path,
-  // so here we actually have to call `open` ourselves to get a file descriptor
-  // we can return as a result.
-  if (_mktemp_s(path, strlen(path) + 1) != 0) {
-    return -1;
-  }
-
-  // NOTE: We open the file with read / write access for the given user, an
-  // attempt to match POSIX's specification of `mkstemp`. We use `_S_IREAD` and
-  // `_S_IWRITE` here instead of the POSIX equivalents. On Windows the file is
-  // is not present, we use `_O_CREAT` option when opening the file.
-  return _open(path, _O_CREAT, _S_IREAD | _S_IWRITE);
-}
-
-
 // NOTE: Signals do not exist on Windows, so all signals are unknown.
 // If the signal number is unknown, the Posix specification leaves the
 // return value of `strsignal` unspecified.


[40/50] mesos git commit: Windows: Made `WindowsError` use Unicode.

Posted by jo...@apache.org.
Windows: Made `WindowsError` use Unicode.

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


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

Branch: refs/heads/master
Commit: 52adff160f8c28e4aa1133561bc690f58e0d850c
Parents: bb52f6c
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 14:52:03 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:38 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/windows/error.hpp | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/52adff16/3rdparty/stout/include/stout/windows/error.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/error.hpp b/3rdparty/stout/include/stout/windows/error.hpp
index 2f2cbd4..0bec474 100644
--- a/3rdparty/stout/include/stout/windows/error.hpp
+++ b/3rdparty/stout/include/stout/windows/error.hpp
@@ -19,6 +19,7 @@
 
 #include <stout/error.hpp>
 #include <stout/windows.hpp>
+#include <stout/stringify.hpp>
 
 
 // A useful type that can be used to represent a Try that has failed. This is a
@@ -58,20 +59,20 @@ private:
     // `message_buffer`, and then dumps said pretty-printed error message at
     // that address, in our `default_language`.
     //
-    // The 5th actual parameter (namely `(LPSTR)&message_buffer`), may look
+    // The 5th actual parameter (namely `(LPWSTR)&message_buffer`), may look
     // strange to readers of this code. It is copied directly out of the
     // documentation[1], and is unfortunately required to get the
     // pretty-printed error message. The short story is:
     //
     //   * The flag `FORMAT_MESSAGE_ALLOCATE_BUFFER` tells `FormatMessage` to
-    //     point `message_buffer` (which is an `LPSTR` a.k.a. `char*`) at a
+    //     point `message_buffer` (which is an `LPWSTR` a.k.a. `char*`) at a
     //     string error message. But, `message_buffer` to point a `char*` at a
     //     different place, `FormatMessage` would need the address
     //     `&message_buffer` so that it could change where it is pointing.
     //   * So, to solve this problem, the API writers decided that when you
     //     pass that flag in, `FormatMessage` will treat the 5th parameter not
-    //     as `LPSTR` (which is what the type is in the function signagure),
-    //     but as `LPSTR*` a.k.a. `char**`, which (assuming you've casted the
+    //     as `LPWSTR` (which is what the type is in the function signagure),
+    //     but as `LPWSTR*` a.k.a. `char**`, which (assuming you've casted the
     //     parameter correctly) allows it to allocate the message on your
     //     behalf, and change `message_buffer` to point at this new error
     //     string.
@@ -82,22 +83,22 @@ private:
     // the documentation as well.
     //
     // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/ms679351(v=vs.85).aspx
-    LPSTR message_buffer;
-    size_t size = FormatMessage(
+    wchar_t *message_buffer = nullptr;
+    size_t size = ::FormatMessageW(
         allocate_message_buffer,
         nullptr,                 // Ignored.
         errorCode,
         default_language,
-        (LPSTR) &message_buffer, // See comment above about quirky cast.
+        (LPWSTR)&message_buffer, // See comment above about quirky cast.
         0,                       // Ignored.
         nullptr);                // Ignored.
 
-    std::string message(message_buffer, size);
+    std::wstring message(message_buffer, size);
 
     // Required per documentation above.
-    LocalFree(message_buffer);
+    ::LocalFree(message_buffer);
 
-    return message;
+    return stringify(message);
   }
 };
 


[11/50] mesos git commit: Windows: Replaced use of `_stat()` in `reparsepoint.hpp`.

Posted by jo...@apache.org.
Windows: Replaced use of `_stat()` in `reparsepoint.hpp`.

This reworks some code which did not support long paths.

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


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

Branch: refs/heads/master
Commit: 06162f6a29f7d056cc6343151c5eb3b8f7128e38
Parents: 7fdd28d
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Fri Jul 7 14:06:41 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:33 2017 -0700

----------------------------------------------------------------------
 .../stout/internal/windows/reparsepoint.hpp     | 24 ++++++++++++--------
 1 file changed, 14 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/06162f6a/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp b/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
index dcadfed..066c192 100644
--- a/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
+++ b/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
@@ -179,14 +179,15 @@ inline Try<SymbolicLink> build_symbolic_link(const REPARSE_DATA_BUFFER& data)
 // refer to the symlink rather than the file or folder the symlink points at.
 inline Try<SharedHandle> get_handle_no_follow(const std::string& absolute_path)
 {
-  struct _stat absolute_path_stat;
-  bool resolved_path_is_directory = false;
-  if (::_stat(absolute_path.c_str(), &absolute_path_stat) == 0) {
-    resolved_path_is_directory = S_ISDIR(absolute_path_stat.st_mode);
-  } else {
-    return ErrnoError("'_stat' failed on path '" + absolute_path + "'");
+  const Try<DWORD> attributes = ::internal::windows::get_file_attributes(
+      wide_stringify(absolute_path));
+
+  if (attributes.isError()) {
+    return Error(attributes.error());
   }
 
+  bool resolved_path_is_directory = attributes.get() & FILE_ATTRIBUTE_DIRECTORY;
+
   // NOTE: According to the `CreateFile` documentation[1], the `OPEN_EXISTING`
   // and `FILE_FLAG_OPEN_REPARSE_POINT` flags need to be used when getting a
   // handle for the symlink.
@@ -319,16 +320,19 @@ inline Try<Nothing> create_symbolic_link(
 
   // Determine if target is a folder or a file. This makes a difference
   // in the way we call `create_symbolic_link`.
-  struct _stat absolute_target_path_stat;
-  if (::_stat(absolute_target_path.c_str(), &absolute_target_path_stat) != 0) {
-    return ErrnoError("'_stat' failed on path '" + absolute_target_path + "'");
+  const Try<DWORD> attributes = ::internal::windows::get_file_attributes(
+      wide_stringify(absolute_target_path));
+
+  if (attributes.isError()) {
+    return Error(attributes.error());
   }
 
-  const bool target_is_folder = S_ISDIR(absolute_target_path_stat.st_mode);
+  const bool target_is_folder = attributes.get() & FILE_ATTRIBUTE_DIRECTORY;
 
   // Bail out if target is already a reparse point.
   Try<bool> attribute_set = reparse_point_attribute_set(
       longpath(absolute_target_path));
+
   if (!attribute_set.isSome()) {
     return Error(
         "Could not get reparse point attribute for '" + absolute_target_path +


[38/50] mesos git commit: Windows: Made `net.hpp` use Unicode.

Posted by jo...@apache.org.
Windows: Made `net.hpp` use Unicode.

This commit moves most of the shared `os::net` code into similar but
separate POSIX and Windows implementations, where the latter use the
explicit wide/Unicode Windows APIs.

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


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

Branch: refs/heads/master
Commit: 498c530269f8574937cd33658c92102e7a9b05af
Parents: 52adff1
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 14:56:52 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:38 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/net.hpp         | 106 --------------------
 3rdparty/stout/include/stout/posix/net.hpp   | 108 ++++++++++++++++++++-
 3rdparty/stout/include/stout/windows/net.hpp | 113 ++++++++++++++++++++++
 3 files changed, 219 insertions(+), 108 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/498c5302/3rdparty/stout/include/stout/net.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/net.hpp b/3rdparty/stout/include/stout/net.hpp
index f9fbd51..7b6557d 100644
--- a/3rdparty/stout/include/stout/net.hpp
+++ b/3rdparty/stout/include/stout/net.hpp
@@ -193,112 +193,6 @@ inline Try<int> download(const std::string& url, const std::string& path)
   return Try<int>::some(code);
 }
 
-
-inline struct addrinfo createAddrInfo(int socktype, int family, int flags)
-{
-  struct addrinfo addr;
-  memset(&addr, 0, sizeof(addr));
-  addr.ai_socktype = socktype;
-  addr.ai_family = family;
-  addr.ai_flags |= flags;
-
-  return addr;
-}
-
-
-// Returns a Try of the hostname for the provided IP. If the hostname
-// cannot be resolved, then a string version of the IP address is
-// returned.
-//
-// TODO(benh): Merge with `net::hostname`.
-inline Try<std::string> getHostname(const IP& ip)
-{
-  struct sockaddr_storage storage;
-  memset(&storage, 0, sizeof(storage));
-
-  switch (ip.family()) {
-    case AF_INET: {
-      struct sockaddr_in addr;
-      memset(&addr, 0, sizeof(addr));
-      addr.sin_family = AF_INET;
-      addr.sin_addr = ip.in().get();
-      addr.sin_port = 0;
-
-      memcpy(&storage, &addr, sizeof(addr));
-      break;
-    }
-    case AF_INET6: {
-      struct sockaddr_in6 addr;
-      memset(&addr, 0, sizeof(addr));
-      addr.sin6_family = AF_INET6;
-      addr.sin6_addr = ip.in6().get();
-      addr.sin6_port = 0;
-
-      memcpy(&storage, &addr, sizeof(addr));
-      break;
-    }
-    default: {
-      ABORT("Unsupported family type: " + stringify(ip.family()));
-    }
-  }
-
-  char hostname[MAXHOSTNAMELEN];
-  socklen_t length;
-
-  if (ip.family() == AF_INET) {
-    length = sizeof(struct sockaddr_in);
-  } else if (ip.family() == AF_INET6) {
-    length = sizeof(struct sockaddr_in6);
-  } else {
-    return Error("Unknown address family: " + stringify(ip.family()));
-  }
-
-  int error = getnameinfo(
-      (struct sockaddr*) &storage,
-      length,
-      hostname,
-      MAXHOSTNAMELEN,
-      nullptr,
-      0,
-      0);
-
-  if (error != 0) {
-    return Error(std::string(gai_strerror(error)));
-  }
-
-  return std::string(hostname);
-}
-
-
-// Returns a Try of the IP for the provided hostname or an error if no IP is
-// obtained.
-inline Try<IP> getIP(const std::string& hostname, int family = AF_UNSPEC)
-{
-  struct addrinfo hints = createAddrInfo(SOCK_STREAM, family, 0);
-  struct addrinfo* result = nullptr;
-
-  int error = getaddrinfo(hostname.c_str(), nullptr, &hints, &result);
-
-  if (error != 0) {
-    return Error(gai_strerror(error));
-  }
-
-  if (result->ai_addr == nullptr) {
-    freeaddrinfo(result);
-    return Error("No addresses found");
-  }
-
-  Try<IP> ip = IP::create(*result->ai_addr);
-
-  if (ip.isError()) {
-    freeaddrinfo(result);
-    return Error("Unsupported family type");
-  }
-
-  freeaddrinfo(result);
-  return ip.get();
-}
-
 } // namespace net {
 
 #endif // __STOUT_NET_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/498c5302/3rdparty/stout/include/stout/posix/net.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/posix/net.hpp b/3rdparty/stout/include/stout/posix/net.hpp
index 841d9ca..b8ea601 100644
--- a/3rdparty/stout/include/stout/posix/net.hpp
+++ b/3rdparty/stout/include/stout/posix/net.hpp
@@ -25,6 +25,112 @@
 
 namespace net {
 
+inline struct addrinfo createAddrInfo(int socktype, int family, int flags)
+{
+  struct addrinfo addr;
+  memset(&addr, 0, sizeof(addr));
+  addr.ai_socktype = socktype;
+  addr.ai_family = family;
+  addr.ai_flags |= flags;
+
+  return addr;
+}
+
+
+// Returns a Try of the hostname for the provided IP. If the hostname
+// cannot be resolved, then a string version of the IP address is
+// returned.
+//
+// TODO(benh): Merge with `net::hostname`.
+inline Try<std::string> getHostname(const IP& ip)
+{
+  struct sockaddr_storage storage;
+  memset(&storage, 0, sizeof(storage));
+
+  switch (ip.family()) {
+    case AF_INET: {
+      struct sockaddr_in addr;
+      memset(&addr, 0, sizeof(addr));
+      addr.sin_family = AF_INET;
+      addr.sin_addr = ip.in().get();
+      addr.sin_port = 0;
+
+      memcpy(&storage, &addr, sizeof(addr));
+      break;
+    }
+    case AF_INET6: {
+      struct sockaddr_in6 addr;
+      memset(&addr, 0, sizeof(addr));
+      addr.sin6_family = AF_INET6;
+      addr.sin6_addr = ip.in6().get();
+      addr.sin6_port = 0;
+
+      memcpy(&storage, &addr, sizeof(addr));
+      break;
+    }
+    default: {
+      ABORT("Unsupported family type: " + stringify(ip.family()));
+    }
+  }
+
+  char hostname[MAXHOSTNAMELEN];
+  socklen_t length;
+
+  if (ip.family() == AF_INET) {
+    length = sizeof(struct sockaddr_in);
+  } else if (ip.family() == AF_INET6) {
+    length = sizeof(struct sockaddr_in6);
+  } else {
+    return Error("Unknown address family: " + stringify(ip.family()));
+  }
+
+  int error = getnameinfo(
+      (struct sockaddr*) &storage,
+      length,
+      hostname,
+      MAXHOSTNAMELEN,
+      nullptr,
+      0,
+      0);
+
+  if (error != 0) {
+    return Error(std::string(gai_strerror(error)));
+  }
+
+  return std::string(hostname);
+}
+
+
+// Returns a Try of the IP for the provided hostname or an error if no IP is
+// obtained.
+inline Try<IP> getIP(const std::string& hostname, int family = AF_UNSPEC)
+{
+  struct addrinfo hints = createAddrInfo(SOCK_STREAM, family, 0);
+  struct addrinfo* result = nullptr;
+
+  int error = getaddrinfo(hostname.c_str(), nullptr, &hints, &result);
+
+  if (error != 0) {
+    return Error(gai_strerror(error));
+  }
+
+  if (result->ai_addr == nullptr) {
+    freeaddrinfo(result);
+    return Error("No addresses found");
+  }
+
+  Try<IP> ip = IP::create(*result->ai_addr);
+
+  if (ip.isError()) {
+    freeaddrinfo(result);
+    return Error("Unsupported family type");
+  }
+
+  freeaddrinfo(result);
+  return ip.get();
+}
+
+
 // Returns the names of all the link devices in the system.
 inline Try<std::set<std::string>> links()
 {
@@ -45,8 +151,6 @@ inline Try<std::set<std::string>> links()
 }
 
 
-inline struct addrinfo createAddrInfo(int socktype, int family, int flags);
-
 inline Try<std::string> hostname()
 {
   char host[512];

http://git-wip-us.apache.org/repos/asf/mesos/blob/498c5302/3rdparty/stout/include/stout/windows/net.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/net.hpp b/3rdparty/stout/include/stout/windows/net.hpp
index 6df4916..1418b5c 100644
--- a/3rdparty/stout/include/stout/windows/net.hpp
+++ b/3rdparty/stout/include/stout/windows/net.hpp
@@ -31,6 +31,119 @@
 
 namespace net {
 
+inline struct addrinfoW createAddrInfo(int socktype, int family, int flags)
+{
+  struct addrinfoW addr;
+  memset(&addr, 0, sizeof(addr));
+  addr.ai_socktype = socktype;
+  addr.ai_family = family;
+  addr.ai_flags |= flags;
+
+  return addr;
+}
+
+
+inline Error GaiError(int error)
+{
+  return Error(stringify(std::wstring(gai_strerrorW(error))));
+}
+
+
+// Returns a Try of the hostname for the provided IP. If the hostname
+// cannot be resolved, then a string version of the IP address is
+// returned.
+//
+// TODO(benh): Merge with `net::hostname`.
+inline Try<std::string> getHostname(const IP& ip)
+{
+  struct sockaddr_storage storage;
+  memset(&storage, 0, sizeof(storage));
+
+  switch (ip.family()) {
+    case AF_INET: {
+      struct sockaddr_in addr;
+      memset(&addr, 0, sizeof(addr));
+      addr.sin_family = AF_INET;
+      addr.sin_addr = ip.in().get();
+      addr.sin_port = 0;
+
+      memcpy(&storage, &addr, sizeof(addr));
+      break;
+    }
+    case AF_INET6: {
+      struct sockaddr_in6 addr;
+      memset(&addr, 0, sizeof(addr));
+      addr.sin6_family = AF_INET6;
+      addr.sin6_addr = ip.in6().get();
+      addr.sin6_port = 0;
+
+      memcpy(&storage, &addr, sizeof(addr));
+      break;
+    }
+    default: {
+      ABORT("Unsupported family type: " + stringify(ip.family()));
+    }
+  }
+
+  wchar_t hostname[MAXHOSTNAMELEN];
+  socklen_t length;
+
+  if (ip.family() == AF_INET) {
+    length = sizeof(struct sockaddr_in);
+  } else if (ip.family() == AF_INET6) {
+    length = sizeof(struct sockaddr_in6);
+  } else {
+    return Error("Unknown address family: " + stringify(ip.family()));
+  }
+
+  int error = GetNameInfoW(
+      (struct sockaddr*) &storage,
+      length,
+      hostname,
+      MAXHOSTNAMELEN,
+      nullptr,
+      0,
+      0);
+
+  if (error != 0) {
+    return GaiError(error);
+  }
+
+  return stringify(std::wstring(hostname));
+}
+
+
+// Returns a Try of the IP for the provided hostname or an error if no IP is
+// obtained.
+inline Try<IP> getIP(const std::string& hostname, int family = AF_UNSPEC)
+{
+  struct addrinfoW hints = createAddrInfo(SOCK_STREAM, family, 0);
+  struct addrinfoW* result = nullptr;
+
+  int error =
+      GetAddrInfoW(wide_stringify(hostname).data(), nullptr, &hints, &result);
+
+  if (error != 0) {
+    return GaiError(error);
+  }
+
+  if (result->ai_addr == nullptr) {
+    FreeAddrInfoW(result);
+    return Error("No addresses found");
+  }
+
+  Try<IP> ip = IP::create(*result->ai_addr);
+
+  if (ip.isError()) {
+    FreeAddrInfoW(result);
+    return Error("Unsupported family type");
+  }
+
+  FreeAddrInfoW(result);
+  return ip.get();
+}
+
+
 // Returns the names of all the link devices in the system.
 //
 // NOTE: On Windows, the device names are GUID's which are not easily


[29/50] mesos git commit: Windows: Implemented `WSTRINGIFY()` to print exit codes.

Posted by jo...@apache.org.
Windows: Implemented `WSTRINGIFY()` to print exit codes.

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


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

Branch: refs/heads/master
Commit: d7eee2dff8cb83aa231fe4b564f075ab12fbcc71
Parents: 6d782b1
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 10:56:53 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:36 2017 -0700

----------------------------------------------------------------------
 src/common/status_utils.hpp | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d7eee2df/src/common/status_utils.hpp
----------------------------------------------------------------------
diff --git a/src/common/status_utils.hpp b/src/common/status_utils.hpp
index 36df84d..be0734d 100644
--- a/src/common/status_utils.hpp
+++ b/src/common/status_utils.hpp
@@ -31,15 +31,13 @@ inline bool WSUCCEEDED(int status)
 
 inline std::string WSTRINGIFY(int status)
 {
+  std::string message;
 #ifdef __WINDOWS__
-  // On Windows the exit codes are not standardized. The behaviour should
-  // be defined to improve the diagnostic based on logs.
-  // TODO(dpravat): MESOS-5417 tracks this improvement.
-  LOG(WARNING) << "`WSTRINGIFY` has been called, but it is not implemented.";
-
-  return "";
+  // NOTE: On Windows, exit codes are not standardized, so we cannot
+  // treat any exit codes differently.
+  message += "exited with status ";
+  message += stringify(status);
 #else
-  std::string message;
   if (WIFEXITED(status)) {
     message += "exited with status ";
     message += stringify(WEXITSTATUS(status));
@@ -56,8 +54,8 @@ inline std::string WSTRINGIFY(int status)
     message += "wait status ";
     message += stringify(status);
   }
-  return message;
 #endif // __WINDOWS__
+  return message;
 }
 
 #endif // __STATUS_UTILS_HPP__


[44/50] mesos git commit: Windows: Updated job object name types to `wstring`.

Posted by jo...@apache.org.
Windows: Updated job object name types to `wstring`.

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


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

Branch: refs/heads/master
Commit: fd40752f2a3fb860e0964491c6d7f8330825e68a
Parents: dc81df5
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 15:37:49 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:39 2017 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/include/process/windows/jobobject.hpp | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/fd40752f/3rdparty/libprocess/include/process/windows/jobobject.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/include/process/windows/jobobject.hpp b/3rdparty/libprocess/include/process/windows/jobobject.hpp
index 5fb41c4..0de374d 100644
--- a/3rdparty/libprocess/include/process/windows/jobobject.hpp
+++ b/3rdparty/libprocess/include/process/windows/jobobject.hpp
@@ -41,7 +41,7 @@ public:
 
   void manage(
       const pid_t pid,
-      const std::string& name,
+      const std::wstring& name,
       const SharedHandle& handle)
   {
     jobs.emplace(pid, JobData{name, handle});
@@ -68,7 +68,7 @@ protected:
 
 private:
   struct JobData {
-    std::string name;
+    std::wstring name;
     SharedHandle handle;
   };
 
@@ -91,7 +91,7 @@ inline Subprocess::ParentHook Subprocess::ParentHook::CREATE_JOB() {
     // object is greater than the lifetime of the processes it contains. Thus
     // the job object handle is explicitly owned by the global job object
     // manager process.
-    Try<std::string> name = os::name_job(pid);
+    Try<std::wstring> name = os::name_job(pid);
     if (name.isError()) {
       return Error(name.error());
     }


[09/50] mesos git commit: Windows: Added long path test.

Posted by jo...@apache.org.
Windows: Added long path test.

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


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

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

----------------------------------------------------------------------
 3rdparty/stout/tests/os/filesystem_tests.cpp | 29 +++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/cabb6476/3rdparty/stout/tests/os/filesystem_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/os/filesystem_tests.cpp b/3rdparty/stout/tests/os/filesystem_tests.cpp
index ee5a1a1..f385d35 100644
--- a/3rdparty/stout/tests/os/filesystem_tests.cpp
+++ b/3rdparty/stout/tests/os/filesystem_tests.cpp
@@ -22,6 +22,7 @@
 #include <stout/try.hpp>
 #include <stout/uuid.hpp>
 
+#include <stout/os/access.hpp>
 #include <stout/os/find.hpp>
 #include <stout/os/getcwd.hpp>
 #include <stout/os/int_fd.hpp>
@@ -179,6 +180,30 @@ TEST_F(FsTest, Touch)
 }
 
 
+#ifdef __WINDOWS__
+// This test attempts to perform some basic file operations on a file
+// with an absolute path longer than the `MAX_PATH`.
+TEST_F(FsTest, LongPath)
+{
+  string testdir = os::getcwd();
+  while (testdir.length() <= MAX_PATH)
+  {
+    testdir = path::join(testdir, UUID::random().toString());
+  }
+  ASSERT_TRUE(testdir.length() > MAX_PATH);
+
+  ASSERT_SOME(os::mkdir(testdir));
+
+  const string testfile = path::join(testdir, "file.txt");
+
+  ASSERT_SOME(os::touch(testfile));
+  EXPECT_TRUE(os::exists(testfile));
+  EXPECT_SOME_TRUE(os::access(testfile, R_OK | W_OK));
+  EXPECT_SOME_EQ(testfile, os::realpath(testfile));
+}
+#endif // __WINDOWS__
+
+
 TEST_F(FsTest, SYMLINK_Symlink)
 {
   const string temp_path = os::getcwd();
@@ -387,8 +412,8 @@ TEST_F(FsTest, Close)
 #ifdef __WINDOWS__
   // Open a file with the traditional Windows `HANDLE` API, then verify that
   // writing to that `HANDLE` succeeds before we close it, and fails after.
-  const HANDLE open_valid_handle = CreateFile(
-      testfile.c_str(),
+  const HANDLE open_valid_handle = CreateFileW(
+      wide_stringify(testfile).data(),
       FILE_APPEND_DATA,
       0,                     // No sharing mode.
       nullptr,               // Default security.


[16/50] mesos git commit: Windows: Refactored `reparse_point_attribute_set()`.

Posted by jo...@apache.org.
Windows: Refactored `reparse_point_attribute_set()`.

It now takes a `std::wstring` and uses `get_file_attributes()`.

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


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

Branch: refs/heads/master
Commit: 28fd210467b64df8797343ae9d2b397c5c1dc0a2
Parents: 0cbc033
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Wed Jul 5 16:53:24 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:33 2017 -0700

----------------------------------------------------------------------
 .../stout/internal/windows/reparsepoint.hpp     | 21 +++++++++++---------
 .../include/stout/internal/windows/symlink.hpp  |  5 +++--
 2 files changed, 15 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/28fd2104/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp b/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
index a922843..61c4084 100644
--- a/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
+++ b/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
@@ -24,6 +24,9 @@
 #include <stout/os/mkdir.hpp>
 #include <stout/os/realpath.hpp>
 
+#include <stout/internal/windows/attributes.hpp>
+#include <stout/internal/windows/longpath.hpp>
+
 // We pass this struct to `DeviceIoControl` to get information about a reparse
 // point (including things like whether it's a symlink). It is normally part of
 // the Device Driver Kit (DDK), specifically `nitfs.h`, but rather than taking
@@ -112,15 +115,14 @@ struct SymbolicLink
 // Checks file/folder attributes for a path to see if the reparse point
 // attribute is set; this indicates whether the path points at a reparse point,
 // rather than a "normal" file or folder.
-inline Try<bool> reparse_point_attribute_set(const std::string& absolute_path)
+inline Try<bool> reparse_point_attribute_set(const std::wstring& absolute_path)
 {
-  const DWORD attributes = ::GetFileAttributes(absolute_path.c_str());
-  if (attributes == INVALID_FILE_ATTRIBUTES) {
-    return WindowsError(
-        "Failed to get attributes for file '" + absolute_path + "'");
+  const Try<DWORD> attributes = get_file_attributes(absolute_path.data());
+  if (attributes.isError()) {
+    return Error(attributes.error());
   }
 
-  return (attributes & FILE_ATTRIBUTE_REPARSE_POINT) != 0;
+  return (attributes.get() & FILE_ATTRIBUTE_REPARSE_POINT) != 0;
 }
 
 
@@ -192,8 +194,8 @@ inline Try<SharedHandle> get_handle_no_follow(const std::string& absolute_path)
     ? (FILE_FLAG_OPEN_REPARSE_POINT | FILE_FLAG_BACKUP_SEMANTICS)
     : FILE_FLAG_OPEN_REPARSE_POINT;
 
-  const HANDLE handle = ::CreateFile(
-      absolute_path.c_str(),
+  const HANDLE handle = ::CreateFileW(
+      longpath(absolute_path).data(),
       GENERIC_READ,     // Open the file for reading only.
       FILE_SHARE_READ,  // Just reading this file, allow others to do the same.
       nullptr,          // Ignored.
@@ -307,7 +309,8 @@ inline Try<Nothing> create_symbolic_link(
   const bool target_is_folder = S_ISDIR(absolute_target_path_stat.st_mode);
 
   // Bail out if target is already a reparse point.
-  Try<bool> attribute_set = reparse_point_attribute_set(absolute_target_path);
+  Try<bool> attribute_set = reparse_point_attribute_set(
+      longpath(absolute_target_path));
   if (!attribute_set.isSome()) {
     return Error(
         "Could not get reparse point attribute for '" + absolute_target_path +

http://git-wip-us.apache.org/repos/asf/mesos/blob/28fd2104/3rdparty/stout/include/stout/internal/windows/symlink.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/internal/windows/symlink.hpp b/3rdparty/stout/include/stout/internal/windows/symlink.hpp
index 5dc022b..b9cf122 100644
--- a/3rdparty/stout/include/stout/internal/windows/symlink.hpp
+++ b/3rdparty/stout/include/stout/internal/windows/symlink.hpp
@@ -18,6 +18,7 @@
 #include <stout/try.hpp>
 #include <stout/windows.hpp>
 
+#include <stout/internal/windows/longpath.hpp>
 #include <stout/internal/windows/reparsepoint.hpp>
 
 #include <stout/os/realpath.hpp>
@@ -59,8 +60,8 @@ inline Try<SymbolicLink> query_symbolic_link_data(const std::string& path)
   // Windows has no built-in way to tell whether a path points at a symbolic
   // link; but, we know that symbolic links are implemented with reparse
   // points, so we begin by checking that.
-  Try<bool> is_reparse_point =
-    reparse_point_attribute_set(absolute_path.get());
+  Try<bool> is_reparse_point = reparse_point_attribute_set(
+      ::internal::windows::longpath(absolute_path.get()));
 
   if (is_reparse_point.isError()) {
     return Error(is_reparse_point.error());


[47/50] mesos git commit: Windows: Required building with `_UNICODE` and `UNICODE`.

Posted by jo...@apache.org.
Windows: Required building with `_UNICODE` and `UNICODE`.

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


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

Branch: refs/heads/master
Commit: 33734527c0acd7c577292dfc785f5a48e058acb2
Parents: fcbb67c
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 15:51:25 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:39 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/windows.hpp | 32 +++++++++++++++++++--------
 1 file changed, 23 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/33734527/3rdparty/stout/include/stout/windows.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows.hpp b/3rdparty/stout/include/stout/windows.hpp
index 6f5b323..92db727 100644
--- a/3rdparty/stout/include/stout/windows.hpp
+++ b/3rdparty/stout/include/stout/windows.hpp
@@ -36,19 +36,33 @@
 #include <glog/logging.h>
 
 
-#ifdef _UNICODE
-// Much of the core Windows API is available both in `string` and `wstring`
+#if !defined(_UNICODE) || !defined(UNICODE)
+// Much of the Windows API is available both in `string` and `wstring`
 // varieties. To avoid polluting the namespace with two versions of every
 // function, a common pattern in the Windows headers is to offer a single macro
 // that expands to the `string` or `wstring` version, depending on whether the
-// `_UNICODE` preprocessor symbol is set. For example, `GetMessage` will expand
-// to either `GetMessageA` (the `string` version) or `GetMessageW` (the
-// `wstring` version) depending on whether this symbol is defined.
+// `_UNICODE` and `UNICODE` preprocessor symbols are set. For example,
+// `GetMessage` will expand to either `GetMessageA` (the `string` version) or
+// `GetMessageW` (the `wstring` version) depending on whether these symbols are
+// defined.
 //
-// The downside of this is that it makes POSIX interop really hard. Hence, we
-// refuse to compile if such a symbol is passed in during compilation.
-#error "Mesos doesn't currently support the `_UNICODE` Windows header constant"
-#endif // _UNICODE
+// Unfortunately the `string` version is not UTF-8, like a developer would
+// expect on Linux, but is instead the current Windows code page, and thus may
+// take a different value at runtime. This makes it potentially difficult to
+// decode, whereas the `wstring` version is always encoded as UTF-16, and thus
+// can be programatically converted to UTF-8 using the `stringify()` function
+// (converting UTF-8 to UTF-16 is done with `wide_stringify()`).
+//
+// Furthermore, support for NTFS long paths requires the use of the `wstring`
+// APIs, coupled with the `\\?\` long path prefix marker for paths longer than
+// the max path limit. This is accomplished by wrapping paths sent to Windows
+// APIs with the `internal::windows::longpath()` helper. In order to prevent
+// future regressions, we enforce the definitions of `_UNICODE` and `UNICODE`.
+//
+// NOTE: The Mesos code should always use the explicit `W` suffixed APIs in
+// order to avoid type ambiguity.
+#error "Mesos must be built with `_UNICODE` and `UNICODE` defined."
+#endif // !defined(_UNICODE) || !defined(UNICODE)
 
 // An RAII `HANDLE`.
 class SharedHandle : public std::shared_ptr<void>


[06/50] mesos git commit: Windows: Updated `isdir()` and `isfile()` to support long paths.

Posted by jo...@apache.org.
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);
 }
 
 


[28/50] mesos git commit: Windows: Updated `process::createIoPath()` to support long paths.

Posted by jo...@apache.org.
Windows: Updated `process::createIoPath()` to support long paths.

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


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

Branch: refs/heads/master
Commit: 6d782b1b09b7baebbe23a6206bc2943576cb2983
Parents: c412d3f
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 10:55:23 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:36 2017 -0700

----------------------------------------------------------------------
 3rdparty/libprocess/src/subprocess_windows.cpp | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/6d782b1b/3rdparty/libprocess/src/subprocess_windows.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/libprocess/src/subprocess_windows.cpp b/3rdparty/libprocess/src/subprocess_windows.cpp
index cc71fbd..1a91fbe 100644
--- a/3rdparty/libprocess/src/subprocess_windows.cpp
+++ b/3rdparty/libprocess/src/subprocess_windows.cpp
@@ -32,6 +32,8 @@
 #include <stout/try.hpp>
 #include <stout/windows.hpp>
 
+#include <stout/internal/windows/longpath.hpp>
+
 using std::array;
 using std::string;
 
@@ -124,8 +126,8 @@ static Try<HANDLE> createIoPath(const string& path, DWORD accessFlags)
   // the documentation is not clear about whether `FILE_SHARE_WRITE` also
   // ensures we don't take a read lock out.
   SECURITY_ATTRIBUTES sa = { sizeof(SECURITY_ATTRIBUTES), nullptr, TRUE };
-  const HANDLE handle = ::CreateFile(
-      path.c_str(),
+  const HANDLE handle = ::CreateFileW(
+      ::internal::windows::longpath(path).data(),
       accessFlags,
       FILE_SHARE_READ | FILE_SHARE_WRITE,
       &sa,


[23/50] mesos git commit: Windows: Updated `fs::list()` to support long paths.

Posted by jo...@apache.org.
Windows: Updated `fs::list()` to support long paths.

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


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

Branch: refs/heads/master
Commit: d472f8af9166743d1ea27219553d93fc782177dd
Parents: 04054e0
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 10:42:38 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:35 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/windows/fs.hpp | 22 +++++++++++-----------
 1 file changed, 11 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d472f8af/3rdparty/stout/include/stout/windows/fs.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/fs.hpp b/3rdparty/stout/include/stout/windows/fs.hpp
index 7c3413b..4e156a9 100644
--- a/3rdparty/stout/include/stout/windows/fs.hpp
+++ b/3rdparty/stout/include/stout/windows/fs.hpp
@@ -19,6 +19,7 @@
 #include <stout/error.hpp>
 #include <stout/nothing.hpp>
 #include <stout/try.hpp>
+#include <stout/windows.hpp>
 
 #include <stout/internal/windows/symlink.hpp>
 
@@ -89,10 +90,12 @@ inline Try<Nothing> symlink(
 inline Try<std::list<std::string>> list(const std::string& pattern)
 {
   std::list<std::string> found_files;
-  WIN32_FIND_DATA find_data;
-  const HANDLE search_handle = ::FindFirstFile(pattern.c_str(), &find_data);
+  WIN32_FIND_DATAW found;
+  const SharedHandle search_handle(
+    ::FindFirstFileW(wide_stringify(pattern).data(), &found),
+    ::FindClose);
 
-  if (search_handle == INVALID_HANDLE_VALUE) {
+  if (search_handle.get() == INVALID_HANDLE_VALUE) {
     // For compliance with the POSIX implementation (which uses `::glob`),
     // return an empty list instead of an error when the path does not exist.
     int error = ::GetLastError();
@@ -106,18 +109,15 @@ inline Try<std::list<std::string>> list(const std::string& pattern)
   }
 
   do {
-    const std::string current_file(find_data.cFileName);
+    const std::wstring current_file(found.cFileName);
 
-    // Ignore `.` and `..` entries
-    if (current_file.compare(".") != 0 && current_file.compare("..") != 0) {
-      found_files.push_back(current_file);
+    // Ignore `.` and `..` entries.
+    if (current_file.compare(L".") != 0 && current_file.compare(L"..") != 0) {
+      found_files.push_back(stringify(current_file));
     }
-  } while (::FindNextFile(search_handle, &find_data));
+  } while (::FindNextFileW(search_handle.get(), &found));
 
-  // Cache `FindNextFile` error, `FindClose` will overwrite it
   const DWORD error = ::GetLastError();
-  ::FindClose(search_handle);
-
   if (error != ERROR_NO_MORE_FILES) {
     return WindowsError(
         error,


[43/50] mesos git commit: Windows: Deleted `os::hstrerror()` as it is unused.

Posted by jo...@apache.org.
Windows: Deleted `os::hstrerror()` as it is unused.

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


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

Branch: refs/heads/master
Commit: 5df5750d473d61f1feb35b06e00e7211c74ef034
Parents: 54b4f0e
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 15:30:09 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:39 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/windows/os.hpp | 37 +-----------------------
 3rdparty/stout/tests/os/strerror_tests.cpp  | 33 ++-------------------
 2 files changed, 4 insertions(+), 66 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/5df5750d/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/os.hpp b/3rdparty/stout/include/stout/windows/os.hpp
index e24022e..1a5abda 100644
--- a/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/stout/include/stout/windows/os.hpp
@@ -356,42 +356,7 @@ inline Result<pid_t> waitpid(long pid, int* status, int options)
 }
 
 
-inline std::string hstrerror(int err)
-{
-  char buffer[1024];
-  DWORD format_error = 0;
-
-  // NOTE: Per the Linux documentation[1], `h_errno` can have only one of the
-  // following errors.
-  switch (err) {
-    case WSAHOST_NOT_FOUND:
-    case WSANO_DATA:
-    case WSANO_RECOVERY:
-    case WSATRY_AGAIN: {
-      format_error = ::FormatMessage(
-          FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
-          nullptr,
-          err,
-          MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-          buffer,
-          sizeof(buffer),
-          nullptr);
-      break;
-    }
-    default: {
-      return "Unknown resolver error";
-    }
-  }
-
-  if (format_error == 0) {
-    // If call to `FormatMessage` fails, then we choose to output the error
-    // code rather than call `FormatMessage` again.
-    return "os::hstrerror: Call to `FormatMessage` failed with error code" +
-      std::to_string(GetLastError());
-  } else {
-    return buffer;
-  }
-}
+inline std::string hstrerror(int err) = delete;
 
 
 inline Try<Nothing> chown(

http://git-wip-us.apache.org/repos/asf/mesos/blob/5df5750d/3rdparty/stout/tests/os/strerror_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/os/strerror_tests.cpp b/3rdparty/stout/tests/os/strerror_tests.cpp
index f69a4d3..6a69d52 100644
--- a/3rdparty/stout/tests/os/strerror_tests.cpp
+++ b/3rdparty/stout/tests/os/strerror_tests.cpp
@@ -23,25 +23,6 @@
 using std::string;
 
 
-#ifdef __WINDOWS__
-const string errorMessage(int err)
-{
-  char buffer[1024];
-
-  ::FormatMessage(
-      FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
-      nullptr,
-      err,
-      MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
-      buffer,
-      sizeof(buffer),
-      nullptr);
-
-  return buffer;
-}
-#endif // __WINDOWS__
-
-
 TEST(StrerrorTest, ValidErrno)
 {
   EXPECT_EQ(::strerror(ENODEV), os::strerror(ENODEV));
@@ -62,25 +43,17 @@ TEST(StrerrorTest, InvalidErrno)
 
 
 // The Linux documentation[1] on `herrno` indicates there are only 4 possible
-// values that `h_errno` can have. Here we test that the Windows implementation
-// will return "Unknown resolver error" for other error values.
+// values that `h_errno` can have.
 //
 // [1] http://linux.die.net/man/3/hstrerror
+#ifndef __WINDOWS__
 TEST(StrerrorTest, ValidHerrno)
 {
-#ifdef __WINDOWS__
-  EXPECT_EQ("Unknown resolver error", os::hstrerror(ENODEV));
-  EXPECT_EQ("Unknown resolver error", os::hstrerror(EINTR));
-  EXPECT_EQ(::errorMessage(HOST_NOT_FOUND), os::hstrerror(HOST_NOT_FOUND));
-  EXPECT_EQ(::errorMessage(NO_DATA), os::hstrerror(NO_DATA));
-  EXPECT_EQ(::errorMessage(NO_RECOVERY), os::hstrerror(NO_RECOVERY));
-  EXPECT_EQ(::errorMessage(TRY_AGAIN), os::hstrerror(TRY_AGAIN));
-#else
   EXPECT_EQ(::hstrerror(ENODEV), os::hstrerror(ENODEV));
   EXPECT_EQ(::hstrerror(EINTR), os::hstrerror(EINTR));
   EXPECT_EQ(::hstrerror(HOST_NOT_FOUND), os::hstrerror(HOST_NOT_FOUND));
   EXPECT_EQ(::hstrerror(NO_DATA), os::hstrerror(NO_DATA));
   EXPECT_EQ(::hstrerror(NO_RECOVERY), os::hstrerror(NO_RECOVERY));
   EXPECT_EQ(::hstrerror(TRY_AGAIN), os::hstrerror(TRY_AGAIN));
-#endif // __WINDOWS__
 }
+#endif // __WINDOWS__


[26/50] mesos git commit: Windows: Cleaned up `os::var()`.

Posted by jo...@apache.org.
Windows: Cleaned up `os::var()`.

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


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

Branch: refs/heads/master
Commit: 04054e08cd42cc7c18a93d9f9b405a0f1d162cca
Parents: 41debf9
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 09:11:27 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:35 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/windows/os.hpp | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/04054e08/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/os.hpp b/3rdparty/stout/include/stout/windows/os.hpp
index 397ea0a..42fda71 100644
--- a/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/stout/include/stout/windows/os.hpp
@@ -21,7 +21,6 @@
 
 #include <sys/utime.h>
 
-#include <codecvt>
 #include <list>
 #include <map>
 #include <memory>
@@ -33,6 +32,7 @@
 #include <stout/nothing.hpp>
 #include <stout/option.hpp>
 #include <stout/path.hpp>
+#include <stout/stringify.hpp>
 #include <stout/strings.hpp>
 #include <stout/try.hpp>
 #include <stout/version.hpp>
@@ -805,19 +805,16 @@ inline Try<std::string> var()
     // The expected behavior here is for the function to "fail"
     // and return `false`, and `size` receives necessary buffer size.
     return WindowsError(
-        "os::var: `GetAllUsersProfileDirectory` succeeded unexpectedly");
+        "os::var: `GetAllUsersProfileDirectoryW` succeeded unexpectedly");
   }
 
-  std::vector<wchar_t> var_folder(size);
-  if (!::GetAllUsersProfileDirectoryW(&var_folder[0], &size)) {
-    return WindowsError(
-        "os::var: `GetAllUsersProfileDirectory` failed");
+  std::vector<wchar_t> buffer;
+  buffer.reserve(static_cast<size_t>(size));
+  if (!::GetAllUsersProfileDirectoryW(buffer.data(), &size)) {
+    return WindowsError("os::var: `GetAllUsersProfileDirectoryW` failed");
   }
 
-  // Convert UTF-16 `wchar[]` to UTF-8 `string`.
-  std::wstring wvar_folder(&var_folder[0]);
-  std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>, wchar_t> converter;
-  return converter.to_bytes(wvar_folder);
+  return stringify(std::wstring(buffer.data()));
 }
 
 


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

Posted by jo...@apache.org.
Windows: Updated `os::rename()` to support long paths.

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


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

Branch: refs/heads/master
Commit: c412d3f3ba253ad538c92ff5eef505ad19d86989
Parents: d472f8a
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 10:51:53 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:35 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/os/windows/rename.hpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/c412d3f3/3rdparty/stout/include/stout/os/windows/rename.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/rename.hpp b/3rdparty/stout/include/stout/os/windows/rename.hpp
index 544ff90..523912a 100644
--- a/3rdparty/stout/include/stout/os/windows/rename.hpp
+++ b/3rdparty/stout/include/stout/os/windows/rename.hpp
@@ -20,6 +20,8 @@
 #include <stout/try.hpp>
 #include <stout/windows.hpp>
 
+#include <stout/internal/windows/longpath.hpp>
+
 
 namespace os {
 
@@ -36,9 +38,9 @@ inline Try<Nothing> rename(const std::string& from, const std::string& to)
   // [1] https://msdn.microsoft.com/en-us/library/zw5t957f.aspx
   // [2] http://man7.org/linux/man-pages/man2/rename.2.html
   // [3] https://msdn.microsoft.com/en-us/library/windows/desktop/aa365240(v=vs.85).aspx
-  const BOOL result = ::MoveFileEx(
-      from.c_str(),
-      to.c_str(),
+  const BOOL result = ::MoveFileExW(
+      ::internal::windows::longpath(from).data(),
+      ::internal::windows::longpath(to).data(),
       MOVEFILE_COPY_ALLOWED | MOVEFILE_REPLACE_EXISTING);
 
   if (!result) {


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

Posted by jo...@apache.org.
Windows: Updated `os::access()` to support long paths.

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


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

Branch: refs/heads/master
Commit: 6f30623ab84de61ea972a5979a9858d8465c3643
Parents: d91e4be
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Sat Jul 8 22:17:34 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:34 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/os/access.hpp | 14 ++++++++++++--
 3rdparty/stout/include/stout/windows.hpp   |  7 -------
 2 files changed, 12 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/6f30623a/3rdparty/stout/include/stout/os/access.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/access.hpp b/3rdparty/stout/include/stout/os/access.hpp
index d87762a..a7dea1c 100644
--- a/3rdparty/stout/include/stout/os/access.hpp
+++ b/3rdparty/stout/include/stout/os/access.hpp
@@ -19,14 +19,24 @@
 #include <stout/try.hpp>
 
 #ifdef __WINDOWS__
-#include <stout/windows.hpp> // To be certain we're using the right `access`.
+#include <stout/windows.hpp>
+#include <stout/internal/windows/longpath.hpp>
 #endif // __WINDOWS__
 
 namespace os {
 
 inline Try<bool> access(const std::string& path, int how)
 {
-  if (::access(path.c_str(), how) < 0) {
+  int result;
+
+#ifdef __WINDOWS__
+  std::wstring longpath = ::internal::windows::longpath(path);
+  result = ::_waccess(longpath.data(), how);
+#else
+  result = ::access(path.data(), how);
+#endif
+
+  if (result < 0) {
     if (errno == EACCES) {
       return false;
     } else {

http://git-wip-us.apache.org/repos/asf/mesos/blob/6f30623a/3rdparty/stout/include/stout/windows.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows.hpp b/3rdparty/stout/include/stout/windows.hpp
index d70d436..34273dc 100644
--- a/3rdparty/stout/include/stout/windows.hpp
+++ b/3rdparty/stout/include/stout/windows.hpp
@@ -372,13 +372,6 @@ decltype(_mktemp_s(path, strlen(path) + 1))
 }
 
 
-inline auto access(const char* fileName, int accessMode) ->
-decltype(_access(fileName, accessMode))
-{
-  return _access(fileName, accessMode);
-}
-
-
 // NOTE: Signals do not exist on Windows, so all signals are unknown.
 // If the signal number is unknown, the Posix specification leaves the
 // return value of `strsignal` unspecified.


[39/50] mesos git commit: Windows: Made `dynamiclibrary.hpp` use Unicode.

Posted by jo...@apache.org.
Windows: Made `dynamiclibrary.hpp` use Unicode.

This also qualifies the namespace of a few library calls.
Review: https://reviews.apache.org/r/60338/


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

Branch: refs/heads/master
Commit: 54b4f0e32129c5f24c4cea426145fd5b02972339
Parents: 293c7e1
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 15:24:44 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:38 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/windows/dynamiclibrary.hpp | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/54b4f0e3/3rdparty/stout/include/stout/windows/dynamiclibrary.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/dynamiclibrary.hpp b/3rdparty/stout/include/stout/windows/dynamiclibrary.hpp
index 28b8e32..5b3cbf4 100644
--- a/3rdparty/stout/include/stout/windows/dynamiclibrary.hpp
+++ b/3rdparty/stout/include/stout/windows/dynamiclibrary.hpp
@@ -17,6 +17,7 @@
 
 #include <stout/nothing.hpp>
 #include <stout/option.hpp>
+#include <stout/stringify.hpp>
 #include <stout/try.hpp>
 
 #include <stout/windows/error.hpp>
@@ -50,7 +51,7 @@ public:
       return Error("Library already opened");
     }
 
-    handle_ = LoadLibrary(path.c_str());
+    handle_ = ::LoadLibraryW(wide_stringify(path).data());
 
     if (handle_ == nullptr) {
       return WindowsError("Could not load library '" + path + "'");
@@ -67,7 +68,7 @@ public:
       return Error("Could not close library; handle was already `nullptr`");
     }
 
-    if (!FreeLibrary(handle_)) {
+    if (!::FreeLibrary(handle_)) {
       return WindowsError(
           "Could not close library '" + (path_.isSome() ? path_.get() : ""));
     }
@@ -85,7 +86,7 @@ public:
           "Could not get symbol '" + name + "'; library handle was `nullptr`");
     }
 
-    void* symbol = GetProcAddress(handle_, name.c_str());
+    void* symbol = ::GetProcAddress(handle_, name.c_str());
 
     if (symbol == nullptr) {
       return WindowsError(


[46/50] mesos git commit: Windows: Made version info use Unicode.

Posted by jo...@apache.org.
Windows: Made version info use Unicode.

The `GetVersionEx` family of functions have been marked deprecated; not
just the non-Unicode version as the previous comment implied. Thus we do
not hide the valid deprecation warning, and should replace the use of
this API.

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


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

Branch: refs/heads/master
Commit: 76c58f458d4d49551f19a431bea3b4fc75b914e0
Parents: fd40752
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 15:39:06 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:39 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/windows/os.hpp | 38 ++++++++----------------
 1 file changed, 13 insertions(+), 25 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/76c58f45/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/os.hpp b/3rdparty/stout/include/stout/windows/os.hpp
index e0909d1..b234e15 100644
--- a/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/stout/include/stout/windows/os.hpp
@@ -49,20 +49,14 @@
 namespace os {
 namespace internal {
 
-inline Try<OSVERSIONINFOEX> os_version()
+inline Try<OSVERSIONINFOEXW> os_version()
 {
-  OSVERSIONINFOEX os_version;
-  os_version.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
-#pragma warning(push)
-#pragma warning(disable : 4996)
-  // Disable compiler warning asking us to use the Unicode version of
-  // `GetVersionEx`, because Mesos currently does not support Unicode. See
-  // MESOS-6817.
-  if (!::GetVersionEx(reinterpret_cast<LPOSVERSIONINFO>(&os_version))) {
+  OSVERSIONINFOEXW os_version;
+  os_version.dwOSVersionInfoSize = sizeof(os_version);
+  if (!::GetVersionExW(reinterpret_cast<LPOSVERSIONINFO>(&os_version))) {
     return WindowsError(
         "os::internal::os_version: Call to `GetVersionEx` failed");
   }
-#pragma warning(pop)
 
   return os_version;
 }
@@ -116,7 +110,7 @@ inline std::string machine()
 }
 
 
-inline std::string sysname(OSVERSIONINFOEX os_version)
+inline std::string sysname(OSVERSIONINFOEXW os_version)
 {
   switch (os_version.wProductType) {
     case VER_NT_DOMAIN_CONTROLLER:
@@ -128,20 +122,20 @@ inline std::string sysname(OSVERSIONINFOEX os_version)
 }
 
 
-inline std::string release(OSVERSIONINFOEX os_version)
+inline std::string release(OSVERSIONINFOEXW os_version)
 {
   return stringify(
       Version(os_version.dwMajorVersion, os_version.dwMinorVersion, 0));
 }
 
 
-inline std::string version(OSVERSIONINFOEX os_version)
+inline std::string version(OSVERSIONINFOEXW os_version)
 {
   std::string version = std::to_string(os_version.dwBuildNumber);
 
-  if (os_version.szCSDVersion[0] != '\0') {
+  if (os_version.szCSDVersion[0] != L'\0') {
     version.append(" ");
-    version.append(os_version.szCSDVersion);
+    version.append(stringify(os_version.szCSDVersion));
   }
 
   return version;
@@ -437,17 +431,11 @@ inline Try<Memory> memory()
 
 inline Try<Version> release()
 {
-  OSVERSIONINFOEX os_version;
-  os_version.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
-#pragma warning(push)
-#pragma warning(disable : 4996)
-  // Disable compiler warning asking us to use the Unicode version of
-  // `GetVersionEx`, because Mesos currently does not support Unicode. See
-  // MESOS-6817.
-  if (!::GetVersionEx(reinterpret_cast<LPOSVERSIONINFO>(&os_version))) {
+  OSVERSIONINFOEXW os_version;
+  os_version.dwOSVersionInfoSize = sizeof(os_version);
+  if (!::GetVersionExW(reinterpret_cast<LPOSVERSIONINFO>(&os_version))) {
     return WindowsError("os::release: Call to `GetVersionEx` failed");
   }
-#pragma warning(pop)
 
   return Version(os_version.dwMajorVersion, os_version.dwMinorVersion, 0);
 }
@@ -456,7 +444,7 @@ inline Try<Version> release()
 // Return the system information.
 inline Try<UTSInfo> uname()
 {
-  Try<OSVERSIONINFOEX> os_version = internal::os_version();
+  Try<OSVERSIONINFOEXW> os_version = internal::os_version();
   if (os_version.isError()) {
     return Error(os_version.error());
   }


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

Posted by jo...@apache.org.
Windows: Updated `os::chdir()` to support long paths.

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


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

Branch: refs/heads/master
Commit: d91e4bed09abdeac31bc9d901c159167760f716a
Parents: 7367901
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Sat Jul 8 21:53:27 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:34 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/Makefile.am              |  2 +
 3rdparty/stout/include/stout/os/chdir.hpp       | 25 +++---------
 3rdparty/stout/include/stout/os/posix/chdir.hpp | 37 ++++++++++++++++++
 .../stout/include/stout/os/windows/chdir.hpp    | 41 ++++++++++++++++++++
 3rdparty/stout/include/stout/windows.hpp        |  7 ----
 5 files changed, 85 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d91e4bed/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/Makefile.am b/3rdparty/stout/include/Makefile.am
index 5c0f9f8..b0c28b2 100644
--- a/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/stout/include/Makefile.am
@@ -115,6 +115,7 @@ nobase_include_HEADERS =			\
   stout/os/write.hpp				\
   stout/os/xattr.hpp				\
   stout/os/posix/bootid.hpp			\
+  stout/os/posix/chdir.hpp			\
   stout/os/posix/chown.hpp			\
   stout/os/posix/chroot.hpp			\
   stout/os/posix/close.hpp			\
@@ -150,6 +151,7 @@ nobase_include_HEADERS =			\
   stout/os/raw/argv.hpp				\
   stout/os/raw/environment.hpp			\
   stout/os/windows/bootid.hpp			\
+  stout/os/windows/chdir.hpp			\
   stout/os/windows/chroot.hpp			\
   stout/os/windows/close.hpp			\
   stout/os/windows/dup.hpp			\

http://git-wip-us.apache.org/repos/asf/mesos/blob/d91e4bed/3rdparty/stout/include/stout/os/chdir.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/chdir.hpp b/3rdparty/stout/include/stout/os/chdir.hpp
index 4406076..30017bd 100644
--- a/3rdparty/stout/include/stout/os/chdir.hpp
+++ b/3rdparty/stout/include/stout/os/chdir.hpp
@@ -13,29 +13,14 @@
 #ifndef __STOUT_OS_CHDIR_HPP__
 #define __STOUT_OS_CHDIR_HPP__
 
-#include <string>
-
-#include <stout/error.hpp>
-#include <stout/nothing.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 `chdir`.
+#include <stout/os/windows/chdir.hpp>
+#else
+#include <stout/os/posix/chdir.hpp>
 #endif // __WINDOWS__
 
 
-namespace os {
-
-inline Try<Nothing> chdir(const std::string& directory)
-{
-  if (::chdir(directory.c_str()) < 0) {
-    return ErrnoError();
-  }
-
-  return Nothing();
-}
-
-} // namespace os {
-
-
 #endif // __STOUT_OS_CHDIR_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/d91e4bed/3rdparty/stout/include/stout/os/posix/chdir.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/chdir.hpp b/3rdparty/stout/include/stout/os/posix/chdir.hpp
new file mode 100644
index 0000000..8bb2b3b
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/posix/chdir.hpp
@@ -0,0 +1,37 @@
+// 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_CHDIR_HPP__
+#define __STOUT_OS_POSIX_CHDIR_HPP__
+
+#include <string>
+
+#include <stout/error.hpp>
+#include <stout/nothing.hpp>
+#include <stout/try.hpp>
+
+
+namespace os {
+
+inline Try<Nothing> chdir(const std::string& directory)
+{
+  if (::chdir(directory.c_str()) < 0) {
+    return ErrnoError();
+  }
+
+  return Nothing();
+}
+
+} // namespace os {
+
+
+#endif // __STOUT_OS_POSIX_CHDIR_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/d91e4bed/3rdparty/stout/include/stout/os/windows/chdir.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/chdir.hpp b/3rdparty/stout/include/stout/os/windows/chdir.hpp
new file mode 100644
index 0000000..523c7f7
--- /dev/null
+++ b/3rdparty/stout/include/stout/os/windows/chdir.hpp
@@ -0,0 +1,41 @@
+// 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_CHDIR_HPP__
+#define __STOUT_OS_WINDOWS_CHDIR_HPP__
+
+#include <string>
+
+#include <stout/error.hpp>
+#include <stout/nothing.hpp>
+#include <stout/try.hpp>
+#include <stout/windows.hpp>
+
+#include <stout/internal/windows/longpath.hpp>
+
+
+namespace os {
+
+inline Try<Nothing> chdir(const std::string& directory)
+{
+  std::wstring longpath = ::internal::windows::longpath(directory);
+  if (::SetCurrentDirectoryW(longpath.data()) == 0) {
+    return WindowsError();
+  }
+
+  return Nothing();
+}
+
+} // namespace os {
+
+
+#endif // __STOUT_OS_WINDOWS_CHDIR_HPP__

http://git-wip-us.apache.org/repos/asf/mesos/blob/d91e4bed/3rdparty/stout/include/stout/windows.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows.hpp b/3rdparty/stout/include/stout/windows.hpp
index a2b13c3..d70d436 100644
--- a/3rdparty/stout/include/stout/windows.hpp
+++ b/3rdparty/stout/include/stout/windows.hpp
@@ -345,13 +345,6 @@ decltype(strerror_s(buffer, length, errnum))
 // maintain the code. It is an explicit marker that we are using the compiler
 // to guarantee that the return type is identical to whatever is in the Windows
 // implementation of the standard.
-inline auto chdir(const char* path) ->
-decltype(_chdir(path))
-{
-  return _chdir(path);
-}
-
-
 inline auto mktemp(char* path) ->
 decltype(_mktemp(path))
 {


[33/50] mesos git commit: Windows: Updated `fs::usage()` to support long paths.

Posted by jo...@apache.org.
Windows: Updated `fs::usage()` to support long paths.

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


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

Branch: refs/heads/master
Commit: 3ebe54d80497d98802d7d958f274899a15c5ec77
Parents: 129d431
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 14:42:09 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:37 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/windows/fs.hpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/3ebe54d8/3rdparty/stout/include/stout/windows/fs.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/fs.hpp b/3rdparty/stout/include/stout/windows/fs.hpp
index 4e156a9..d7b883c 100644
--- a/3rdparty/stout/include/stout/windows/fs.hpp
+++ b/3rdparty/stout/include/stout/windows/fs.hpp
@@ -21,6 +21,7 @@
 #include <stout/try.hpp>
 #include <stout/windows.hpp>
 
+#include <stout/internal/windows/longpath.hpp>
 #include <stout/internal/windows/symlink.hpp>
 
 namespace fs {
@@ -36,8 +37,8 @@ inline Try<Bytes> size(const std::string& path = "/")
   }
 
   ULARGE_INTEGER free_bytes, total_bytes, total_free_bytes;
-  if (::GetDiskFreeSpaceEx(
-          real_path.get().c_str(),
+  if (::GetDiskFreeSpaceExW(
+          internal::windows::longpath(real_path.get()).data(),
           &free_bytes,
           &total_bytes,
           &total_free_bytes) == 0) {
@@ -61,8 +62,8 @@ inline Try<double> usage(const std::string& path = "/")
   }
 
   ULARGE_INTEGER free_bytes, total_bytes, total_free_bytes;
-  if (::GetDiskFreeSpaceEx(
-          real_path.get().c_str(),
+  if (::GetDiskFreeSpaceExW(
+          internal::windows::longpath(real_path.get()).data(),
           &free_bytes,
           &total_bytes,
           &total_free_bytes) == 0) {


[50/50] mesos git commit: Windows: Updated documentation for NTFS long path support.

Posted by jo...@apache.org.
Windows: Updated documentation for NTFS long path support.

The list of individual components was also removed for clarity.
Developers should either install the entire workload (which is confirmed
sufficient), or know their environment well enough to choose specific
components. Furthermore, the list of available components changes
frequently enough that maintaining this list becomes difficult.

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


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

Branch: refs/heads/master
Commit: edba292659e05d7a0989eb122f7824e1c21db8fb
Parents: 4b9daa2
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 18:38:02 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 18:38:02 2017 -0700

----------------------------------------------------------------------
 docs/windows.md | 29 +++++++----------------------
 1 file changed, 7 insertions(+), 22 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/edba2926/docs/windows.md
----------------------------------------------------------------------
diff --git a/docs/windows.md b/docs/windows.md
index d596158..b47ba5a 100644
--- a/docs/windows.md
+++ b/docs/windows.md
@@ -15,14 +15,7 @@ Mesos 1.0.0 introduced experimental support for Windows.
 
 1. Install the latest [Visual Studio 2017](https://www.visualstudio.com/downloads/):
    The "Community" edition is sufficient (and free).
-   During installation, you install either the "Desktop development with C++"
-   workload or choose the following "Individual components":
-    * VC++ 2017 v141 toolset
-    * Windows 10 SDK (10.0.15036.0, currently) for Desktop C++
-    * Windows Universal CRT SDK
-    * Windows Universal C Runtime
-    * C++ profiling tools (optional, for profiling)
-    * Visual Studio C++ core features (optional, for IDE)
+   During installation, choose the "Desktop development with C++" workload.
 
 2. Install [CMake 3.8.0](https://cmake.org/download/) or later.
    During installation, choose to "Add CMake to the system PATH for all users".
@@ -34,18 +27,10 @@ Mesos 1.0.0 introduced experimental support for Windows.
    Command Prompt", and "Checkout Windows-style, commit Unix-style
    line endings" (i.e. `git config core.autocrlf true`).
 
-5. Enable filesystem long path support by running the following
-   in an administrative PowerShell prompt:
-   `Set-ItemProperty -Path HKLM:\SYSTEM\CurrentControlSet\Control\FileSystem -Name LongPathsEnabled -Value 1`
-   And then reboot.  Alternatively this can be set manually through `regedit`.
-   For more details, see this
-   [MSDN article](https://msdn.microsoft.com/en-us/library/windows/desktop/aa365247(v=vs.85).aspx).
-   NOTE: This requirement is in the process of being deprecated!
-
-6. Make sure there are no spaces in your build directory.
+5. Make sure there are no spaces in your build directory.
    For example, `C:/Program Files (x86)/mesos` is an invalid build directory.
 
-7. If developing Mesos, install [Python 2](https://www.python.org/downloads/)
+6. If developing Mesos, install [Python 2](https://www.python.org/downloads/)
    (not Python 3), in order to use our support scripts (e.g. to post and apply
    patches, or lint source code).
 
@@ -55,7 +40,7 @@ Mesos 1.0.0 introduced experimental support for Windows.
 Following are the instructions for Windows 10.
 
     # Start an administrative session of PowerShell
-    # (required for creating symlinks).
+    # (required for creating symlinks when using the agent).
 
     # Clone (or extract) Mesos.
     git clone https://git-wip-us.apache.org/repos/asf/mesos.git
@@ -83,8 +68,8 @@ The current implementation is known to have the following limitations:
 * Only the agent should be run on Windows.  The Mesos master can be
   launched, but only for testing as the master does not support
   high-availability setups on Windows.
-* Due to the 260 character `MAX_PATH` limitation on Windows,
-  it is required to enable the NTFS long path support.
+* While Mesos supports NTFS long paths internally, tasks which do not support
+  long paths must be run on agent whose `--work_dir` is a short path.
 * The Mesos agent must be run as Administrator, mainly due to symlinks.
 * The `MesosContainerizer` currently does not provide any actual
   resource isolation (similar to running the Mesos agent on POSIX).
@@ -93,4 +78,4 @@ The current implementation is known to have the following limitations:
 ## Status
 
 For more information regarding the status of Windows support in Mesos,
-please refer to the [Jira epic](https://issues.apache.org/jira/browse/MESOS-3094).
\ No newline at end of file
+please refer to the [JIRA epic](https://issues.apache.org/jira/browse/MESOS-3094).


[48/50] mesos git commit: Windows: Made `process_entry()` use Unicode.

Posted by jo...@apache.org.
Windows: Made `process_entry()` use Unicode.

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


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

Branch: refs/heads/master
Commit: fcbb67c77cbc2dd2e887c8f4a778c64f7c94fcd3
Parents: 76c58f4
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 15:46:17 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:39 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/windows/os.hpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/fcbb67c7/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/os.hpp b/3rdparty/stout/include/stout/windows/os.hpp
index b234e15..f35bf31 100644
--- a/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/stout/include/stout/windows/os.hpp
@@ -474,7 +474,7 @@ inline tm* gmtime_r(const time_t* timep, tm* result)
 }
 
 
-inline Result<PROCESSENTRY32> process_entry(pid_t pid)
+inline Result<PROCESSENTRY32W> process_entry(pid_t pid)
 {
   // Get a snapshot of the processes in the system. NOTE: We should not check
   // whether the handle is `nullptr`, because this API will always return
@@ -488,9 +488,9 @@ inline Result<PROCESSENTRY32> process_entry(pid_t pid)
   SharedHandle safe_snapshot_handle(snapshot_handle, ::CloseHandle);
 
   // Initialize process entry.
-  PROCESSENTRY32 process_entry;
-  ZeroMemory(&process_entry, sizeof(PROCESSENTRY32));
-  process_entry.dwSize = sizeof(PROCESSENTRY32);
+  PROCESSENTRY32W process_entry;
+  memset(&process_entry, 0, sizeof(process_entry));
+  process_entry.dwSize = sizeof(process_entry);
 
   // Get first process so that we can loop through process entries until we
   // find the one we care about.
@@ -535,7 +535,7 @@ inline Result<PROCESSENTRY32> process_entry(pid_t pid)
 inline Result<Process> process(pid_t pid)
 {
   // Find process with pid.
-  Result<PROCESSENTRY32> entry = process_entry(pid);
+  Result<PROCESSENTRY32W> entry = process_entry(pid);
 
   if (entry.isError()) {
     return WindowsError(entry.error());
@@ -604,7 +604,7 @@ inline Result<Process> process(pid_t pid)
       Bytes(proc_mem_counters.WorkingSetSize),
       utime.isSome() ? utime.get() : Option<Duration>::none(),
       stime.isSome() ? stime.get() : Option<Duration>::none(),
-      entry.get().szExeFile,                   // Executable filename.
+      stringify(entry.get().szExeFile),        // Executable filename.
       false);                                  // Is not zombie process.
 }
 


[42/50] mesos git commit: Windows: Made `os::user()` use Unicode.

Posted by jo...@apache.org.
Windows: Made `os::user()` use Unicode.

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


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

Branch: refs/heads/master
Commit: 293c7e1b4073e65085750ee695d7d16e10256516
Parents: 0f2bfe7
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 15:22:42 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:38 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/os/windows/su.hpp | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/293c7e1b/3rdparty/stout/include/stout/os/windows/su.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/su.hpp b/3rdparty/stout/include/stout/os/windows/su.hpp
index 573fdef..1bfbb26 100644
--- a/3rdparty/stout/include/stout/os/windows/su.hpp
+++ b/3rdparty/stout/include/stout/os/windows/su.hpp
@@ -81,18 +81,19 @@ inline Result<std::string> user(Option<uid_t> uid = None())
 
   EXTENDED_NAME_FORMAT username_format = NameSamCompatible;
   ULONG buffer_size = 0;
-  if (::GetUserNameEx(username_format, nullptr, &buffer_size) == FALSE) {
+  if (::GetUserNameExW(username_format, nullptr, &buffer_size) == FALSE) {
     if (::GetLastError() != ERROR_MORE_DATA) {
       return WindowsError("os::user: Failed to get buffer size for username");
     }
   }
 
-  std::vector<TCHAR> user_name(buffer_size);
-  if (::GetUserNameEx(username_format, &user_name[0], &buffer_size) == FALSE) {
+  std::vector<wchar_t> user_name(buffer_size);
+  if (::GetUserNameExW(username_format, user_name.data(), &buffer_size)
+      == FALSE) {
     return WindowsError("os::user: Failed to get username from OS");
   }
 
-  return std::string(&user_name[0]);
+  return stringify(std::wstring(user_name.data()));
 }
 
 


[45/50] mesos git commit: Windows: Made job object APIs use Unicode.

Posted by jo...@apache.org.
Windows: Made job object APIs use Unicode.

Changed the Job Object name to be a `wstring` for easier use.

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


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

Branch: refs/heads/master
Commit: dc81df5c2e53acecb3dcc215f8d9499e8095a327
Parents: 5df5750
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 15:36:08 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:39 2017 -0700

----------------------------------------------------------------------
 .../stout/include/stout/os/windows/killtree.hpp |  2 +-
 3rdparty/stout/include/stout/windows/os.hpp     | 28 +++++++++++---------
 2 files changed, 16 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/dc81df5c/3rdparty/stout/include/stout/os/windows/killtree.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/killtree.hpp b/3rdparty/stout/include/stout/os/windows/killtree.hpp
index 267a9a0..ce8bdcd 100644
--- a/3rdparty/stout/include/stout/os/windows/killtree.hpp
+++ b/3rdparty/stout/include/stout/os/windows/killtree.hpp
@@ -34,7 +34,7 @@ inline Try<std::list<ProcessTree>> killtree(
     bool groups = false,
     bool sessions = false)
 {
-  Try<std::string> name = os::name_job(pid);
+  Try<std::wstring> name = os::name_job(pid);
   if (name.isError()) {
     return Error("Failed to determine job object name: " + name.error());
   }

http://git-wip-us.apache.org/repos/asf/mesos/blob/dc81df5c/3rdparty/stout/include/stout/windows/os.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/windows/os.hpp b/3rdparty/stout/include/stout/windows/os.hpp
index 1a5abda..e0909d1 100644
--- a/3rdparty/stout/include/stout/windows/os.hpp
+++ b/3rdparty/stout/include/stout/windows/os.hpp
@@ -627,17 +627,17 @@ inline int random()
 }
 
 
-// `name_job` maps a `pid` to a `string` name for a job object.
+// `name_job` maps a `pid` to a `wstring` name for a job object.
 // Only named job objects are accessible via `OpenJobObject`.
 // Thus all our job objects must be named. This is essentially a shim
 // to map the Linux concept of a process tree's root `pid` to a
 // named job object so that the process group can be treated similarly.
-inline Try<std::string> name_job(pid_t pid) {
+inline Try<std::wstring> name_job(pid_t pid) {
   Try<std::string> alpha_pid = strings::internal::format("MESOS_JOB_%X", pid);
   if (alpha_pid.isError()) {
     return Error(alpha_pid.error());
   }
-  return alpha_pid;
+  return wide_stringify(alpha_pid.get());
 }
 
 
@@ -649,18 +649,19 @@ inline Try<std::string> name_job(pid_t pid) {
 inline Try<SharedHandle> open_job(
     const DWORD desired_access,
     BOOL inherit_handles,
-    const std::string& name)
+    const std::wstring& name)
 {
   SharedHandle jobHandle(
-      ::OpenJobObject(
+      ::OpenJobObjectW(
           desired_access,
           inherit_handles,
-          name.c_str()),
+          name.data()),
       ::CloseHandle);
 
   if (jobHandle.get() == nullptr) {
     return WindowsError(
-        "os::open_job: Call to `OpenJobObject` failed for job: " + name);
+        "os::open_job: Call to `OpenJobObject` failed for job: " +
+        stringify(name));
   }
 
   return jobHandle;
@@ -673,19 +674,19 @@ inline Try<SharedHandle> open_job(
 // handle is closed and all associated processes have exited,
 // a running process must be assigned to the created job
 // before the returned handle is closed.
-inline Try<SharedHandle> create_job(const std::string& name)
+inline Try<SharedHandle> create_job(const std::wstring& name)
 {
   SharedHandle jobHandle(
-      ::CreateJobObject(
+      ::CreateJobObjectW(
           nullptr,       // Use a default security descriptor, and
                          // the created handle cannot be inherited.
-          name.c_str()), // The name of the job.
+          name.data()),  // The name of the job.
       ::CloseHandle);
-  // TODO(andschwa): Fix the type of `name` when Unicode is turned on.
 
   if (jobHandle.get_handle() == nullptr) {
     return WindowsError(
-        "os::create_job: Call to `CreateJobObject` failed for job: " + name);
+        "os::create_job: Call to `CreateJobObject` failed for job: " +
+        stringify(name));
   }
 
   JOBOBJECT_EXTENDED_LIMIT_INFORMATION jeli = { { 0 }, 0 };
@@ -705,7 +706,8 @@ inline Try<SharedHandle> create_job(const std::string& name)
 
   if (setInformationResult == FALSE) {
     return WindowsError(
-        "os::create_job: `SetInformationJobObject` failed for job: " + name);
+        "os::create_job: `SetInformationJobObject` failed for job: " +
+        stringify(name));
   }
 
   return jobHandle;


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

Posted by jo...@apache.org.
Windows: Updated `os::rmdir()` to support long paths.

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


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

Branch: refs/heads/master
Commit: e1abdf9054a9d5ff3f59eb2d0f4c8378ffe5eb85
Parents: f2db53f
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Fri Jul 7 16:01:41 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:34 2017 -0700

----------------------------------------------------------------------
 .../stout/include/stout/os/windows/rmdir.hpp    | 46 +++++++++++---------
 1 file changed, 26 insertions(+), 20 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/e1abdf90/3rdparty/stout/include/stout/os/windows/rmdir.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/rmdir.hpp b/3rdparty/stout/include/stout/os/windows/rmdir.hpp
index 05eceea..76b74f8 100644
--- a/3rdparty/stout/include/stout/os/windows/rmdir.hpp
+++ b/3rdparty/stout/include/stout/os/windows/rmdir.hpp
@@ -26,6 +26,9 @@
 
 #include <stout/windows/error.hpp>
 
+#include <stout/internal/windows/longpath.hpp>
+#include <stout/internal/windows/reparsepoint.hpp>
+
 
 namespace os {
 namespace internal {
@@ -59,27 +62,29 @@ inline Try<Nothing> recursive_remove_directory(
   } else {
     current_path = path;
   }
+  const std::wstring long_current_path =
+      ::internal::windows::longpath(current_path);
 
   // Get first file matching pattern `X:\path\to\wherever\*`.
-  WIN32_FIND_DATA found;
-  const std::string search_pattern = current_path + "*";
+  WIN32_FIND_DATAW found;
+  const std::wstring search_pattern = long_current_path + L"*";
   const SharedHandle search_handle(
-      FindFirstFile(search_pattern.c_str(), &found),
-      FindClose);
+      ::FindFirstFileW(search_pattern.data(), &found),
+      ::FindClose);
 
   if (search_handle.get() == INVALID_HANDLE_VALUE) {
     return WindowsError(
         "`os::internal::recursive_remove_directory` failed when searching "
-        "for files with pattern '" + search_pattern + "'");
+        "for files with pattern '" + stringify(search_pattern) + "'");
   }
 
   do {
     // NOTE: do-while is appropriate here because folder is guaranteed to have
     // at least a file called `.` (and probably also one called `..`).
-    const std::string current_file(found.cFileName);
+    const std::wstring current_file(found.cFileName);
 
-    const bool is_current_directory = current_file.compare(".") == 0;
-    const bool is_parent_directory = current_file.compare("..") == 0;
+    const bool is_current_directory = current_file.compare(L".") == 0;
+    const bool is_parent_directory = current_file.compare(L"..") == 0;
 
     // Don't try to delete `.` and `..` files in directory.
     if (is_current_directory || is_parent_directory) {
@@ -87,7 +92,7 @@ inline Try<Nothing> recursive_remove_directory(
     }
 
     // Path to remove.
-    const std::string current_absolute_path = current_path + current_file;
+    const std::wstring current_absolute_path = long_current_path + current_file;
 
     Try<bool> is_reparse_point =
       ::internal::windows::reparse_point_attribute_set(current_absolute_path);
@@ -102,47 +107,48 @@ inline Try<Nothing> recursive_remove_directory(
       //
       // If either `RemoveDirectory` or `DeleteFile` succeeds, the reparse
       // point has been successfully removed, and we report success.
-      const BOOL rmdir = ::RemoveDirectory(current_absolute_path.c_str());
+      const BOOL rmdir = ::RemoveDirectoryW(current_absolute_path.data());
 
       if (rmdir == FALSE) {
-        const BOOL rm = ::DeleteFile(current_absolute_path.c_str());
+        const BOOL rm = ::DeleteFileW(current_absolute_path.data());
 
         if (rm == FALSE) {
           return WindowsError(
               "Failed to remove reparse point at '" +
-              current_absolute_path + "'");
+              stringify(current_absolute_path) + "'");
         }
       }
-    } else if (os::stat::isdir(current_absolute_path)) {
+    } else if (os::stat::isdir(stringify(current_absolute_path))) {
       Try<Nothing> removed = recursive_remove_directory(
-          current_absolute_path, true, continueOnError);
+          stringify(current_absolute_path), true, continueOnError);
 
       if (removed.isError()) {
         if (continueOnError) {
-          LOG(WARNING) << "Failed to delete directory " << current_absolute_path
+          LOG(WARNING) << "Failed to delete directory "
+                       << stringify(current_absolute_path)
                        << " with error " << removed.error();
         } else {
           return Error(removed.error());
         }
       }
     } else {
-      if (::remove(current_absolute_path.c_str()) != 0) {
+      if (::DeleteFileW(current_absolute_path.data()) == 0) {
         if (continueOnError) {
           LOG(WARNING)
               << "`os::internal::recursive_remove_directory`"
               << " attempted to delete file '"
-              << current_absolute_path << "', but failed";
+              << stringify(current_absolute_path) << "', but failed";
         } else {
           return WindowsError(
               "`os::internal::recursive_remove_directory` attempted to delete "
-              "file '" + current_absolute_path + "', but failed");
+              "file '" + stringify(current_absolute_path) + "', but failed");
         }
       }
     }
-  } while (FindNextFile(search_handle.get(), &found));
+  } while (::FindNextFileW(search_handle.get(), &found));
 
   // Finally, remove current directory unless `removeRoot` is disabled.
-  if (removeRoot && ::_rmdir(current_path.c_str()) == -1) {
+  if (removeRoot && ::RemoveDirectoryW(long_current_path.data()) == FALSE) {
     if (continueOnError) {
       LOG(WARNING) << "`os::internal::recursive_remove_directory`"
                    << " attempted to delete directory '"


[30/50] mesos git commit: Windows: Replaced `ping` with `Start-Sleep`.

Posted by jo...@apache.org.
Windows: Replaced `ping` with `Start-Sleep`.

This `SLEEP_COMMAND` macro represents a command that should sleep. On
POSIX systems, a `sleep` binary is available, but on Windows, `sleep` is
a `cmd.exe` feature that requires a TTY. Previously, this was replaced
with `ping` as it approximates sleep, except that it produces noisy
output. We replace it with the `Start-Sleep` PowerShell command, which
does not require a TTY, and is always available.

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


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

Branch: refs/heads/master
Commit: 0fb02c875d72d0ed8c6cf13acc5401212f72be50
Parents: d7eee2d
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 11:14:31 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:36 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/gtest.hpp | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/0fb02c87/3rdparty/stout/include/stout/gtest.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/gtest.hpp b/3rdparty/stout/include/stout/gtest.hpp
index a004a37..1df5eaf 100644
--- a/3rdparty/stout/include/stout/gtest.hpp
+++ b/3rdparty/stout/include/stout/gtest.hpp
@@ -226,7 +226,7 @@ template <typename T1, typename T2>
 #ifndef __WINDOWS__
 #define SLEEP_COMMAND(x) "sleep " #x
 #else
-#define SLEEP_COMMAND(x) (x > 0 ? "ping 127.0.0.1 -n " #x : "cmd /C exit 0")
+#define SLEEP_COMMAND(x) "powershell -NoProfile -Command Start-Sleep " #x
 #endif // __WINDOWS__
 
 


[04/50] mesos git commit: Windows: Added `internal::windows::longpath()` helper.

Posted by jo...@apache.org.
Windows: Added `internal::windows::longpath()` helper.

This function provides a concise mapping from any UTF-8 `std::string
path` to a UTF-16 `std::wstring path` with the long path prefix, used
for eliminating the `PATH_MAX` restriction of Windows filesystem APIs.

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


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

Branch: refs/heads/master
Commit: 4bfc99ca747e62d669326613b47051bbb397c350
Parents: 4892a8f
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Tue Jun 27 13:59:18 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:31 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/Makefile.am              |  1 +
 .../include/stout/internal/windows/longpath.hpp | 53 ++++++++++++++++++++
 2 files changed, 54 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/4bfc99ca/3rdparty/stout/include/Makefile.am
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/Makefile.am b/3rdparty/stout/include/Makefile.am
index dec7293..8e1799b 100644
--- a/3rdparty/stout/include/Makefile.am
+++ b/3rdparty/stout/include/Makefile.am
@@ -41,6 +41,7 @@ nobase_include_HEADERS =			\
   stout/hashset.hpp				\
   stout/internal/windows/dirent.hpp		\
   stout/internal/windows/grp.hpp		\
+  stout/internal/windows/longpath.hpp		\
   stout/internal/windows/pwd.hpp		\
   stout/internal/windows/reparsepoint.hpp	\
   stout/internal/windows/symlink.hpp		\

http://git-wip-us.apache.org/repos/asf/mesos/blob/4bfc99ca/3rdparty/stout/include/stout/internal/windows/longpath.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/internal/windows/longpath.hpp b/3rdparty/stout/include/stout/internal/windows/longpath.hpp
new file mode 100644
index 0000000..446b038
--- /dev/null
+++ b/3rdparty/stout/include/stout/internal/windows/longpath.hpp
@@ -0,0 +1,53 @@
+// 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_INTERNAL_WINDOWS_LONGPATH_HPP__
+#define __STOUT_INTERNAL_WINDOWS_LONGPATH_HPP__
+
+#include <string>
+
+#include <assert.h>
+
+#include <stout/path.hpp>
+#include <stout/stringify.hpp>
+
+#include <stout/os/constants.hpp>
+
+
+namespace internal {
+namespace windows {
+
+// This function idempotently prepends "\\?\" to the given path iff:
+// (1) The path's length is greater than 248, the minimum Windows API limit.
+//     This limit is neither `NAME_MAX` nor `PATH_MAX`; it is an arbitrary
+//     limit of `CreateDirectory` and is the smallest such limit.
+// (2) The path is absolute (otherwise the marker is meaningless).
+// (3) The path does not already have the marker (idempotent).
+//
+// It then converts the path to UTF-16, appropriate for use in Uniode versions
+// of Windows filesystem APIs which support lengths greater than NAME_MAX.
+inline std::wstring longpath(const std::string& path)
+{
+  const size_t max_path_length = 248;
+  if (path.size() > max_path_length &&
+      path::absolute(path) &&
+      !strings::startsWith(path, os::LONGPATH_PREFIX)) {
+    return wide_stringify(os::LONGPATH_PREFIX + path);
+  } else {
+    return wide_stringify(path);
+  }
+}
+
+} // namespace windows {
+} // namespace internal {
+
+#endif // __STOUT_INTERNAL_WINDOWS_LONGPATH_HPP__


[14/50] mesos git commit: Refactored `enum FollowSymlink` to an `enum class FollowSymlink`.

Posted by jo...@apache.org.
Refactored `enum FollowSymlink` to an `enum class FollowSymlink`.

Using `enum class` is preferred as it provides stronger type-safety.

The `enum class FollowSymlink` definition is moved into
the POSIX `stat.hpp` and Windows `reparsepoint.hpp` headers
to avoid a circular dependency.

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


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

Branch: refs/heads/master
Commit: 841f879375b32989193ed7ac86ae3341e5a57468
Parents: d107bb7
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Fri Jul 7 12:00:53 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:33 2017 -0700

----------------------------------------------------------------------
 .../stout/internal/windows/reparsepoint.hpp     | 18 ++++++
 3rdparty/stout/include/stout/os/posix/stat.hpp  | 38 ++++++++-----
 3rdparty/stout/include/stout/os/stat.hpp        | 18 ------
 .../stout/include/stout/os/windows/stat.hpp     | 30 +++++-----
 3rdparty/stout/tests/os_tests.cpp               | 60 +++++++++++++-------
 5 files changed, 97 insertions(+), 67 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/841f8793/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp b/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
index 3a1ea16..dcadfed 100644
--- a/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
+++ b/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
@@ -27,6 +27,24 @@
 #include <stout/internal/windows/attributes.hpp>
 #include <stout/internal/windows/longpath.hpp>
 
+
+namespace os {
+namespace stat {
+
+// Specify whether symlink path arguments should be followed or
+// not. APIs in the os::stat family that take a FollowSymlink
+// argument all provide FollowSymlink::FOLLOW_SYMLINK as the default value,
+// so they will follow symlinks unless otherwise specified.
+enum class FollowSymlink
+{
+  DO_NOT_FOLLOW_SYMLINK,
+  FOLLOW_SYMLINK
+};
+
+} // namespace stat {
+} // namespace os {
+
+
 // We pass this struct to `DeviceIoControl` to get information about a reparse
 // point (including things like whether it's a symlink). It is normally part of
 // the Device Driver Kit (DDK), specifically `nitfs.h`, but rather than taking

http://git-wip-us.apache.org/repos/asf/mesos/blob/841f8793/3rdparty/stout/include/stout/os/posix/stat.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/posix/stat.hpp b/3rdparty/stout/include/stout/os/posix/stat.hpp
index 2762c41..5835374 100644
--- a/3rdparty/stout/include/stout/os/posix/stat.hpp
+++ b/3rdparty/stout/include/stout/os/posix/stat.hpp
@@ -27,6 +27,17 @@ namespace os {
 
 namespace stat {
 
+// Specify whether symlink path arguments should be followed or
+// not. APIs in the os::stat family that take a FollowSymlink
+// argument all provide FollowSymlink::FOLLOW_SYMLINK as the default value,
+// so they will follow symlinks unless otherwise specified.
+enum class FollowSymlink
+{
+  DO_NOT_FOLLOW_SYMLINK,
+  FOLLOW_SYMLINK
+};
+
+
 namespace internal {
 
 inline Try<struct ::stat> stat(
@@ -36,12 +47,12 @@ inline Try<struct ::stat> stat(
   struct ::stat s;
 
   switch (follow) {
-    case DO_NOT_FOLLOW_SYMLINK:
+    case FollowSymlink::DO_NOT_FOLLOW_SYMLINK:
       if (::lstat(path.c_str(), &s) < 0) {
         return ErrnoError("Failed to lstat '" + path + "'");
       }
       return s;
-    case FOLLOW_SYMLINK:
+    case FollowSymlink::FOLLOW_SYMLINK:
       if (::stat(path.c_str(), &s) < 0) {
         return ErrnoError("Failed to stat '" + path + "'");
       }
@@ -55,17 +66,18 @@ inline Try<struct ::stat> stat(
 
 inline bool islink(const std::string& path)
 {
-  // By definition, you don't followsymlinks when trying
+  // By definition, you don't follow symlinks when trying
   // to find whether a path is a link. If you followed it,
   // it wouldn't ever be a link.
-  Try<struct ::stat> s = internal::stat(path, DO_NOT_FOLLOW_SYMLINK);
+  Try<struct ::stat> s = internal::stat(
+      path, FollowSymlink::DO_NOT_FOLLOW_SYMLINK);
   return s.isSome() && S_ISLNK(s->st_mode);
 }
 
 
 inline bool isdir(
     const std::string& path,
-    const FollowSymlink follow = FOLLOW_SYMLINK)
+    const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
 {
   Try<struct ::stat> s = internal::stat(path, follow);
   return s.isSome() && S_ISDIR(s->st_mode);
@@ -74,7 +86,7 @@ inline bool isdir(
 
 inline bool isfile(
     const std::string& path,
-    const FollowSymlink follow = FOLLOW_SYMLINK)
+    const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
 {
   Try<struct ::stat> s = internal::stat(path, follow);
   return s.isSome() && S_ISREG(s->st_mode);
@@ -87,7 +99,7 @@ inline bool isfile(
 // name (strlen).
 inline Try<Bytes> size(
     const std::string& path,
-    const FollowSymlink follow = FOLLOW_SYMLINK)
+    const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
 {
   Try<struct ::stat> s = internal::stat(path, follow);
   if (s.isError()) {
@@ -100,7 +112,7 @@ inline Try<Bytes> size(
 
 inline Try<long> mtime(
     const std::string& path,
-    const FollowSymlink follow = FOLLOW_SYMLINK)
+    const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
 {
   Try<struct ::stat> s = internal::stat(path, follow);
   if (s.isError()) {
@@ -113,7 +125,7 @@ inline Try<long> mtime(
 
 inline Try<mode_t> mode(
     const std::string& path,
-    const FollowSymlink follow = FOLLOW_SYMLINK)
+    const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
 {
   Try<struct ::stat> s = internal::stat(path, follow);
   if (s.isError()) {
@@ -126,7 +138,7 @@ inline Try<mode_t> mode(
 
 inline Try<dev_t> dev(
     const std::string& path,
-    const FollowSymlink follow = FOLLOW_SYMLINK)
+    const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
 {
   Try<struct ::stat> s = internal::stat(path, follow);
   if (s.isError()) {
@@ -139,7 +151,7 @@ inline Try<dev_t> dev(
 
 inline Try<dev_t> rdev(
     const std::string& path,
-    const FollowSymlink follow = FOLLOW_SYMLINK)
+    const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
 {
   Try<struct ::stat> s = internal::stat(path, follow);
   if (s.isError()) {
@@ -156,7 +168,7 @@ inline Try<dev_t> rdev(
 
 inline Try<ino_t> inode(
     const std::string& path,
-    const FollowSymlink follow = FOLLOW_SYMLINK)
+    const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
 {
   Try<struct ::stat> s = internal::stat(path, follow);
   if (s.isError()) {
@@ -169,7 +181,7 @@ inline Try<ino_t> inode(
 
 inline Try<uid_t> uid(
     const std::string& path,
-    const FollowSymlink follow = FOLLOW_SYMLINK)
+    const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
 {
   Try<struct ::stat> s = internal::stat(path, follow);
   if (s.isError()) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/841f8793/3rdparty/stout/include/stout/os/stat.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/stat.hpp b/3rdparty/stout/include/stout/os/stat.hpp
index d002c98..f4f76c7 100644
--- a/3rdparty/stout/include/stout/os/stat.hpp
+++ b/3rdparty/stout/include/stout/os/stat.hpp
@@ -13,24 +13,6 @@
 #ifndef __STOUT_OS_STAT_HPP__
 #define __STOUT_OS_STAT_HPP__
 
-namespace os {
-
-namespace stat {
-
-// Specify whether symlink path arguments should be followed or
-// not. APIs in the os::stat family that take a FollowSymlink
-// argument all provide FOLLOW_SYMLINK as the default value,
-// so they will follow symlinks unless otherwise specified.
-enum FollowSymlink
-{
-  DO_NOT_FOLLOW_SYMLINK,
-  FOLLOW_SYMLINK
-};
-
-} // namespace stat {
-
-} // namespace os {
-
 // For readability, we minimize the number of #ifdef blocks in the code by
 // splitting platform specific system calls into separate directories.
 #ifdef __WINDOWS__

http://git-wip-us.apache.org/repos/asf/mesos/blob/841f8793/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 b22ae80..0db6d48 100644
--- a/3rdparty/stout/include/stout/os/windows/stat.hpp
+++ b/3rdparty/stout/include/stout/os/windows/stat.hpp
@@ -38,11 +38,11 @@ inline bool islink(const std::string& path);
 
 inline bool isdir(
     const std::string& path,
-    const FollowSymlink follow = FOLLOW_SYMLINK)
+    const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
 {
   // A symlink itself is not a directory.
   // If it's not a link, we ignore `follow`.
-  if (follow == DO_NOT_FOLLOW_SYMLINK && islink(path)) {
+  if (follow == FollowSymlink::DO_NOT_FOLLOW_SYMLINK && islink(path)) {
     return false;
   }
 
@@ -59,13 +59,13 @@ inline bool isdir(
 
 inline bool isfile(
     const std::string& path,
-    const FollowSymlink follow = FOLLOW_SYMLINK)
+    const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
 {
   // 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.
   // If it's not a link, we ignore `follow`.
-  if (follow == DO_NOT_FOLLOW_SYMLINK && islink(path)) {
+  if (follow == FollowSymlink::DO_NOT_FOLLOW_SYMLINK && islink(path)) {
     return false;
   }
 
@@ -99,10 +99,10 @@ inline bool islink(const std::string& path)
 // name (strlen).
 inline Try<Bytes> size(
     const std::string& path,
-    const FollowSymlink follow = FOLLOW_SYMLINK)
+    const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
 {
   switch (follow) {
-    case DO_NOT_FOLLOW_SYMLINK: {
+    case FollowSymlink::DO_NOT_FOLLOW_SYMLINK: {
       Try<::internal::windows::SymbolicLink> symlink =
         ::internal::windows::query_symbolic_link_data(path);
 
@@ -113,7 +113,7 @@ inline Try<Bytes> size(
       }
       break;
     }
-    case FOLLOW_SYMLINK: {
+    case FollowSymlink::FOLLOW_SYMLINK: {
       struct _stat s;
 
       if (::_stat(path.c_str(), &s) < 0) {
@@ -131,9 +131,9 @@ inline Try<Bytes> size(
 
 inline Try<long> mtime(
     const std::string& path,
-    const FollowSymlink follow = FOLLOW_SYMLINK)
+    const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
 {
-  if (follow == DO_NOT_FOLLOW_SYMLINK) {
+  if (follow == FollowSymlink::DO_NOT_FOLLOW_SYMLINK) {
     Try<::internal::windows::SymbolicLink> symlink =
       ::internal::windows::query_symbolic_link_data(path);
 
@@ -163,11 +163,11 @@ inline Try<long> mtime(
 
 inline Try<mode_t> mode(
     const std::string& path,
-    const FollowSymlink follow = FOLLOW_SYMLINK)
+    const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
 {
   struct _stat s;
 
-  if (follow == DO_NOT_FOLLOW_SYMLINK && islink(path)) {
+  if (follow == FollowSymlink::DO_NOT_FOLLOW_SYMLINK && islink(path)) {
     return Error("lstat not supported for symlink '" + path + "'");
   }
 
@@ -181,11 +181,11 @@ inline Try<mode_t> mode(
 
 inline Try<dev_t> dev(
     const std::string& path,
-    const FollowSymlink follow = FOLLOW_SYMLINK)
+    const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
 {
   struct _stat s;
 
-  if (follow == DO_NOT_FOLLOW_SYMLINK && islink(path)) {
+  if (follow == FollowSymlink::DO_NOT_FOLLOW_SYMLINK && islink(path)) {
     return Error("lstat not supported for symlink '" + path + "'");
   }
 
@@ -199,11 +199,11 @@ inline Try<dev_t> dev(
 
 inline Try<ino_t> inode(
     const std::string& path,
-    const FollowSymlink follow = FOLLOW_SYMLINK)
+    const FollowSymlink follow = FollowSymlink::FOLLOW_SYMLINK)
 {
   struct _stat s;
 
-  if (follow == DO_NOT_FOLLOW_SYMLINK) {
+  if (follow == FollowSymlink::DO_NOT_FOLLOW_SYMLINK) {
       return Error("Non-following stat not supported for '" + path + "'");
   }
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/841f8793/3rdparty/stout/tests/os_tests.cpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/tests/os_tests.cpp b/3rdparty/stout/tests/os_tests.cpp
index 7f785b0..b6491c4 100644
--- a/3rdparty/stout/tests/os_tests.cpp
+++ b/3rdparty/stout/tests/os_tests.cpp
@@ -39,15 +39,18 @@
 #include <stout/hashset.hpp>
 #include <stout/numify.hpp>
 #include <stout/os.hpp>
+#include <stout/stopwatch.hpp>
+#include <stout/strings.hpp>
+#include <stout/try.hpp>
+#include <stout/uuid.hpp>
+
 #include <stout/os/environment.hpp>
 #include <stout/os/int_fd.hpp>
 #include <stout/os/kill.hpp>
 #include <stout/os/killtree.hpp>
+#include <stout/os/stat.hpp>
+#include <stout/os/stat.hpp>
 #include <stout/os/write.hpp>
-#include <stout/stopwatch.hpp>
-#include <stout/strings.hpp>
-#include <stout/try.hpp>
-#include <stout/uuid.hpp>
 
 #if defined(__APPLE__) || defined(__FreeBSD__)
 #include <stout/os/sysctl.hpp>
@@ -62,6 +65,8 @@ using os::Fork;
 using os::Process;
 using os::ProcessTree;
 
+using os::stat::FollowSymlink;
+
 using std::list;
 using std::set;
 using std::string;
@@ -222,8 +227,10 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(OsTest, SYMLINK_Size)
 
   // The reported file size should be the same whether following links
   // or not, given that the input parameter is not a link.
-  EXPECT_SOME_EQ(size, os::stat::size(file, os::stat::FOLLOW_SYMLINK));
-  EXPECT_SOME_EQ(size, os::stat::size(file, os::stat::DO_NOT_FOLLOW_SYMLINK));
+  EXPECT_SOME_EQ(size,
+      os::stat::size(file, FollowSymlink::FOLLOW_SYMLINK));
+  EXPECT_SOME_EQ(size,
+      os::stat::size(file, FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
 
   EXPECT_ERROR(os::stat::size("aFileThatDoesNotExist"));
 
@@ -232,11 +239,11 @@ TEST_F_TEMP_DISABLED_ON_WINDOWS(OsTest, SYMLINK_Size)
   ASSERT_SOME(fs::symlink(file, link));
 
   // Following links we expect the file's size, not the link's.
-  EXPECT_SOME_EQ(size, os::stat::size(link, os::stat::FOLLOW_SYMLINK));
+  EXPECT_SOME_EQ(size, os::stat::size(link, FollowSymlink::FOLLOW_SYMLINK));
 
   // Not following links, we expect the string length of the linked path.
   EXPECT_SOME_EQ(Bytes(file.size()),
-                 os::stat::size(link, os::stat::DO_NOT_FOLLOW_SYMLINK));
+      os::stat::size(link, FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
 }
 
 
@@ -756,8 +763,6 @@ TEST_F(OsTest, User)
 
 TEST_F(OsTest, SYMLINK_Chown)
 {
-  using os::stat::DO_NOT_FOLLOW_SYMLINK;
-
   Result<uid_t> uid = os::getuid();
   ASSERT_SOME(uid);
 
@@ -783,33 +788,46 @@ TEST_F(OsTest, SYMLINK_Chown)
   // symlink does not chown that subtree.
   EXPECT_SOME(fs::symlink("chown/one/two", "two.link"));
   EXPECT_SOME(os::chown(9, 9, "two.link", true));
-  EXPECT_SOME_EQ(9u, os::stat::uid("two.link", DO_NOT_FOLLOW_SYMLINK));
-  EXPECT_SOME_EQ(0u, os::stat::uid("chown", DO_NOT_FOLLOW_SYMLINK));
+  EXPECT_SOME_EQ(9u,
+      os::stat::uid("two.link", FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
+  EXPECT_SOME_EQ(0u,
+      os::stat::uid("chown", FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
   EXPECT_SOME_EQ(0u,
-      os::stat::uid("chown/one/two/three/file", DO_NOT_FOLLOW_SYMLINK));
+      os::stat::uid("chown/one/two/three/file",
+                    FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
 
   // Recursively chown the whole tree.
   EXPECT_SOME(os::chown(9, 9, "chown", true));
-  EXPECT_SOME_EQ(9u, os::stat::uid("chown", DO_NOT_FOLLOW_SYMLINK));
   EXPECT_SOME_EQ(9u,
-      os::stat::uid("chown/one/two/three/file", DO_NOT_FOLLOW_SYMLINK));
+      os::stat::uid("chown", FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
   EXPECT_SOME_EQ(9u,
-      os::stat::uid("chown/one/two/three/link", DO_NOT_FOLLOW_SYMLINK));
+      os::stat::uid("chown/one/two/three/file",
+                    FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
+  EXPECT_SOME_EQ(9u,
+      os::stat::uid("chown/one/two/three/link",
+                    FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
 
   // Chown the subtree with the embedded link back and verify that it
   // doesn't follow back to the top of the tree.
   EXPECT_SOME(os::chown(0, 0, "chown/one/two/three", true));
-  EXPECT_SOME_EQ(9u, os::stat::uid("chown", DO_NOT_FOLLOW_SYMLINK));
+  EXPECT_SOME_EQ(9u,
+      os::stat::uid("chown", FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
   EXPECT_SOME_EQ(0u,
-      os::stat::uid("chown/one/two/three", DO_NOT_FOLLOW_SYMLINK));
+      os::stat::uid("chown/one/two/three",
+                    FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
   EXPECT_SOME_EQ(0u,
-      os::stat::uid("chown/one/two/three/link", DO_NOT_FOLLOW_SYMLINK));
+      os::stat::uid("chown/one/two/three/link",
+                    FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
 
   // Verify that non-recursive chown changes the directory and not
   // its contents.
   EXPECT_SOME(os::chown(0, 0, "chown/one", false));
-  EXPECT_SOME_EQ(0u, os::stat::uid("chown/one", DO_NOT_FOLLOW_SYMLINK));
-  EXPECT_SOME_EQ(9u, os::stat::uid("chown/one/file", DO_NOT_FOLLOW_SYMLINK));
+  EXPECT_SOME_EQ(0u,
+      os::stat::uid("chown/one",
+                    FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
+  EXPECT_SOME_EQ(9u,
+      os::stat::uid("chown/one/file",
+                    FollowSymlink::DO_NOT_FOLLOW_SYMLINK));
 }
 
 


[15/50] mesos git commit: Windows: Updated `CreateSymbolicLink()` to support long paths.

Posted by jo...@apache.org.
Windows: Updated `CreateSymbolicLink()` to support long paths.

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


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

Branch: refs/heads/master
Commit: d107bb7a0c00f7f747a04c490a8fe114bb371505
Parents: 28fd210
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Wed Jul 5 17:35:48 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:33 2017 -0700

----------------------------------------------------------------------
 .../stout/include/stout/internal/windows/reparsepoint.hpp | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/d107bb7a/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp b/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
index 61c4084..3a1ea16 100644
--- a/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
+++ b/3rdparty/stout/include/stout/internal/windows/reparsepoint.hpp
@@ -330,10 +330,12 @@ inline Try<Nothing> create_symbolic_link(
   // [1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa363866(v=vs.85).aspx
   static std::mutex adjust_privileges_mutex;
   synchronized(adjust_privileges_mutex) {
-    if (!::CreateSymbolicLink(
-        reparse_point.c_str(),  // path to the symbolic link
-        target.c_str(),        // symlink target
-        target_is_folder ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0)) {
+    if (!::CreateSymbolicLinkW(
+            // Path to link.
+            longpath(real_reparse_point_path.get()).data(),
+            // Path to target.
+            longpath(real_target_path.get()).data(),
+            target_is_folder ? SYMBOLIC_LINK_FLAG_DIRECTORY : 0)) {
       return WindowsError(
           "'internal::windows::create_symbolic_link': 'CreateSymbolicLink' "
           "call failed");


[31/50] mesos git commit: Added `map` explict cast to `Envp`.

Posted by jo...@apache.org.
Added `map<string, string>` explict cast to `Envp`.

This is needed for implementations that expect a `map<string, string>`
over a `char **`.

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


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

Branch: refs/heads/master
Commit: 92ab3286e6332a96019d8058acf946b768ddbde9
Parents: eac6cf4
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 14:26:22 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:36 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/os/raw/environment.hpp | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/92ab3286/3rdparty/stout/include/stout/os/raw/environment.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/raw/environment.hpp b/3rdparty/stout/include/stout/os/raw/environment.hpp
index c7f889f..51c93f5 100644
--- a/3rdparty/stout/include/stout/os/raw/environment.hpp
+++ b/3rdparty/stout/include/stout/os/raw/environment.hpp
@@ -121,10 +121,12 @@ class Envp
 public:
   Envp(Envp&& that)
     : envp(that.envp),
-      size(that.size)
+      size(that.size),
+      environment(that.environment)
   {
     that.envp = nullptr;
     that.size = 0;
+    that.environment = std::map<std::string, std::string>();
   }
 
   template <typename Map>
@@ -137,6 +139,7 @@ public:
     size_t index = 0;
 
     for (auto it = map.begin(); it != map.end(); ++it) {
+      environment[stringify(it->first)] = stringify(it->second);
       std::string entry = stringify(it->first) + "=" + stringify(it->second);
       envp[index] = new char[entry.size() + 1];
       ::memcpy(envp[index], entry.c_str(), entry.size() + 1);
@@ -157,6 +160,7 @@ public:
     foreachpair (const std::string& key,
                  const JSON::Value& value,
                  object.values) {
+      environment[key] = stringify(value.as<JSON::String>().value);
       std::string entry = key + "=" + value.as<JSON::String>().value;
       envp[index] = new char[entry.size() + 1];
       ::memcpy(envp[index], entry.c_str(), entry.size() + 1);
@@ -183,12 +187,18 @@ public:
     return envp;
   }
 
+  operator std::map<std::string, std::string>()
+  {
+    return environment;
+  }
+
 private:
   Envp(const Envp&) = delete;
   Envp& operator=(const Envp&) = delete;
 
   char **envp;
   size_t size;
+  std::map<std::string, std::string> environment;
 };
 
 } // namespace raw {


[25/50] mesos git commit: Windows: Updated `os::temp()` to use UTF-16 syscalls.

Posted by jo...@apache.org.
Windows: Updated `os::temp()` to use UTF-16 syscalls.

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


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

Branch: refs/heads/master
Commit: ffe2f2dc04f7835525bd52aafff911fb3839b133
Parents: 6f30623
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 07:33:35 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:35 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/os/windows/temp.hpp | 13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/ffe2f2dc/3rdparty/stout/include/stout/os/windows/temp.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/windows/temp.hpp b/3rdparty/stout/include/stout/os/windows/temp.hpp
index 639f1aa..9cf467f 100644
--- a/3rdparty/stout/include/stout/os/windows/temp.hpp
+++ b/3rdparty/stout/include/stout/os/windows/temp.hpp
@@ -14,7 +14,9 @@
 #define __STOUT_OS_WINDOWS_TEMP_HPP__
 
 #include <string>
+#include <vector>
 
+#include <stout/stringify.hpp>
 #include <stout/windows.hpp>
 
 
@@ -27,15 +29,18 @@ namespace os {
 // where none of these are found, this function returns the current directory.
 inline std::string temp()
 {
-  char temp_folder[MAX_PATH + 2];
-  if (::GetTempPath(MAX_PATH + 2, temp_folder) == 0) {
-    if (::GetCurrentDirectory(MAX_PATH + 2, temp_folder) == 0) {
+  size_t size = static_cast<size_t>(MAX_PATH) + 2;
+  std::vector<wchar_t> buffer;
+  buffer.reserve(size);
+  if (::GetTempPathW(static_cast<DWORD>(size), buffer.data()) == 0) {
+    // Failed, use current directory.
+    if (::GetCurrentDirectoryW(static_cast<DWORD>(size), buffer.data()) == 0) {
       // Failed, use relative path.
       return ".";
     }
   }
 
-  return std::string(temp_folder);
+  return stringify(std::wstring(buffer.data()));
 }
 
 } // namespace os {


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

Posted by jo...@apache.org.
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))
 {


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

Posted by jo...@apache.org.
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))
 {


[49/50] mesos git commit: Windows: Set Unicode compilation flags.

Posted by jo...@apache.org.
Windows: Set Unicode compilation flags.

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


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

Branch: refs/heads/master
Commit: 4b9daa2954006cdeadc6e1a436f820f714351886
Parents: 3373452
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 15:54:21 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:40 2017 -0700

----------------------------------------------------------------------
 cmake/CompilationConfigure.cmake | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/4b9daa29/cmake/CompilationConfigure.cmake
----------------------------------------------------------------------
diff --git a/cmake/CompilationConfigure.cmake b/cmake/CompilationConfigure.cmake
index 3fa2e2f..437300f 100644
--- a/cmake/CompilationConfigure.cmake
+++ b/cmake/CompilationConfigure.cmake
@@ -248,9 +248,9 @@ if (WIN32)
   # NOTE: We APPEND ${CRT} rather than REPLACE so it gets picked up by
   # dependencies.
   foreach (lang C CXX)
-    # Enable multi-threaded compilation.
+    # Enable multi-threaded and UNICODE compilation.
     # NOTE: We do not add CRT here because dependencies will use it incorrectly.
-    string(APPEND CMAKE_${lang}_FLAGS " /MP")
+    string(APPEND CMAKE_${lang}_FLAGS " /MP -DUNICODE -D_UNICODE")
 
     # Debug library for debug configuration.
     string(APPEND CMAKE_${lang}_FLAGS_DEBUG "${CRT}d")


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

Posted by jo...@apache.org.
Windows: Updated `os::open()` to support long paths.

The CRT library can support long paths on Windows, if the Unicode
versions of the APIs are used, and the long path prefix is prepended to
the path.

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


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

Branch: refs/heads/master
Commit: 7367901d53db0fe6430db93b0a8d3c90598e3228
Parents: e1abdf9
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Sat Jul 8 19:22:07 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:34 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/os/open.hpp | 10 ++++++++++
 1 file changed, 10 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/7367901d/3rdparty/stout/include/stout/os/open.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/open.hpp b/3rdparty/stout/include/stout/os/open.hpp
index ceff89f..c9346c6 100644
--- a/3rdparty/stout/include/stout/os/open.hpp
+++ b/3rdparty/stout/include/stout/os/open.hpp
@@ -25,6 +25,11 @@
 #include <stout/os/close.hpp>
 #include <stout/os/int_fd.hpp>
 
+#ifdef __WINDOWS__
+#include <stout/windows.hpp>
+#include <stout/internal/windows/longpath.hpp>
+#endif // __WINDOWS__
+
 // For old systems that do not support O_CLOEXEC, we still want
 // os::open to accept that flag so that we can simplify the code.
 #ifndef O_CLOEXEC
@@ -70,7 +75,12 @@ inline Try<int_fd> open(const std::string& path, int oflag, mode_t mode = 0)
   }
 #endif
 
+#ifdef __WINDOWS__
+  std::wstring longpath = ::internal::windows::longpath(path);
+  int_fd fd = ::_wopen(longpath.data(), oflag, mode);
+#else
   int_fd fd = ::open(path.c_str(), oflag, mode);
+#endif // __WINDOWS__
   if (fd < 0) {
     return ErrnoError();
   }


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

Posted by jo...@apache.org.
Windows: Updated `os::exists()` to support long paths.

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


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

Branch: refs/heads/master
Commit: 4f6719f6c422d002aa8edb61fa5489f64290a799
Parents: dd87bd4
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Wed Jul 5 10:52:48 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:32 2017 -0700

----------------------------------------------------------------------
 .../stout/include/stout/os/windows/exists.hpp   | 23 ++++++++------------
 1 file changed, 9 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/4f6719f6/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 42b8a9d..7c8c85c 100644
--- a/3rdparty/stout/include/stout/os/windows/exists.hpp
+++ b/3rdparty/stout/include/stout/os/windows/exists.hpp
@@ -15,9 +15,10 @@
 
 #include <string>
 
+#include <stout/error.hpp>
 #include <stout/windows.hpp>
 
-#include <stout/os/realpath.hpp>
+#include <stout/internal/windows/longpath.hpp>
 
 
 namespace os {
@@ -25,21 +26,15 @@ namespace os {
 
 inline bool exists(const std::string& path)
 {
-  Result<std::string> absolutePath = os::realpath(path);
-
-  if (!absolutePath.isSome()) {
-    return false;
-  }
-
-  // NOTE: `GetFileAttributes` redirects to either `GetFileAttributesA`
-  // (ASCII) or `GetFileAttributesW` (for `wchar`s). It returns
-  // `INVALID_FILE_ATTRIBUTES` if the file could not be opened for any reason.
-  // Checking for one of two 'not found' error codes (`ERROR_FILE_NOT_FOUND` or
-  // `ERROR_PATH_NOT_FOUND`) is a reliable test for whether the file or
-  // directory exists. See also [1] for more information on this technique.
+  // NOTE: `GetFileAttributes` returns `INVALID_FILE_ATTRIBUTES` if the file
+  // could not be opened for any reason. Checking for one of two 'not found'
+  // error codes (`ERROR_FILE_NOT_FOUND` or `ERROR_PATH_NOT_FOUND`) is a
+  // reliable test for whether the file or directory exists. See also [1] for
+  // more information on this technique.
   //
   // [1] http://blogs.msdn.com/b/oldnewthing/archive/2007/10/23/5612082.aspx
-  DWORD attributes = GetFileAttributes(absolutePath.get().c_str());
+  const DWORD attributes = ::GetFileAttributesW(
+      ::internal::windows::longpath(path).data());
 
   if (attributes == INVALID_FILE_ATTRIBUTES) {
     DWORD error = GetLastError();


[32/50] mesos git commit: Added `vector` explicit cast to `Argv`.

Posted by jo...@apache.org.
Added `vector<string>` explicit cast to `Argv`.

This is needed for implementations that expect a `vector<string>`
instead of a `char **`.

This includes a slight refactoring because storing a
`vector<string>` is very similar to the current `Argv`
implementation, which uses a `vector<char*>` local variable.

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


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

Branch: refs/heads/master
Commit: eac6cf4ad54d975f69efb08d98ca39b81779cb1a
Parents: 0fb02c8
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 11:27:53 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:36 2017 -0700

----------------------------------------------------------------------
 3rdparty/stout/include/stout/gtest.hpp       |  3 ++-
 3rdparty/stout/include/stout/os/raw/argv.hpp | 29 ++++++++++++-----------
 2 files changed, 17 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/eac6cf4a/3rdparty/stout/include/stout/gtest.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/gtest.hpp b/3rdparty/stout/include/stout/gtest.hpp
index 1df5eaf..a8ae3d9 100644
--- a/3rdparty/stout/include/stout/gtest.hpp
+++ b/3rdparty/stout/include/stout/gtest.hpp
@@ -226,7 +226,8 @@ template <typename T1, typename T2>
 #ifndef __WINDOWS__
 #define SLEEP_COMMAND(x) "sleep " #x
 #else
-#define SLEEP_COMMAND(x) "powershell -NoProfile -Command Start-Sleep " #x
+#define SLEEP_COMMAND(x) \
+  "powershell -NoProfile -Command Start-Sleep -Seconds " #x
 #endif // __WINDOWS__
 
 

http://git-wip-us.apache.org/repos/asf/mesos/blob/eac6cf4a/3rdparty/stout/include/stout/os/raw/argv.hpp
----------------------------------------------------------------------
diff --git a/3rdparty/stout/include/stout/os/raw/argv.hpp b/3rdparty/stout/include/stout/os/raw/argv.hpp
index 58e5ee2..5e7711b 100644
--- a/3rdparty/stout/include/stout/os/raw/argv.hpp
+++ b/3rdparty/stout/include/stout/os/raw/argv.hpp
@@ -39,37 +39,38 @@ public:
   template <typename Iterable>
   explicit Argv(const Iterable& iterable)
   {
-    std::vector<char*> _argv;
     foreach (const std::string& arg, iterable) {
-      char* _arg = new char[arg.size() + 1];
-      ::memcpy(_arg, arg.c_str(), arg.size() + 1);
-      _argv.emplace_back(_arg);
+      args.emplace_back(arg);
     }
 
-    size = _argv.size();
-    argv = new char*[size + 1];
-    for (size_t i = 0; i < size; i++) {
-      argv[i] = _argv[i];
+    argv = new char*[args.size() + 1];
+    for (size_t i = 0; i < args.size(); i++) {
+      argv[i] = const_cast<char*>(args[i].c_str());
     }
-    argv[size] = nullptr;
+
+    argv[args.size()] = nullptr;
   }
 
   ~Argv()
   {
-    for (size_t i = 0; i < size; i++) {
-      delete[] argv[i];
-    }
     delete[] argv;
   }
 
-  operator char**()
+  operator char**() const
   {
     return argv;
   }
 
+  operator std::vector<std::string>() const
+  {
+    return args;
+  }
+
 private:
+  std::vector<std::string> args;
+
+  // NOTE: This points to strings in the vector `args`.
   char** argv;
-  size_t size;
 };
 
 } // namespace raw {


[36/50] mesos git commit: Windows: Updated use of `getSystemEnvironment` in containerizer.

Posted by jo...@apache.org.
Windows: Updated use of `getSystemEnvironment` in containerizer.

This function was moved to stout and renamed to
`get_system_env`.

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


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

Branch: refs/heads/master
Commit: 3ec06c6816019b9681103178745b5b106efe8cce
Parents: 4b28a28
Author: Andrew Schwartzmeyer <an...@schwartzmeyer.com>
Authored: Mon Jul 10 14:37:35 2017 -0700
Committer: Joseph Wu <jo...@apache.org>
Committed: Mon Jul 10 17:15:37 2017 -0700

----------------------------------------------------------------------
 src/slave/containerizer/docker.cpp       | 2 +-
 src/slave/containerizer/mesos/launch.cpp | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/3ec06c68/src/slave/containerizer/docker.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/docker.cpp b/src/slave/containerizer/docker.cpp
index 5cd3b6d..2fe9227 100644
--- a/src/slave/containerizer/docker.cpp
+++ b/src/slave/containerizer/docker.cpp
@@ -1427,7 +1427,7 @@ Future<pid_t> DockerContainerizerProcess::launchExecutorProcess(
   // applications to not work, but upon overriding system defaults, it becomes
   // the overidder's problem.
   Option<map<std::wstring, std::wstring>> systemEnvironment =
-    process::internal::getSystemEnvironment();
+    ::internal::windows::get_system_env();
   foreachpair(const std::wstring& key,
               const std::wstring& value,
               systemEnvironment.get()) {

http://git-wip-us.apache.org/repos/asf/mesos/blob/3ec06c68/src/slave/containerizer/mesos/launch.cpp
----------------------------------------------------------------------
diff --git a/src/slave/containerizer/mesos/launch.cpp b/src/slave/containerizer/mesos/launch.cpp
index 973b248..8e66293 100644
--- a/src/slave/containerizer/mesos/launch.cpp
+++ b/src/slave/containerizer/mesos/launch.cpp
@@ -711,7 +711,7 @@ int MesosContainerizerLaunch::execute()
     // cause applications to not work, but upon overriding system defaults, it
     // becomes the overidder's problem.
     Option<std::map<std::wstring, std::wstring>> systemEnvironment =
-      process::internal::getSystemEnvironment();
+      ::internal::windows::get_system_env();
     foreachpair (const std::wstring& key,
                  const std::wstring& value,
                  systemEnvironment.get()) {