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

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

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__