Skip to content

Commit e9704e1

Browse files
committed
Update Win::touch to fix race conditions.
1 parent 1ff6ebf commit e9704e1

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

tiledb/sm/filesystem/win.cc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,6 @@ Status Win::create_dir(const std::string& path) const {
159159
}
160160

161161
Status Win::touch(const std::string& filename) const {
162-
if (is_file(filename)) {
163-
return Status::Ok();
164-
}
165-
166162
HANDLE file_h = CreateFile(
167163
filename.c_str(),
168164
GENERIC_WRITE,
@@ -178,6 +174,10 @@ Status Win::touch(const std::string& filename) const {
178174
tiledb::common::ScopedExecutor onexit1(closefileonexit);
179175
if (file_h == INVALID_HANDLE_VALUE) {
180176
auto gle = GetLastError();
177+
if (gle == ERROR_FILE_EXISTS) {
178+
// Do not fail if the file already exists.
179+
return Status::Ok();
180+
}
181181
return LOG_STATUS(Status_IOError(
182182
std::string("Failed to create file '") + filename + " (" +
183183
get_last_error_msg(gle, "CreateFile") + ")'"));

0 commit comments

Comments
 (0)