Skip to content

Commit 48a1f0f

Browse files
authored
Merge pull request #8518 from z2oh/z2oh/cherrypick-fix-windows-fs-access-release-6.0
[cherrypick swift/release/6.0] Return `errc::no_such_file_or_directory` in `fs::access` if `GetFileAttributesW` fails
2 parents 72fc9c0 + 0ca426e commit 48a1f0f

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
@@ -630,6 +630,10 @@ std::error_code access(const Twine &Path, AccessMode Mode) {
630630
DWORD Attributes = ::GetFileAttributesW(PathUtf16.begin());
631631

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

0 commit comments

Comments
 (0)