Revert "Work around $PATH issues under WSL (#10506)"

This reverts commit 3374692b91.
This commit is contained in:
Cuichen Li
2025-05-06 11:28:46 +08:00
committed by Peter Ammon
parent f1456f9707
commit 25b944e3e6

View File

@@ -2,7 +2,7 @@
//! for testing if a command with a given name can be found in the PATH, and various other
//! path-related issues.
use crate::common::{is_windows_subsystem_for_linux as is_wsl, wcs2osstring, wcs2zstring, WSL};
use crate::common::{wcs2osstring, wcs2zstring};
use crate::env::{EnvMode, EnvStack, Environment};
use crate::expand::{expand_tilde, HOME_DIRECTORY};
use crate::flog::{FLOG, FLOGF};
@@ -308,29 +308,6 @@ fn path_get_path_core<S: AsRef<wstr>>(cmd: &wstr, pathsv: &[S]) -> GetPathResult
return GetPathResult::new(test_path(cmd).err(), cmd.to_owned());
}
// WSLv1/WSLv2 tack on the entire Windows PATH to the end of the PATH environment variable, and
// accessing these paths from WSL binaries is pathalogically slow. We also don't expect to find
// any "normal" nix binaries under these paths, so we can skip them unless we are executing bins
// with Windows-ish names. We try to keep paths manually added to $fish_user_paths by only
// chopping off entries after the last "normal" PATH entry.
let pathsv = if is_wsl(WSL::Any) && !cmd.contains('.') {
let win_path_count = pathsv
.iter()
.rev()
.take_while(|p| {
let p = p.as_ref();
p.starts_with("/mnt/")
&& p.chars()
.nth("/mnt/x".len())
.map(|c| c == '/')
.unwrap_or(false)
})
.count();
&pathsv[..pathsv.len() - win_path_count]
} else {
pathsv
};
let mut best = noent_res;
for next_path in pathsv {
let next_path: &wstr = next_path.as_ref();