Skip to content

Commit

Permalink
Migrate from winapi to windows-sys. (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
sunfishcode committed Jul 1, 2022
1 parent d224855 commit 8b66129
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# unreleased

- Added feature to enable use of rayon.
- Migrated from winapi to windows-sys

# 0.5.2

Expand Down
15 changes: 8 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
15 changes: 7 additions & 8 deletions src/fs.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
use std::{
fs::{self, OpenOptions},
io,
ffi::c_void,
mem::size_of,
os::windows::prelude::*,
path::{Path, PathBuf},
};

#[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.
///
Expand Down Expand Up @@ -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::<FILE_DISPOSITION_INFO>() as u32,
)
};
Expand Down
4 changes: 2 additions & 2 deletions src/portable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 8b66129

Please sign in to comment.