mirror of
https://github.com/uutils/coreutils
synced 2024-07-23 19:04:18 +00:00
uucore: migrate from winapi
to windows-sys
crate
This commit is contained in:
parent
0f2067f0b9
commit
76ee0db26c
79
Cargo.lock
generated
79
Cargo.lock
generated
|
@ -869,7 +869,7 @@ dependencies = [
|
|||
"cfg-if",
|
||||
"libc",
|
||||
"redox_syscall",
|
||||
"windows-sys",
|
||||
"windows-sys 0.36.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1264,7 +1264,7 @@ dependencies = [
|
|||
"libc",
|
||||
"log",
|
||||
"wasi",
|
||||
"windows-sys",
|
||||
"windows-sys 0.36.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1469,7 +1469,7 @@ dependencies = [
|
|||
"libc",
|
||||
"redox_syscall",
|
||||
"smallvec",
|
||||
"windows-sys",
|
||||
"windows-sys 0.36.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -1790,7 +1790,7 @@ dependencies = [
|
|||
"io-lifetimes",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
"windows-sys",
|
||||
"windows-sys 0.36.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -2029,7 +2029,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||
checksum = "8440c860cf79def6164e4a0a983bcc2305d82419177a0e0c71930d049e3ac5a1"
|
||||
dependencies = [
|
||||
"rustix",
|
||||
"windows-sys",
|
||||
"windows-sys 0.36.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
|
@ -3181,8 +3181,8 @@ dependencies = [
|
|||
"uucore_procs",
|
||||
"walkdir",
|
||||
"wild",
|
||||
"winapi",
|
||||
"winapi-util",
|
||||
"windows-sys 0.42.0",
|
||||
"z85",
|
||||
]
|
||||
|
||||
|
@ -3334,43 +3334,100 @@ version = "0.36.1"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ea04155a16a59f9eab786fe12a4a450e75cdb175f9e0d80da1e17db09f55b8d2"
|
||||
dependencies = [
|
||||
"windows_aarch64_msvc",
|
||||
"windows_i686_gnu",
|
||||
"windows_i686_msvc",
|
||||
"windows_x86_64_gnu",
|
||||
"windows_x86_64_msvc",
|
||||
"windows_aarch64_msvc 0.36.1",
|
||||
"windows_i686_gnu 0.36.1",
|
||||
"windows_i686_msvc 0.36.1",
|
||||
"windows_x86_64_gnu 0.36.1",
|
||||
"windows_x86_64_msvc 0.36.1",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows-sys"
|
||||
version = "0.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "5a3e1820f08b8513f676f7ab6c1f99ff312fb97b553d30ff4dd86f9f15728aa7"
|
||||
dependencies = [
|
||||
"windows_aarch64_gnullvm",
|
||||
"windows_aarch64_msvc 0.42.0",
|
||||
"windows_i686_gnu 0.42.0",
|
||||
"windows_i686_msvc 0.42.0",
|
||||
"windows_x86_64_gnu 0.42.0",
|
||||
"windows_x86_64_gnullvm",
|
||||
"windows_x86_64_msvc 0.42.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_gnullvm"
|
||||
version = "0.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "41d2aa71f6f0cbe00ae5167d90ef3cfe66527d6f613ca78ac8024c3ccab9a19e"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.36.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9bb8c3fd39ade2d67e9874ac4f3db21f0d710bee00fe7cab16949ec184eeaa47"
|
||||
|
||||
[[package]]
|
||||
name = "windows_aarch64_msvc"
|
||||
version = "0.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "dd0f252f5a35cac83d6311b2e795981f5ee6e67eb1f9a7f64eb4500fbc4dcdb4"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.36.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "180e6ccf01daf4c426b846dfc66db1fc518f074baa793aa7d9b9aaeffad6a3b6"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_gnu"
|
||||
version = "0.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "fbeae19f6716841636c28d695375df17562ca208b2b7d0dc47635a50ae6c5de7"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.36.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e2e7917148b2812d1eeafaeb22a97e4813dfa60a3f8f78ebe204bcc88f12f024"
|
||||
|
||||
[[package]]
|
||||
name = "windows_i686_msvc"
|
||||
version = "0.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "84c12f65daa39dd2babe6e442988fc329d6243fdce47d7d2d155b8d874862246"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.36.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4dcd171b8776c41b97521e5da127a2d86ad280114807d0b2ab1e462bc764d9e1"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnu"
|
||||
version = "0.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "bf7b1b21b5362cbc318f686150e5bcea75ecedc74dd157d874d754a2ca44b0ed"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_gnullvm"
|
||||
version = "0.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "09d525d2ba30eeb3297665bd434a54297e4170c7f1a44cad4ef58095b4cd2028"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.36.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c811ca4a8c853ef420abd8592ba53ddbbac90410fab6903b3e79972a631f7680"
|
||||
|
||||
[[package]]
|
||||
name = "windows_x86_64_msvc"
|
||||
version = "0.42.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f40009d85759725a34da6d89a94e63d7bdc50a862acf0dbc7c8e488f1edcb6f5"
|
||||
|
||||
[[package]]
|
||||
name = "xattr"
|
||||
version = "0.2.3"
|
||||
|
|
|
@ -45,16 +45,16 @@ clap = "4.0"
|
|||
once_cell = "1.13"
|
||||
|
||||
[target.'cfg(target_os = "windows")'.dependencies]
|
||||
winapi = { version = "0.3", features = ["errhandlingapi", "fileapi", "handleapi", "winerror"] }
|
||||
winapi-util = { version= "0.1.5", optional=true }
|
||||
windows-sys = { version = "0.42.0", optional = true, default-features = false, features = ["Win32_Storage_FileSystem", "Win32_Foundation", "Win32_System_WindowsProgramming"] }
|
||||
|
||||
[features]
|
||||
default = []
|
||||
# * non-default features
|
||||
encoding = ["data-encoding", "data-encoding-macro", "z85", "thiserror"]
|
||||
entries = ["libc"]
|
||||
fs = ["libc", "nix", "winapi-util"]
|
||||
fsext = ["libc", "nix", "time"]
|
||||
fs = ["libc", "nix", "winapi-util", "windows-sys"]
|
||||
fsext = ["libc", "nix", "time", "windows-sys"]
|
||||
lines = []
|
||||
memo = ["itertools"]
|
||||
mode = ["libc"]
|
||||
|
|
|
@ -81,9 +81,10 @@ impl FileInformation {
|
|||
let mut open_options = OpenOptions::new();
|
||||
let mut custom_flags = 0;
|
||||
if !dereference {
|
||||
custom_flags |= winapi::um::winbase::FILE_FLAG_OPEN_REPARSE_POINT;
|
||||
custom_flags |=
|
||||
windows_sys::Win32::Storage::FileSystem::FILE_FLAG_OPEN_REPARSE_POINT;
|
||||
}
|
||||
custom_flags |= winapi::um::winbase::FILE_FLAG_BACKUP_SEMANTICS;
|
||||
custom_flags |= windows_sys::Win32::Storage::FileSystem::FILE_FLAG_BACKUP_SEMANTICS;
|
||||
open_options.custom_flags(custom_flags);
|
||||
let file = open_options.read(true).open(path.as_ref())?;
|
||||
Self::from_file(&file)
|
||||
|
|
|
@ -32,18 +32,14 @@ use std::ffi::OsStr;
|
|||
#[cfg(windows)]
|
||||
use std::os::windows::ffi::OsStrExt;
|
||||
#[cfg(windows)]
|
||||
use winapi::shared::minwindef::DWORD;
|
||||
use windows_sys::Win32::Foundation::{ERROR_NO_MORE_FILES, INVALID_HANDLE_VALUE};
|
||||
#[cfg(windows)]
|
||||
use winapi::um::fileapi::GetDiskFreeSpaceW;
|
||||
#[cfg(windows)]
|
||||
use winapi::um::fileapi::{
|
||||
FindFirstVolumeW, FindNextVolumeW, FindVolumeClose, GetDriveTypeW, GetVolumeInformationW,
|
||||
GetVolumePathNamesForVolumeNameW, QueryDosDeviceW,
|
||||
use windows_sys::Win32::Storage::FileSystem::{
|
||||
FindFirstVolumeW, FindNextVolumeW, FindVolumeClose, GetDiskFreeSpaceW, GetDriveTypeW,
|
||||
GetVolumeInformationW, GetVolumePathNamesForVolumeNameW, QueryDosDeviceW,
|
||||
};
|
||||
#[cfg(windows)]
|
||||
use winapi::um::handleapi::INVALID_HANDLE_VALUE;
|
||||
#[cfg(windows)]
|
||||
use winapi::um::winbase::DRIVE_REMOTE;
|
||||
use windows_sys::Win32::System::WindowsProgramming::DRIVE_REMOTE;
|
||||
|
||||
// Warning: the pointer has to be used *immediately* or the Vec
|
||||
// it points to will be dropped!
|
||||
|
@ -265,7 +261,7 @@ impl MountInfo {
|
|||
.collect::<Vec<u16>>()
|
||||
.as_ptr(),
|
||||
dev_name_buf.as_mut_ptr(),
|
||||
dev_name_buf.len() as DWORD,
|
||||
dev_name_buf.len() as u32,
|
||||
)
|
||||
};
|
||||
volume_name.push('\\');
|
||||
|
@ -276,7 +272,7 @@ impl MountInfo {
|
|||
GetVolumePathNamesForVolumeNameW(
|
||||
String2LPWSTR!(volume_name),
|
||||
mount_root_buf.as_mut_ptr(),
|
||||
mount_root_buf.len() as DWORD,
|
||||
mount_root_buf.len() as u32,
|
||||
ptr::null_mut(),
|
||||
)
|
||||
};
|
||||
|
@ -296,7 +292,7 @@ impl MountInfo {
|
|||
ptr::null_mut(),
|
||||
ptr::null_mut(),
|
||||
fs_type_buf.as_mut_ptr(),
|
||||
fs_type_buf.len() as DWORD,
|
||||
fs_type_buf.len() as u32,
|
||||
)
|
||||
};
|
||||
let fs_type = if 0 != success {
|
||||
|
@ -443,9 +439,8 @@ pub fn read_fs_list() -> Result<Vec<MountInfo>, std::io::Error> {
|
|||
{
|
||||
let mut volume_name_buf = [0u16; MAX_PATH];
|
||||
// As recommended in the MS documentation, retrieve the first volume before the others
|
||||
let find_handle = unsafe {
|
||||
FindFirstVolumeW(volume_name_buf.as_mut_ptr(), volume_name_buf.len() as DWORD)
|
||||
};
|
||||
let find_handle =
|
||||
unsafe { FindFirstVolumeW(volume_name_buf.as_mut_ptr(), volume_name_buf.len() as u32) };
|
||||
if INVALID_HANDLE_VALUE == find_handle {
|
||||
crash!(
|
||||
EXIT_ERR,
|
||||
|
@ -467,12 +462,11 @@ pub fn read_fs_list() -> Result<Vec<MountInfo>, std::io::Error> {
|
|||
FindNextVolumeW(
|
||||
find_handle,
|
||||
volume_name_buf.as_mut_ptr(),
|
||||
volume_name_buf.len() as DWORD,
|
||||
volume_name_buf.len() as u32,
|
||||
)
|
||||
} {
|
||||
let err = IOError::last_os_error();
|
||||
if err.raw_os_error() != Some(winapi::shared::winerror::ERROR_NO_MORE_FILES as i32)
|
||||
{
|
||||
if err.raw_os_error() != Some(ERROR_NO_MORE_FILES as i32) {
|
||||
crash!(EXIT_ERR, "FindNextVolumeW failed: {}", err);
|
||||
}
|
||||
break;
|
||||
|
@ -524,7 +518,7 @@ impl FsUsage {
|
|||
//path_utf8.as_ptr(),
|
||||
String2LPWSTR!(path.as_os_str()),
|
||||
root_path.as_mut_ptr(),
|
||||
root_path.len() as DWORD,
|
||||
root_path.len() as u32,
|
||||
ptr::null_mut(),
|
||||
)
|
||||
};
|
||||
|
|
|
@ -6,8 +6,8 @@
|
|||
// * feature-gated external crates (re-shared as public internal modules)
|
||||
#[cfg(feature = "libc")]
|
||||
pub extern crate libc;
|
||||
#[cfg(feature = "winapi")]
|
||||
pub extern crate winapi;
|
||||
#[cfg(all(feature = "windows-sys", target_os = "windows"))]
|
||||
pub extern crate windows_sys;
|
||||
|
||||
//## internal modules
|
||||
|
||||
|
|
Loading…
Reference in a new issue