Skip to content

Commit f45bfcc

Browse files
authored
Merge pull request #8513 from z2oh/z2oh/cherrypick-fix-windows-fs-access
[cherrypick stable/20240123] Return `errc::no_such_file_or_directory` in `fs::access` if `GetFileAttributesW` fails (llvm#83495)
2 parents 25f2be6 + 87156a3 commit f45bfcc

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

llvm/lib/Support/Windows/Path.inc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -629,6 +629,10 @@ std::error_code access(const Twine &Path, AccessMode Mode) {
629629
DWORD Attributes = ::GetFileAttributesW(PathUtf16.begin());
630630

631631
if (Attributes == INVALID_FILE_ATTRIBUTES) {
632+
// Avoid returning unexpected error codes when querying for existence.
633+
if (Mode == AccessMode::Exist)
634+
return errc::no_such_file_or_directory;
635+
632636
// See if the file didn't actually exist.
633637
DWORD LastError = ::GetLastError();
634638
if (LastError != ERROR_FILE_NOT_FOUND && LastError != ERROR_PATH_NOT_FOUND)

0 commit comments

Comments
 (0)