Skip to content

Commit 827ced9

Browse files
committed
f Always use MoveFileExW
As we'll account for potentially open files via unique temp file names and locking, we should be good to always use `MoveFileExW`, which also gives us `fsync`-like properties via `MOVEFILE_WRITE_THROUGH`: "The function does not return until the file is actually moved on the disk. Setting this value guarantees that a move performed as a copy and delete operation is flushed to disk before the function returns. The flush occurs at the end of the copy operation."
1 parent fca4498 commit 827ced9

File tree

1 file changed

+7
-20
lines changed

1 file changed

+7
-20
lines changed

lightning-persister/src/fs_store.rs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -137,27 +137,14 @@ impl KVStore for FilesystemStore {
137137

138138
#[cfg(target_os = "windows")]
139139
{
140-
if dest_file_path.exists() {
141-
call!(unsafe {
142-
windows_sys::Win32::Storage::FileSystem::ReplaceFileW(
143-
path_to_windows_str(dest_file_path).as_ptr(),
144-
path_to_windows_str(tmp_file_path).as_ptr(),
145-
std::ptr::null(),
146-
windows_sys::Win32::Storage::FileSystem::REPLACEFILE_IGNORE_MERGE_ERRORS,
147-
std::ptr::null_mut() as *const core::ffi::c_void,
148-
std::ptr::null_mut() as *const core::ffi::c_void,
140+
call!(unsafe {
141+
windows_sys::Win32::Storage::FileSystem::MoveFileExW(
142+
path_to_windows_str(tmp_file_path).as_ptr(),
143+
path_to_windows_str(dest_file_path).as_ptr(),
144+
windows_sys::Win32::Storage::FileSystem::MOVEFILE_WRITE_THROUGH
145+
| windows_sys::Win32::Storage::FileSystem::MOVEFILE_REPLACE_EXISTING,
149146
)
150-
});
151-
} else {
152-
call!(unsafe {
153-
windows_sys::Win32::Storage::FileSystem::MoveFileExW(
154-
path_to_windows_str(tmp_file_path).as_ptr(),
155-
path_to_windows_str(dest_file_path).as_ptr(),
156-
windows_sys::Win32::Storage::FileSystem::MOVEFILE_WRITE_THROUGH
157-
| windows_sys::Win32::Storage::FileSystem::MOVEFILE_REPLACE_EXISTING,
158-
)
159-
});
160-
}
147+
});
161148
}
162149
}
163150

0 commit comments

Comments
 (0)