[llvm] Return `errc::no_such_file_or_directory` in `fs::access` if `GetFileAttributesW` fails (PR #83495)
Jeremy Day via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 19 10:54:17 PDT 2024
https://github.com/z2oh updated https://github.com/llvm/llvm-project/pull/83495
>From 61b89f30865165691cb717d39e60d2ed52ecc76d Mon Sep 17 00:00:00 2001
From: Jeremy Day <jeremy at thebrowser.company>
Date: Thu, 29 Feb 2024 11:41:42 -0800
Subject: [PATCH] Return errc::no_such_file_or_directory in fs::access if
GetFileAttributesW fails
---
llvm/lib/Support/Windows/Path.inc | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/llvm/lib/Support/Windows/Path.inc b/llvm/lib/Support/Windows/Path.inc
index 3e4c1f74161c6f..854d531ab371fc 100644
--- a/llvm/lib/Support/Windows/Path.inc
+++ b/llvm/lib/Support/Windows/Path.inc
@@ -623,6 +623,10 @@ std::error_code access(const Twine &Path, AccessMode Mode) {
DWORD Attributes = ::GetFileAttributesW(PathUtf16.begin());
if (Attributes == INVALID_FILE_ATTRIBUTES) {
+ // Avoid returning unexpected error codes when querying for existence.
+ if (Mode == AccessMode::Exist)
+ return errc::no_such_file_or_directory;
+
// See if the file didn't actually exist.
DWORD LastError = ::GetLastError();
if (LastError != ERROR_FILE_NOT_FOUND && LastError != ERROR_PATH_NOT_FOUND)
More information about the llvm-commits
mailing list