do some clean up

This commit is contained in:
hzlinyiyu 2023-01-31 18:02:57 +08:00
parent 4ae3576c42
commit ae91d4ed41
17 changed files with 69 additions and 67 deletions

View File

@ -84,25 +84,16 @@ rustc-workspace-hack = "1.0.0"
[target.'cfg(windows)'.dependencies]
fwdansi = "1.1.0"
[target.'cfg(windows)'.dependencies.winapi]
version = "0.3"
[target.'cfg(windows)'.dependencies.windows-sys]
version = "0.45"
features = [
"basetsd",
"handleapi",
"jobapi",
"jobapi2",
"memoryapi",
"minwindef",
"ntdef",
"ntstatus",
"processenv",
"processthreadsapi",
"psapi",
"synchapi",
"winerror",
"winbase",
"wincon",
"winnt",
"Win32_Foundation",
"Win32_Storage_FileSystem",
"Win32_System_IO",
"Win32_System_Threading",
"Win32_System_JobObjects",
"Win32_Security",
"Win32_System_SystemServices"
]
[dev-dependencies]

View File

@ -29,7 +29,7 @@ toml_edit = { version = "0.15.0", features = ["serde", "easy", "perf"] }
url = "2.2.2"
[target.'cfg(windows)'.dependencies]
winapi = "0.3"
windows-sys = { version = "0.45.0", features = ["Win32_Storage_FileSystem"] }
[features]
deny-warnings = []

View File

@ -305,7 +305,7 @@ pub fn windows_reserved_names_are_allowed() -> bool {
use std::ffi::OsStr;
use std::os::windows::ffi::OsStrExt;
use std::ptr;
use winapi::um::fileapi::GetFullPathNameW;
use windows_sys::Win32::Storage::FileSystem::GetFullPathNameW;
let test_file_name: Vec<_> = OsStr::new("aux.rs").encode_wide().collect();

View File

@ -25,4 +25,4 @@ core-foundation = { version = "0.9.0", features = ["mac_os_10_7_support"] }
[target.'cfg(windows)'.dependencies]
miow = "0.5.0"
winapi = { version = "0.3.9", features = ["consoleapi", "minwindef"] }
windows-sys = { version = "0.45.0", features = ["Win32_Storage_FileSystem", "Win32_Foundation", "Win32_System_Console"] }

View File

@ -701,8 +701,9 @@ fn exclude_from_content_indexing(path: &Path) {
{
use std::iter::once;
use std::os::windows::prelude::OsStrExt;
use winapi::um::fileapi::{GetFileAttributesW, SetFileAttributesW};
use winapi::um::winnt::FILE_ATTRIBUTE_NOT_CONTENT_INDEXED;
use windows_sys::Win32::Storage::FileSystem::{
GetFileAttributesW, SetFileAttributesW, FILE_ATTRIBUTE_NOT_CONTENT_INDEXED,
};
let path: Vec<u16> = path.as_os_str().encode_wide().chain(once(0)).collect();
unsafe {

View File

@ -606,10 +606,10 @@ mod imp {
use super::{ProcessBuilder, ProcessError};
use anyhow::Result;
use std::io;
use winapi::shared::minwindef::{BOOL, DWORD, FALSE, TRUE};
use winapi::um::consoleapi::SetConsoleCtrlHandler;
use windows_sys::Win32::Foundation::{BOOL, FALSE, TRUE};
use windows_sys::Win32::System::Console::SetConsoleCtrlHandler;
unsafe extern "system" fn ctrlc_handler(_: DWORD) -> BOOL {
unsafe extern "system" fn ctrlc_handler(_: u32) -> BOOL {
// Do nothing; let the child process handle it.
TRUE
}
@ -626,7 +626,7 @@ mod imp {
}
pub fn command_line_too_big(err: &io::Error) -> bool {
use winapi::shared::winerror::ERROR_FILENAME_EXCED_RANGE;
use windows_sys::Win32::Foundation::ERROR_FILENAME_EXCED_RANGE;
err.raw_os_error() == Some(ERROR_FILENAME_EXCED_RANGE as i32)
}
}

View File

@ -140,11 +140,10 @@ pub fn exit_status_to_string(status: ExitStatus) -> String {
#[cfg(windows)]
fn status_to_string(status: ExitStatus) -> String {
use winapi::shared::minwindef::DWORD;
use winapi::um::winnt::*;
use windows_sys::Win32::Foundation::*;
let mut base = status.to_string();
let extra = match status.code().unwrap() as DWORD {
let extra = match status.code().unwrap() as i32 {
STATUS_ACCESS_VIOLATION => "STATUS_ACCESS_VIOLATION",
STATUS_IN_PAGE_ERROR => "STATUS_IN_PAGE_ERROR",
STATUS_INVALID_HANDLE => "STATUS_INVALID_HANDLE",

View File

@ -84,7 +84,7 @@ mod imp {
use miow::iocp::{CompletionPort, CompletionStatus};
use miow::pipe::NamedPipe;
use miow::Overlapped;
use winapi::shared::winerror::ERROR_BROKEN_PIPE;
use windows_sys::Win32::Foundation::ERROR_BROKEN_PIPE;
struct Pipe<'a> {
dst: &'a mut Vec<u8>,

View File

@ -8,4 +8,4 @@ description = "A Cargo credential process that stores tokens with Windows Creden
[dependencies]
cargo-credential = { version = "0.2.0", path = "../cargo-credential" }
winapi = { version = "0.3.9", features = ["wincred", "winerror", "impl-default"] }
windows-sys = { version = "0.45", features = [] }

View File

@ -16,10 +16,5 @@ readme = "README.md"
repository = "https://github.com/brson/home"
description = "Shared definitions of home directories"
[target."cfg(windows)".dependencies.winapi]
version = "0.3"
features = [
"shlobj",
"std",
"winerror",
]
[target."cfg(windows)".dependencies]
windows-sys = { version = "0.45.0", features = ["Win32_Foundation", "Win32_UI_Shell"] }

View File

@ -30,7 +30,7 @@
pub mod env;
#[cfg(windows)]
#[cfg(target_os(windows))]
mod windows;
use std::io;

View File

@ -4,9 +4,8 @@ use std::os::windows::ffi::OsStringExt;
use std::path::PathBuf;
use std::ptr;
use winapi::shared::minwindef::MAX_PATH;
use winapi::shared::winerror::S_OK;
use winapi::um::shlobj::{SHGetFolderPathW, CSIDL_PROFILE};
use windows_sys::Win32::Foundation::{MAX_PATH, S_OK};
use windows_sys::Win32::UI::Shell::{SHGetFolderPathW, CSIDL_PROFILE};
pub fn home_dir_inner() -> Option<PathBuf> {
env::var_os("USERPROFILE")

View File

@ -812,7 +812,7 @@ impl<'a, 'cfg> FeatureResolver<'a, 'cfg> {
true
})
.flat_map(|dep| {
// Each `dep`endency can be built for multiple targets. For one, it
// Each dependency can be built for multiple targets. For one, it
// may be a library target which is built as initially configured
// by `fk`. If it appears as build dependency, it must be built
// for the host.

View File

@ -557,12 +557,17 @@ mod imp {
#[cfg(windows)]
mod imp {
use std::{cmp, mem, ptr};
use winapi::um::fileapi::*;
use winapi::um::handleapi::*;
use winapi::um::processenv::*;
use winapi::um::winbase::*;
use winapi::um::wincon::*;
use winapi::um::winnt::*;
use windows_sys::core::PCSTR;
use windows_sys::Win32::Foundation::CloseHandle;
use windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE;
use windows_sys::Win32::Storage::FileSystem::{
CreateFileA, FILE_SHARE_READ, FILE_SHARE_WRITE, OPEN_EXISTING,
};
use windows_sys::Win32::System::Console::{
GetConsoleScreenBufferInfo, GetStdHandle, CONSOLE_SCREEN_BUFFER_INFO, STD_ERROR_HANDLE,
};
use windows_sys::Win32::System::SystemServices::{GENERIC_READ, GENERIC_WRITE};
pub(super) use super::{default_err_erase_line as err_erase_line, TtyWidth};
@ -578,7 +583,7 @@ mod imp {
// INVALID_HANDLE_VALUE. Use an alternate method which works
// in that case as well.
let h = CreateFileA(
"CONOUT$\0".as_ptr() as *const CHAR,
"CONOUT$\0".as_ptr() as PCSTR,
GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE,
ptr::null_mut(),

View File

@ -190,8 +190,9 @@ mod imp {
mod imp {
use std::io;
use std::mem;
use winapi::shared::minwindef::*;
use winapi::um::processthreadsapi::*;
use windows_sys::Win32::Foundation::FILETIME;
use windows_sys::Win32::System::Threading::GetSystemTimes;
pub struct State {
idle: FILETIME,

View File

@ -437,10 +437,11 @@ mod sys {
use std::mem;
use std::os::windows::io::AsRawHandle;
use winapi::shared::minwindef::DWORD;
use winapi::shared::winerror::{ERROR_INVALID_FUNCTION, ERROR_LOCK_VIOLATION};
use winapi::um::fileapi::{LockFileEx, UnlockFile};
use winapi::um::minwinbase::{LOCKFILE_EXCLUSIVE_LOCK, LOCKFILE_FAIL_IMMEDIATELY};
use windows_sys::Win32::Foundation::HANDLE;
use windows_sys::Win32::Foundation::{ERROR_INVALID_FUNCTION, ERROR_LOCK_VIOLATION};
use windows_sys::Win32::Storage::FileSystem::{
LockFileEx, UnlockFile, LOCKFILE_EXCLUSIVE_LOCK, LOCKFILE_FAIL_IMMEDIATELY,
};
pub(super) fn lock_shared(file: &File) -> Result<()> {
lock_file(file, 0)
@ -470,7 +471,7 @@ mod sys {
pub(super) fn unlock(file: &File) -> Result<()> {
unsafe {
let ret = UnlockFile(file.as_raw_handle(), 0, 0, !0, !0);
let ret = UnlockFile(file.as_raw_handle() as HANDLE, 0, 0, !0, !0);
if ret == 0 {
Err(Error::last_os_error())
} else {
@ -479,10 +480,17 @@ mod sys {
}
}
fn lock_file(file: &File, flags: DWORD) -> Result<()> {
fn lock_file(file: &File, flags: u32) -> Result<()> {
unsafe {
let mut overlapped = mem::zeroed();
let ret = LockFileEx(file.as_raw_handle(), flags, 0, !0, !0, &mut overlapped);
let ret = LockFileEx(
file.as_raw_handle() as HANDLE,
flags,
0,
!0,
!0,
&mut overlapped,
);
if ret == 0 {
Err(Error::last_os_error())
} else {

View File

@ -47,12 +47,15 @@ mod imp {
use log::info;
use winapi::shared::minwindef::*;
use winapi::um::handleapi::*;
use winapi::um::jobapi2::*;
use winapi::um::processthreadsapi::*;
use winapi::um::winnt::HANDLE;
use winapi::um::winnt::*;
use windows_sys::Win32::Foundation::CloseHandle;
use windows_sys::Win32::Foundation::HANDLE;
use windows_sys::Win32::Foundation::INVALID_HANDLE_VALUE;
use windows_sys::Win32::System::JobObjects::AssignProcessToJobObject;
use windows_sys::Win32::System::JobObjects::CreateJobObjectW;
use windows_sys::Win32::System::JobObjects::JobObjectExtendedLimitInformation;
use windows_sys::Win32::System::JobObjects::SetInformationJobObject;
use windows_sys::Win32::System::JobObjects::JOBOBJECT_EXTENDED_LIMIT_INFORMATION;
use windows_sys::Win32::System::Threading::GetCurrentProcess;
pub struct Setup {
job: Handle,
@ -77,7 +80,7 @@ mod imp {
// we're otherwise part of someone else's job object in this case.
let job = CreateJobObjectW(ptr::null_mut(), ptr::null());
if job.is_null() {
if job == INVALID_HANDLE_VALUE {
return None;
}
let job = Handle { inner: job };