mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-01 12:24:15 +00:00
Use the windows crate facade consistently (#15737)
The initial motivation for this change was that we were using both the `windows`, the `window_sys` and the `windows_core` crate in various places. These crates have slightly unconventional versioning scheme where there is a large workspace with the same version in general, but only some crates get breaking releases when a new breaking release happens, the others stay on the previous breaking version. The `windows` crate is a shim for all three of them, with a single version. This simplifies handling the versions. Using `windows` over `windows_sys` has the advantage of a higher level error interface, we now get a `Result` for all windows API calls instead of C-style int-returns and get-last-error calls. This makes the uv-keyring crate more resilient. We keep using the `windows_registry` crate, which provides a higher level interface to windows registry access.
This commit is contained in:
parent
12764df8b2
commit
cd49e1d11f
15 changed files with 123 additions and 130 deletions
|
|
@ -24,9 +24,8 @@ tracing = { workspace = true }
|
|||
nix = { workspace = true }
|
||||
|
||||
[target.'cfg(windows)'.dependencies]
|
||||
windows = { workspace = true }
|
||||
windows-registry = { workspace = true }
|
||||
windows-result = { workspace = true }
|
||||
windows-sys = { workspace = true }
|
||||
|
||||
[dev-dependencies]
|
||||
fs-err = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -8,9 +8,9 @@ use std::path::Path;
|
|||
|
||||
use anyhow::Context;
|
||||
use tracing::warn;
|
||||
use windows::Win32::Foundation::{ERROR_FILE_NOT_FOUND, ERROR_INVALID_DATA};
|
||||
use windows::core::HRESULT;
|
||||
use windows_registry::{CURRENT_USER, HSTRING};
|
||||
use windows_result::HRESULT;
|
||||
use windows_sys::Win32::Foundation::{ERROR_FILE_NOT_FOUND, ERROR_INVALID_DATA};
|
||||
|
||||
use uv_static::EnvVars;
|
||||
|
||||
|
|
@ -60,13 +60,11 @@ fn get_windows_path_var() -> anyhow::Result<Option<HSTRING>> {
|
|||
let reg_value = environment.get_hstring(EnvVars::PATH);
|
||||
match reg_value {
|
||||
Ok(reg_value) => Ok(Some(reg_value)),
|
||||
Err(err) if err.code() == HRESULT::from_win32(ERROR_INVALID_DATA) => {
|
||||
Err(err) if err.code() == HRESULT::from(ERROR_INVALID_DATA) => {
|
||||
warn!("`HKEY_CURRENT_USER\\Environment\\PATH` is a non-string");
|
||||
Ok(None)
|
||||
}
|
||||
Err(err) if err.code() == HRESULT::from_win32(ERROR_FILE_NOT_FOUND) => {
|
||||
Ok(Some(HSTRING::new()))
|
||||
}
|
||||
Err(err) if err.code() == HRESULT::from(ERROR_FILE_NOT_FOUND) => Ok(Some(HSTRING::new())),
|
||||
Err(err) => Err(err.into()),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue