aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/cpp/util/file_windows.cc
diff options
context:
space:
mode:
authorGravatar Laszlo Csomor <laszlocsomor@google.com>2017-01-18 10:58:17 +0000
committerGravatar Vladimir Moskva <vladmos@google.com>2017-01-18 11:02:24 +0000
commita669557945cf610317307c770a76ed4c53a53f58 (patch)
tree5e711577a1f2c2a5623fc35975f9c5764331dd14 /src/main/cpp/util/file_windows.cc
parentaf0b670d9906e96ae41f55bb3b9b8698d425a1dc (diff)
Bazel client, Windows: use CreateFileW
Use CreateFileW in blaze_util_windows.cc when opening the "jvm.out" file. This allows supporting long paths. Also use AsWindowsPathWithUncPrefix instead of just AsWindowsPath plus manually adding the UNC prefix. Also fix a compilation error in file_windows_test.cc, I'm surprised the CI system didn't catch this, maybe we aren't running this test there. See https://github.com/bazelbuild/bazel/issues/2107 See https://github.com/bazelbuild/bazel/issues/2181 -- PiperOrigin-RevId: 144813245 MOS_MIGRATED_REVID=144813245
Diffstat (limited to 'src/main/cpp/util/file_windows.cc')
-rw-r--r--src/main/cpp/util/file_windows.cc20
1 files changed, 16 insertions, 4 deletions
diff --git a/src/main/cpp/util/file_windows.cc b/src/main/cpp/util/file_windows.cc
index 5848e48d16..de3bd2800e 100644
--- a/src/main/cpp/util/file_windows.cc
+++ b/src/main/cpp/util/file_windows.cc
@@ -52,9 +52,6 @@ static bool IsDirectoryW(const wstring& path);
// necessary.
static bool UnlinkPathW(const wstring& path);
-// Like `AsWindowsPath` but the result is absolute and has UNC prefix if needed.
-static bool AsWindowsPathWithUncPrefix(const string& path, wstring* wpath);
-
static bool IsRootDirectoryW(const wstring& path);
static bool MakeDirectoriesW(const wstring& path);
@@ -293,6 +290,21 @@ void MsysRoot::InitIfNecessary() {
}
}
+// Converts a UTF8-encoded `path` to a normalized, widechar Windows path.
+//
+// Returns true if conversion succeeded and sets the contents of `result` to it.
+//
+// The `path` may be absolute or relative, and may be a Windows or MSYS path.
+// In every case, the output is normalized (see NormalizeWindowsPath).
+// The output won't have a UNC prefix, even if `path` did.
+//
+// Recognizes the drive letter in MSYS paths, so e.g. "/c/windows" becomes
+// "c:\windows". Prepends the MSYS root (computed from the BAZEL_SH envvar) to
+// absolute MSYS paths, so e.g. "/usr" becomes "c:\tools\msys64\usr".
+//
+// The result may be longer than MAX_PATH. It's the caller's responsibility to
+// prepend the UNC prefix in case they need to pass it to a WinAPI function
+// (some require the prefix, some don't), or to quote the path if necessary.
bool AsWindowsPath(const string& path, wstring* result) {
if (path.empty()) {
result->clear();
@@ -332,7 +344,7 @@ bool AsWindowsPath(const string& path, wstring* result) {
return true;
}
-static bool AsWindowsPathWithUncPrefix(const string& path, wstring* wpath) {
+bool AsWindowsPathWithUncPrefix(const string& path, wstring* wpath) {
if (IsDevNull(path)) {
wpath->assign(L"NUL");
return true;