Skip to content

Commit

Permalink
Address review feedback on reparse points (#2288)
Browse files Browse the repository at this point in the history
See: #2284
  • Loading branch information
charliermarsh authored Mar 7, 2024
1 parent 996a859 commit f1e8b64
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 11 deletions.
2 changes: 2 additions & 0 deletions crates/uv-interpreter/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ thiserror = { workspace = true }
tokio = { workspace = true }
tracing = { workspace = true }
which = { workspace = true}

[target.'cfg(target_os = "windows")'.dependencies]
winapi = { workspace = true }

[dev-dependencies]
Expand Down
26 changes: 17 additions & 9 deletions crates/uv-interpreter/src/python_query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ fn find_python(
for name in possible_names.iter().flatten() {
if let Ok(paths) = which::which_in_global(&**name, Some(&path)) {
for path in paths {
#[cfg(windows)]
if windows::is_windows_store_shim(&path) {
continue;
}
Expand Down Expand Up @@ -226,13 +227,19 @@ fn find_executable<R: AsRef<OsStr> + Into<OsString> + Copy>(
// binary is executable and exists. It also has some extra logic that handles inconsistent casing on Windows
// and expands `~`.
for path in env::split_paths(&PATH) {
let mut paths = match which::which_in_global(requested, Some(&path)) {
let paths = match which::which_in_global(requested, Some(&path)) {
Ok(paths) => paths,
Err(which::Error::CannotFindBinaryPath) => continue,
Err(err) => return Err(Error::WhichError(requested.into(), err)),
};

if let Some(path) = paths.find(|path| !windows::is_windows_store_shim(path)) {
#[allow(clippy::never_loop)]
for path in paths {
#[cfg(windows)]
if windows::is_windows_store_shim(&path) {
continue;
}

return Ok(Some(path));
}
}
Expand Down Expand Up @@ -405,7 +412,7 @@ impl PythonVersionSelector {
}

mod windows {
use std::path::{Path, PathBuf};
use std::path::PathBuf;
use std::process::Command;

use once_cell::sync::Lazy;
Expand Down Expand Up @@ -491,7 +498,7 @@ mod windows {
///
/// See: <https://github.com/astral-sh/rye/blob/b0e9eccf05fe4ff0ae7b0250a248c54f2d780b4d/rye/src/cli/shim.rs#L108>
#[cfg(windows)]
pub(super) fn is_windows_store_shim(path: &Path) -> bool {
pub(super) fn is_windows_store_shim(path: &std::path::Path) -> bool {
use std::os::windows::fs::MetadataExt;
use std::os::windows::prelude::OsStrExt;
use winapi::um::fileapi::{CreateFileW, OPEN_EXISTING};
Expand Down Expand Up @@ -591,12 +598,13 @@ mod windows {
CloseHandle(reparse_handle);
}

success && String::from_utf16_lossy(&buf).contains("\\AppInstallerPythonRedirector.exe")
}
// If the operation failed, assume it's not a reparse point.
if !success {
return false;
}

#[cfg(not(windows))]
pub(super) fn is_windows_store_shim(_: &Path) -> bool {
false
let reparse_point = String::from_utf16_lossy(&buf[..bytes_returned as usize]);
reparse_point.contains("\\AppInstallerPythonRedirector.exe")
}

#[cfg(test)]
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@ url = { workspace = true }
which = { workspace = true }

[target.'cfg(target_os = "windows")'.dependencies]
mimalloc = "0.1.39"
mimalloc = { version = "0.1.39" }

[target.'cfg(all(not(target_os = "windows"), not(target_os = "openbsd"), any(target_arch = "x86_64", target_arch = "aarch64", target_arch = "powerpc64")))'.dependencies]
tikv-jemallocator = "0.5.4"
tikv-jemallocator = { version = "0.5.4" }

[dev-dependencies]
assert_cmd = { version = "2.0.14" }
Expand Down

0 comments on commit f1e8b64

Please sign in to comment.