mirror of
https://github.com/astral-sh/uv.git
synced 2025-10-02 23:04:37 +00:00
Expand tildes when matching against PATH (#6829)
## Summary Closes https://github.com/astral-sh/uv/issues/6802.
This commit is contained in:
parent
0b16d10b27
commit
0ce6d75752
2 changed files with 17 additions and 2 deletions
|
@ -171,10 +171,25 @@ impl Shell {
|
||||||
|
|
||||||
/// Returns `true` if the given path is on the `PATH` in this shell.
|
/// Returns `true` if the given path is on the `PATH` in this shell.
|
||||||
pub fn contains_path(path: &Path) -> bool {
|
pub fn contains_path(path: &Path) -> bool {
|
||||||
|
let home_dir = home::home_dir();
|
||||||
std::env::var_os("PATH")
|
std::env::var_os("PATH")
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(std::env::split_paths)
|
.flat_map(std::env::split_paths)
|
||||||
|
.map(|path| {
|
||||||
|
// If the first component is `~`, expand to the home directory.
|
||||||
|
if let Some(home_dir) = home_dir.as_ref() {
|
||||||
|
if path
|
||||||
|
.components()
|
||||||
|
.next()
|
||||||
|
.map(std::path::Component::as_os_str)
|
||||||
|
== Some("~".as_ref())
|
||||||
|
{
|
||||||
|
return home_dir.join(path.components().skip(1).collect::<PathBuf>());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
path
|
||||||
|
})
|
||||||
.any(|p| same_file::is_same_file(path, p).unwrap_or(false))
|
.any(|p| same_file::is_same_file(path, p).unwrap_or(false))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue