Skip to content

Commit 225e14e

Browse files
authored
[Support][Windows] Use the original path if GetFinalPathNameByHandleW() failed (#87749)
The commit f11b056 (#76304) breaks `clang` and other tools if they are used from a RAMDrive. `GetFinalPathNameByHandleW()` may return 0 and GetLastError 0x28. This patch fixes that issue. Note `real_path()` uses `openFileForRead()` but it reports the error only if failed to open a file. Getting `RealPath` is optional functionality. BTW, `sys::fs::real_path()` resolves not only symlinks, but also network drives and virtual drives created by the `subst` tool. It may break an automation. It is better to detect symlinks and resolve only symlinks.
1 parent e4169f7 commit 225e14e

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

llvm/lib/Support/Windows/Path.inc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,9 @@ std::string getMainExecutable(const char *argv0, void *MainExecAddr) {
157157

158158
SmallString<256> RealPath;
159159
sys::fs::real_path(PathNameUTF8, RealPath);
160-
return std::string(RealPath);
160+
if (RealPath.size())
161+
return std::string(RealPath);
162+
return std::string(PathNameUTF8.data());
161163
}
162164

163165
UniqueID file_status::getUniqueID() const {

0 commit comments

Comments
 (0)