Avoid reading symlinks during `uv python install` on Windows (#10639)

Closes #10633
This commit is contained in:
Zanie Blue 2025-01-15 14:17:07 -06:00 committed by GitHub
parent 9736868908
commit 250b77e972
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 26 additions and 18 deletions

View File

@ -362,28 +362,36 @@ pub(crate) async fn install(
target.simplified_display()
);
// Check if the existing link is valid
let valid_link = target
.read_link()
.and_then(|target| target.try_exists())
.inspect_err(|err| debug!("Failed to inspect executable with error: {err}"))
.unwrap_or(true);
// Figure out what installation it references, if any
let existing = valid_link
.then(|| {
find_matching_bin_link(
installations
.iter()
.copied()
.chain(existing_installations.iter()),
&target,
)
})
.flatten();
let existing = find_matching_bin_link(
installations
.iter()
.copied()
.chain(existing_installations.iter()),
&target,
);
match existing {
None => {
// Determine if the link is valid, i.e., if it points to an existing
// Python we don't manage.
let valid_link = cfg!(unix)
.then(|| {
target
.read_link()
.and_then(|target| target.try_exists())
.inspect_err(|err| {
debug!(
"Failed to inspect executable with error: {err}"
);
})
// If we can't verify the link, assume it is valid.
.unwrap_or(true)
})
// On Windows, we just assume it is valid because symlinks are not
// common.
.unwrap_or(true);
// There's an existing executable we don't manage, require `--force`
if valid_link {
if !force {