aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2017-03-09 08:43:41 +0000
committerGravatar Vladimir Moskva <vladmos@google.com>2017-03-09 10:30:38 +0000
commit52ab7d960dab8d5e1003490d4230b9b23c57a492 (patch)
tree889b2e0173db061badfded440d9c54e40e67a125 /src/main/cpp
parent561e4498139da2742314a85930011cb4db4d7879 (diff)
Bazel client, Windows: CreateDirectoryW path limit
Fix the path limit for non-UNC-prefixed paths when using CreateDirectoryW. According to MSDN [1], this is only 248 chars, as opposed to the usual 260 (MAX_PATH). See https://github.com/bazelbuild/bazel/issues/2107 [1] https://msdn.microsoft.com/en-us/library/windows/desktop/aa363855(v=vs.85).aspx -- PiperOrigin-RevId: 149627964 MOS_MIGRATED_REVID=149627964
Diffstat (limited to 'src/main/cpp')
-rw-r--r--src/main/cpp/util/file_platform.h3
-rw-r--r--src/main/cpp/util/file_windows.cc13
2 files changed, 10 insertions, 6 deletions
diff --git a/src/main/cpp/util/file_platform.h b/src/main/cpp/util/file_platform.h
index 7733e7a5c5..50b75de3bb 100644
--- a/src/main/cpp/util/file_platform.h
+++ b/src/main/cpp/util/file_platform.h
@@ -205,7 +205,8 @@ void ForEachDirectoryEntry(const std::string &path,
#if defined(COMPILER_MSVC) || defined(__CYGWIN__)
// Like `AsWindowsPath` but the result is absolute and has UNC prefix if needed.
-bool AsWindowsPathWithUncPrefix(const std::string &path, std::wstring *wpath);
+bool AsWindowsPathWithUncPrefix(const std::string &path, std::wstring *wpath,
+ size_t max_path = 260 /* MAX_PATH */);
// Same as `AsWindowsPath`, but returns a lowercase 8dot3 style shortened path.
// Result will never have a UNC prefix, nor a trailing "/" or "\".
diff --git a/src/main/cpp/util/file_windows.cc b/src/main/cpp/util/file_windows.cc
index f763f9ef48..5159917eb4 100644
--- a/src/main/cpp/util/file_windows.cc
+++ b/src/main/cpp/util/file_windows.cc
@@ -101,8 +101,8 @@ static bool HasDriveSpecifierPrefix(const char_type* ch) {
return CharTraits<char_type>::IsAlpha(ch[0]) && ch[1] == ':';
}
-static void AddUncPrefixMaybe(wstring* path) {
- if (path->size() >= MAX_PATH && !HasUncPrefix(path->c_str())) {
+static void AddUncPrefixMaybe(wstring* path, size_t max_path = MAX_PATH) {
+ if (path->size() >= max_path && !HasUncPrefix(path->c_str())) {
*path = wstring(L"\\\\?\\") + *path;
}
}
@@ -483,7 +483,8 @@ bool AsWindowsPath(const string& path, wstring* result) {
return true;
}
-bool AsWindowsPathWithUncPrefix(const string& path, wstring* wpath) {
+bool AsWindowsPathWithUncPrefix(const string& path, wstring* wpath,
+ size_t max_path) {
if (IsDevNull(path)) {
wpath->assign(L"NUL");
return true;
@@ -497,7 +498,7 @@ bool AsWindowsPathWithUncPrefix(const string& path, wstring* wpath) {
if (!IsAbsolute(path)) {
wpath->assign(wstring(GetCwdW().get()) + L"\\" + *wpath);
}
- AddUncPrefixMaybe(wpath);
+ AddUncPrefixMaybe(wpath, max_path);
return true;
}
@@ -1120,7 +1121,9 @@ bool MakeDirectories(const string& path, unsigned int mode) {
return false;
}
wstring wpath;
- if (!AsWindowsPathWithUncPrefix(path, &wpath)) {
+ // According to MSDN, CreateDirectory's limit without the UNC prefix is
+ // 248 characters (so it could fit another filename before reaching MAX_PATH).
+ if (!AsWindowsPathWithUncPrefix(path, &wpath, 248)) {
return false;
}
return MakeDirectoriesW(wpath);