Skip to content
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

Don't always set GENERIC_READ when opening files on windows #1585

Merged
merged 1 commit into from
May 31, 2023
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
7 changes: 5 additions & 2 deletions src/common/file_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,16 @@ int64_t FileInfo::getFileSize() {

std::unique_ptr<FileInfo> FileUtils::openFile(const std::string& path, int flags) {
#if defined(_WIN32)
// Not providing GENERIC_READ seems to cause problems.
auto dwDesiredAccess = GENERIC_READ;
auto dwDesiredAccess = 0ul;
auto dwCreationDisposition = (flags & O_CREAT) ? OPEN_ALWAYS : OPEN_EXISTING;
auto dwShareMode = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE;
if (flags & (O_CREAT | O_WRONLY | O_RDWR)) {
dwDesiredAccess |= GENERIC_WRITE;
}
// O_RDONLY is 0 in practice, so flags & (O_RDONLY | O_RDWR) doesn't work.
if (!(flags & O_WRONLY)) {
dwDesiredAccess |= GENERIC_READ;
}

HANDLE handle = CreateFileA(path.c_str(), dwDesiredAccess, dwShareMode, nullptr,
dwCreationDisposition, FILE_ATTRIBUTE_NORMAL, nullptr);
Expand Down
Loading