Skip to content

Commit bd8d9f0

Browse files
committed
f Switch to windows-sys crate
1 parent 5568d85 commit bd8d9f0

File tree

2 files changed

+15
-15
lines changed

2 files changed

+15
-15
lines changed

lightning-storage/Cargo.toml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,7 @@ lightning = { version = "0.0.116", path = "../lightning", default-features = fal
1818
libc = "0.2"
1919

2020
[target.'cfg(windows)'.dependencies]
21-
winapi = { version = "0.3", features = ["winbase"] }
21+
windows-sys = { version = "0.48.0", default-features = false, features = ["Win32_Storage_FileSystem", "Win32_Foundation"] }
22+
23+
[target.'cfg(ldk_bench)'.dependencies]
24+
criterion = { version = "0.4", optional = true, default-features = false }

lightning-storage/src/fs_store.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
//! Objects related to [`FilesystemStore`] live here.
2-
#[cfg(target_os = "windows")]
3-
extern crate winapi;
4-
52
use lightning::util::persist::KVStore;
63

74
use std::collections::HashMap;
@@ -28,7 +25,7 @@ macro_rules! call {
2825
}
2926

3027
#[cfg(target_os = "windows")]
31-
fn path_to_windows_str<T: AsRef<OsStr>>(path: T) -> Vec<winapi::shared::ntdef::WCHAR> {
28+
fn path_to_windows_str<T: AsRef<OsStr>>(path: T) -> Vec<u16> {
3229
path.as_ref().encode_wide().chain(Some(0)).collect()
3330
}
3431

@@ -116,33 +113,33 @@ impl KVStore for FilesystemStore {
116113
unsafe {
117114
libc::fsync(dir_file.as_raw_fd());
118115
}
116+
Ok(())
119117
}
120118

121119
#[cfg(target_os = "windows")]
122120
{
123121
if dest_file_path.exists() {
124-
unsafe {
125-
winapi::um::winbase::ReplaceFileW(
122+
call!(unsafe {
123+
windows_sys::Win32::Storage::FileSystem::ReplaceFileW(
126124
path_to_windows_str(dest_file_path).as_ptr(),
127125
path_to_windows_str(tmp_file_path).as_ptr(),
128126
std::ptr::null(),
129-
winapi::um::winbase::REPLACEFILE_IGNORE_MERGE_ERRORS,
130-
std::ptr::null_mut() as *mut winapi::ctypes::c_void,
131-
std::ptr::null_mut() as *mut winapi::ctypes::c_void,
127+
windows_sys::Win32::Storage::FileSystem::REPLACEFILE_IGNORE_MERGE_ERRORS,
128+
std::ptr::null_mut() as *const core::ffi::c_void,
129+
std::ptr::null_mut() as *const core::ffi::c_void,
132130
)
133-
};
131+
});
134132
} else {
135133
call!(unsafe {
136-
winapi::um::winbase::MoveFileExW(
134+
windows_sys::Win32::Storage::FileSystem::MoveFileExW(
137135
path_to_windows_str(tmp_file_path).as_ptr(),
138136
path_to_windows_str(dest_file_path).as_ptr(),
139-
winapi::um::winbase::MOVEFILE_WRITE_THROUGH
140-
| winapi::um::winbase::MOVEFILE_REPLACE_EXISTING,
137+
windows_sys::Win32::Storage::FileSystem::MOVEFILE_WRITE_THROUGH
138+
| windows_sys::Win32::Storage::FileSystem::MOVEFILE_REPLACE_EXISTING,
141139
)
142140
});
143141
}
144142
}
145-
Ok(())
146143
}
147144

148145
fn remove(&self, namespace: &str, key: &str) -> std::io::Result<()> {

0 commit comments

Comments
 (0)