Skip to content

Windows Filesystem fs::status Conditionally Call GetFileAttributes #78118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions llvm/lib/Support/Windows/Path.inc
Original file line number Diff line number Diff line change
Expand Up @@ -777,14 +777,16 @@ std::error_code status(const Twine &path, file_status &result, bool Follow) {
if (std::error_code ec = widenPath(path8, path_utf16))
return ec;

DWORD attr = ::GetFileAttributesW(path_utf16.begin());
if (attr == INVALID_FILE_ATTRIBUTES)
return getStatus(INVALID_HANDLE_VALUE, result);

DWORD Flags = FILE_FLAG_BACKUP_SEMANTICS;
// Handle reparse points.
if (!Follow && (attr & FILE_ATTRIBUTE_REPARSE_POINT))
Flags |= FILE_FLAG_OPEN_REPARSE_POINT;
if (!Follow) {
DWORD attr = ::GetFileAttributesW(path_utf16.begin());
if (attr == INVALID_FILE_ATTRIBUTES)
return getStatus(INVALID_HANDLE_VALUE, result);

// Handle reparse points.
if (attr & FILE_ATTRIBUTE_REPARSE_POINT)
Flags |= FILE_FLAG_OPEN_REPARSE_POINT;
}

ScopedFileHandle h(
::CreateFileW(path_utf16.begin(), 0, // Attributes only.
Expand Down