mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-08-03 06:27:45 +00:00
du: migrate winapi
to windows-sys
crate
This commit is contained in:
parent
45dea119fa
commit
c26bf02a04
3 changed files with 14 additions and 21 deletions
2
Cargo.lock
generated
2
Cargo.lock
generated
|
@ -2367,7 +2367,7 @@ dependencies = [
|
|||
"clap 4.0.17",
|
||||
"glob",
|
||||
"uucore",
|
||||
"winapi",
|
||||
"windows-sys 0.42.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
|
|
@ -22,7 +22,7 @@ clap = { version = "4.0", features = ["wrap_help", "cargo"] }
|
|||
uucore = { version=">=0.0.16", package="uucore", path="../../uucore" }
|
||||
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
winapi = { version="0.3", features=[] }
|
||||
windows-sys = { version = "0.42.0", default-features = false, features = ["Win32_Storage_FileSystem", "Win32_Foundation"] }
|
||||
|
||||
[[bin]]
|
||||
name = "du"
|
||||
|
|
|
@ -41,15 +41,12 @@ use uucore::format_usage;
|
|||
use uucore::parse_glob;
|
||||
use uucore::parse_size::{parse_size, ParseSizeError};
|
||||
#[cfg(windows)]
|
||||
use winapi::shared::minwindef::{DWORD, LPVOID};
|
||||
use windows_sys::Win32::Foundation::HANDLE;
|
||||
#[cfg(windows)]
|
||||
use winapi::um::fileapi::{FILE_ID_INFO, FILE_STANDARD_INFO};
|
||||
#[cfg(windows)]
|
||||
use winapi::um::minwinbase::{FileIdInfo, FileStandardInfo};
|
||||
#[cfg(windows)]
|
||||
use winapi::um::winbase::GetFileInformationByHandleEx;
|
||||
#[cfg(windows)]
|
||||
use winapi::um::winnt::FILE_ID_128;
|
||||
use windows_sys::Win32::Storage::FileSystem::{
|
||||
FileIdInfo, FileStandardInfo, GetFileInformationByHandleEx, FILE_ID_128, FILE_ID_INFO,
|
||||
FILE_STANDARD_INFO,
|
||||
};
|
||||
|
||||
mod options {
|
||||
pub const HELP: &str = "help";
|
||||
|
@ -208,21 +205,19 @@ fn get_size_on_disk(path: &Path) -> u64 {
|
|||
Err(_) => return size_on_disk, // opening directories will fail
|
||||
};
|
||||
|
||||
let handle = file.as_raw_handle();
|
||||
|
||||
unsafe {
|
||||
let mut file_info: FILE_STANDARD_INFO = core::mem::zeroed();
|
||||
let file_info_ptr: *mut FILE_STANDARD_INFO = &mut file_info;
|
||||
|
||||
let success = GetFileInformationByHandleEx(
|
||||
handle,
|
||||
file.as_raw_handle() as HANDLE,
|
||||
FileStandardInfo,
|
||||
file_info_ptr as LPVOID,
|
||||
std::mem::size_of::<FILE_STANDARD_INFO>() as DWORD,
|
||||
file_info_ptr as _,
|
||||
std::mem::size_of::<FILE_STANDARD_INFO>() as u32,
|
||||
);
|
||||
|
||||
if success != 0 {
|
||||
size_on_disk = *file_info.AllocationSize.QuadPart() as u64;
|
||||
size_on_disk = file_info.AllocationSize as u64;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -238,17 +233,15 @@ fn get_file_info(path: &Path) -> Option<FileInfo> {
|
|||
Err(_) => return result,
|
||||
};
|
||||
|
||||
let handle = file.as_raw_handle();
|
||||
|
||||
unsafe {
|
||||
let mut file_info: FILE_ID_INFO = core::mem::zeroed();
|
||||
let file_info_ptr: *mut FILE_ID_INFO = &mut file_info;
|
||||
|
||||
let success = GetFileInformationByHandleEx(
|
||||
handle,
|
||||
file.as_raw_handle() as HANDLE,
|
||||
FileIdInfo,
|
||||
file_info_ptr as LPVOID,
|
||||
std::mem::size_of::<FILE_ID_INFO>() as DWORD,
|
||||
file_info_ptr as _,
|
||||
std::mem::size_of::<FILE_ID_INFO>() as u32,
|
||||
);
|
||||
|
||||
if success != 0 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue