summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorClement Tsang <34804052+ClementTsang@users.noreply.github.com>2023-08-22 17:27:36 -0400
committerGitHub <noreply@github.com>2023-08-22 17:27:36 -0400
commitac55add21e88939d78c23e9be99ff5f38f5a461e (patch)
tree20f6fa0028b26b766f99016c53a3650f9934ba08
parent2e2b32ce7120713d62017a4957a3a58b06fd609d (diff)
deps: bump windows to 0.51.1 (#1279)
* deps: bump windows to 0.51.1 * some changes to fit new API
-rw-r--r--Cargo.lock14
-rw-r--r--Cargo.toml2
-rw-r--r--src/app/data_harvester/disks/windows/bindings.rs54
-rw-r--r--src/app/data_harvester/memory/windows.rs3
-rw-r--r--src/app/process_killer.rs4
5 files changed, 32 insertions, 45 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 49a217e1..1c88ff9c 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1452,9 +1452,19 @@ checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows"
-version = "0.48.0"
+version = "0.51.1"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "ca229916c5ee38c2f2bc1e9d8f04df975b4bd93f9955dc69fabb5d91270045c9"
+dependencies = [
+ "windows-core",
+ "windows-targets",
+]
+
+[[package]]
+name = "windows-core"
+version = "0.51.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "e686886bc078bc1b0b600cac0147aadb815089b6e4da64016cbd754b6342700f"
+checksum = "f1f8cf84f35d2db49a46868f947758c7a1138116f7fac3bc844f43ade1292e64"
dependencies = [
"windows-targets",
]
diff --git a/Cargo.toml b/Cargo.toml
index 3ef11a54..2e0c7c2b 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -114,7 +114,7 @@ core-foundation = "0.9.3"
mach2 = "0.4.1"
[target.'cfg(target_os = "windows")'.dependencies]
-windows = { version = "0.48.0", features = [
+windows = { version = "0.51.1", features = [
"Win32_Foundation",
"Win32_Security",
"Win32_Storage_FileSystem",
diff --git a/src/app/data_harvester/disks/windows/bindings.rs b/src/app/data_harvester/disks/windows/bindings.rs
index 247c6b6d..c5436145 100644
--- a/src/app/data_harvester/disks/windows/bindings.rs
+++ b/src/app/data_harvester/disks/windows/bindings.rs
@@ -9,9 +9,9 @@ use std::{
use anyhow::bail;
use windows::Win32::{
- Foundation::{self, CloseHandle},
+ Foundation::{self, CloseHandle, HANDLE},
Storage::FileSystem::{
- CreateFileW, FindFirstVolumeW, FindNextVolumeW, FindVolumeClose, FindVolumeHandle,
+ CreateFileW, FindFirstVolumeW, FindNextVolumeW, FindVolumeClose,
GetVolumeNameForVolumeMountPointW, FILE_FLAGS_AND_ATTRIBUTES, FILE_SHARE_READ,
FILE_SHARE_WRITE, OPEN_EXISTING,
},
@@ -77,28 +77,12 @@ fn volume_io(volume: &Path) -> anyhow::Result<DISK_PERFORMANCE> {
// SAFETY: This should be safe, we will check the result as well.
let handle_result = unsafe { CloseHandle(h_device) };
- if !handle_result.as_bool() {
- const ERROR_INVALID_FUNCTION: i32 = Foundation::ERROR_INVALID_FUNCTION.0 as i32;
- const ERROR_NOT_SUPPORTED: i32 = Foundation::ERROR_NOT_SUPPORTED.0 as i32;
-
- match io::Error::last_os_error().raw_os_error() {
- Some(ERROR_INVALID_FUNCTION) => {
- bail!("Handle error: invalid function");
- }
- Some(ERROR_NOT_SUPPORTED) => {
- bail!("Handle error: not supported");
- }
- _ => {
- bail!(
- "Unknown handle device result error: {:?}",
- io::Error::last_os_error()
- );
- }
- }
+ if let Err(err) = handle_result {
+ bail!("Handle error: {err:?}");
}
- if !ret.as_bool() {
- bail!("Device I/O error: {:?}", io::Error::last_os_error());
+ if let Err(err) = ret {
+ bail!("Device I/O error: {err:?}");
} else {
Ok(disk_performance)
}
@@ -111,15 +95,11 @@ fn current_volume(buffer: &[u16]) -> PathBuf {
PathBuf::from(path_string)
}
-fn close_find_handle(handle: FindVolumeHandle) -> anyhow::Result<()> {
+fn close_find_handle(handle: HANDLE) -> anyhow::Result<()> {
// Clean up the handle.
// SAFETY: This should be safe, we will check the result as well.
- let handle_result = unsafe { FindVolumeClose(handle) };
- if !handle_result.as_bool() {
- bail!("Could not close volume handle.");
- } else {
- Ok(())
- }
+ let res = unsafe { FindVolumeClose(handle) };
+ Ok(res?)
}
/// Returns the I/O for all volumes.
@@ -144,17 +124,18 @@ pub(crate) fn all_volume_io() -> anyhow::Result<Vec<anyhow::Result<(DISK_PERFORM
}
// Now iterate until there are no more volumes.
- while unsafe { FindNextVolumeW(handle, &mut buffer) }.as_bool() {
+ while unsafe { FindNextVolumeW(handle, &mut buffer) }.is_ok() {
let volume = current_volume(&buffer);
ret.push(volume_io(&volume).map(|res| (res, volume.to_string_lossy().to_string())));
}
let err = io::Error::last_os_error();
match err.raw_os_error() {
- // Iteration completed successfully, continue on.
- Some(ERROR_NO_MORE_FILES) => {}
- // Some error occured.
+ Some(ERROR_NO_MORE_FILES) => {
+ // Iteration completed successfully, continue on.
+ }
_ => {
+ // Some error occured.
close_find_handle(handle)?;
bail!("Error while iterating over volumes: {err:?}");
}
@@ -187,11 +168,8 @@ pub(crate) fn volume_name_from_mount(mount: &str) -> anyhow::Result<String> {
GetVolumeNameForVolumeMountPointW(windows::core::PCWSTR(mount.as_ptr()), &mut buffer)
};
- if !result.as_bool() {
- bail!(
- "Could not get volume name for mount point: {:?}",
- io::Error::last_os_error()
- );
+ if let Err(err) = result {
+ bail!("Could not get volume name for mount point: {err:?}");
} else {
Ok(current_volume(&buffer).to_string_lossy().to_string())
}
diff --git a/src/app/data_harvester/memory/windows.rs b/src/app/data_harvester/memory/windows.rs
index c54657e9..5925a756 100644
--- a/src/app/data_harvester/memory/windows.rs
+++ b/src/app/data_harvester/memory/windows.rs
@@ -1,6 +1,5 @@
use std::mem::{size_of, zeroed};
-use windows::Win32::Foundation::TRUE;
use windows::Win32::System::ProcessStatus::{GetPerformanceInfo, PERFORMANCE_INFORMATION};
use crate::data_harvester::memory::MemHarvest;
@@ -14,7 +13,7 @@ pub(crate) fn get_swap_usage() -> Option<MemHarvest> {
// the bindings are "safe" to use with how we call them.
unsafe {
let mut perf_info: PERFORMANCE_INFORMATION = zeroed();
- if GetPerformanceInfo(&mut perf_info, size_of::<PERFORMANCE_INFORMATION>() as u32) == TRUE {
+ if GetPerformanceInfo(&mut perf_info, size_of::<PERFORMANCE_INFORMATION>() as u32).is_ok() {
// Saturating sub by perf_info.PhysicalTotal for what sysinfo does.
let swap_total = perf_info.PageSize.saturating_mul(perf_info.CommitLimit) as u64;
let swap_used = perf_info.PageSize.saturating_mul(perf_info.CommitTotal) as u64;
diff --git a/src/app/process_killer.rs b/src/app/process_killer.rs
index aac85639..106419ee 100644
--- a/src/app/process_killer.rs
+++ b/src/app/process_killer.rs
@@ -29,7 +29,7 @@ impl Process {
fn kill(self) -> Result<(), String> {
// SAFETY: Windows API call, this is safe as we are passing in the handle.
let result = unsafe { TerminateProcess(self.0, 1) };
- if result.0 == 0 {
+ if result.is_err() {
return Err("process may have already been terminated.".to_string());
}
@@ -42,7 +42,7 @@ impl Drop for Process {
fn drop(&mut self) {
// SAFETY: Windows API call, this is safe as we are passing in the handle.
unsafe {
- CloseHandle(self.0);
+ let _ = CloseHandle(self.0);
}
}
}