Skip to content

Commit

Permalink
Correctly handle READ/WRITE/READ+WRITE flags on Windows
Browse files Browse the repository at this point in the history
  • Loading branch information
Mytherin committed Sep 20, 2021
1 parent 8d2805c commit 8e80101
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/common/local_file_system.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ unique_ptr<FileHandle> LocalFileSystem::OpenFile(const string &path, uint8_t fla
} else {
throw InternalException("READ, WRITE or both should be specified when opening a file");
}
if (flags & FileFlags::FILE_FLAGS_WRITE) {
if (open_write) {
// need Read or Write
D_ASSERT(flags & FileFlags::FILE_FLAGS_WRITE);
open_flags |= O_CLOEXEC;
Expand Down Expand Up @@ -463,14 +463,21 @@ unique_ptr<FileHandle> LocalFileSystem::OpenFile(const string &path, uint8_t fla
DWORD share_mode;
DWORD creation_disposition = OPEN_EXISTING;
DWORD flags_and_attributes = FILE_ATTRIBUTE_NORMAL | FILE_FLAG_OVERLAPPED;
if (flags & FileFlags::FILE_FLAGS_READ) {
bool open_read = flags & FileFlags::FILE_FLAGS_READ;
bool open_write = flags & FileFlags::FILE_FLAGS_WRITE;
if (open_read && open_write) {
desired_access = GENERIC_READ | GENERIC_WRITE;
share_mode = 0;
} else if (open_read) {
desired_access = GENERIC_READ;
share_mode = FILE_SHARE_READ;
} else {
// need Read or Write
D_ASSERT(flags & FileFlags::FILE_FLAGS_WRITE);
desired_access = GENERIC_READ | GENERIC_WRITE;
} else if (open_write) {
desired_access = GENERIC_WRITE;
share_mode = 0;
} else {
throw InternalException("READ, WRITE or both should be specified when opening a file");
}
if (open_write) {
if (flags & FileFlags::FILE_FLAGS_FILE_CREATE) {
creation_disposition = OPEN_ALWAYS;
} else if (flags & FileFlags::FILE_FLAGS_FILE_CREATE_NEW) {
Expand Down

0 comments on commit 8e80101

Please sign in to comment.