From 8b661296ba1ce62d64fdf1798a5590846a5691cd Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Fri, 1 Jul 2022 14:11:27 -0700 Subject: [PATCH] Migrate from winapi to windows-sys. (#42) --- CHANGELOG.md | 1 + Cargo.toml | 15 ++++++++------- src/fs.rs | 15 +++++++-------- src/portable.rs | 4 ++-- 4 files changed, 18 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index eb382de..ed3fe2c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # unreleased - Added feature to enable use of rayon. +- Migrated from winapi to windows-sys # 0.5.2 diff --git a/Cargo.toml b/Cargo.toml index 78fbf85..ab3c307 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -31,13 +31,14 @@ cfg-if = "1.0.0" log = "0.4.11" num_cpus = { version = "1.13", optional = true } rayon = { version = "1.4", optional = true } -winapi = { version = "0.3", features = [ - "std", - "errhandlingapi", - "winerror", - "fileapi", - "winbase", -] } + +[target.'cfg(windows)'.dependencies.windows-sys] +version = "0.36.0" +features = [ + "Win32_Foundation", + "Win32_Storage_FileSystem", + "Win32_System_SystemServices", +] [target.'cfg(not(windows))'.dependencies] libc = "0.2" diff --git a/src/fs.rs b/src/fs.rs index 87311b3..239f5b1 100644 --- a/src/fs.rs +++ b/src/fs.rs @@ -1,6 +1,7 @@ use std::{ fs::{self, OpenOptions}, io, + ffi::c_void, mem::size_of, os::windows::prelude::*, path::{Path, PathBuf}, @@ -8,11 +9,9 @@ use std::{ #[cfg(feature = "parallel")] use rayon::prelude::*; -use winapi::shared::minwindef::*; -use winapi::um::fileapi::*; -use winapi::um::minwinbase::*; -use winapi::um::winbase::*; -use winapi::um::winnt::*; +use windows_sys::Win32::System::SystemServices::*; +use windows_sys::Win32::Storage::FileSystem::*; +use windows_sys::Win32::Foundation::HANDLE; /// Reliably removes a directory and all of its children. /// @@ -146,13 +145,13 @@ fn delete_readonly(metadata: fs::Metadata, path: &Path) -> io::Result<()> { file.set_permissions(perms)?; let mut info = FILE_DISPOSITION_INFO { - DeleteFile: TRUE as u8, + DeleteFileA: true as u8, }; let result = unsafe { SetFileInformationByHandle( - file.as_raw_handle(), + file.as_raw_handle() as HANDLE, FileDispositionInfo, - &mut info as *mut FILE_DISPOSITION_INFO as LPVOID, + &mut info as *mut FILE_DISPOSITION_INFO as *mut c_void, size_of::() as u32, ) }; diff --git a/src/portable.rs b/src/portable.rs index 4ffb7c7..d4f3443 100644 --- a/src/portable.rs +++ b/src/portable.rs @@ -49,8 +49,8 @@ mod test { cfg_if::cfg_if! { if #[cfg(windows)] { - const ENOTDIR:i32 = winapi::shared::winerror::ERROR_DIRECTORY as i32; - const ENOENT:i32 = winapi::shared::winerror::ERROR_FILE_NOT_FOUND as i32; + const ENOTDIR:i32 = windows_sys::Win32::Foundation::ERROR_DIRECTORY as i32; + const ENOENT:i32 = windows_sys::Win32::Foundation::ERROR_FILE_NOT_FOUND as i32; } else { const ENOTDIR:i32 = libc::ENOTDIR; const ENOENT:i32 = libc::ENOENT;