Skip to content

Commit

Permalink
add win
Browse files Browse the repository at this point in the history
  • Loading branch information
ray6080 committed Sep 30, 2023
1 parent 4762664 commit 8450bf0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
10 changes: 9 additions & 1 deletion src/common/file_utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,15 @@ std::unique_ptr<FileInfo> FileUtils::openFile(
path, GetLastError(), std::system_category().message(GetLastError())));
}
if (lock_type != FileLockType::NO_LOCK) {
throw Exception("File lock is not supported on Win platform yet.");
DWORD dwFlags = lock_type == FileLockType::READ_LOCK ?
LOCKFILE_FAIL_IMMEDIATELY :
LOCKFILE_FAIL_IMMEDIATELY | LOCKFILE_EXCLUSIVE_LOCK;
OVERLAPPED overlapped = {0};
overlapped.Offset = 0;
BOOL rc = LockFileEx(handle, dwFlags, 0, 0, 0, &overlapped);
if (!rc) {
throw Exception("Could not set lock on file : " + path);
}
}
return std::make_unique<FileInfo>(path, handle);
#else
Expand Down
5 changes: 0 additions & 5 deletions src/main/database.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,6 @@ void Database::setLoggingLevel(std::string loggingLevel) {
}

void Database::openLockFile() {
#ifdef _WIN_32_
if (systemConfig.accessMode != AccessMode::READ_WRITE) {
throw Exception("Can only open database under the default READ_WRITE mode on Windows.");
}
#endif
int flags;
FileLockType lock;
auto lockFilePath = StorageUtils::getLockFilePath(databasePath);
Expand Down

0 comments on commit 8450bf0

Please sign in to comment.