Skip to content

Visual Studio Code, rebuilt in Rust

Rust

fix(windows): find profile executables on PATH with PATHEXT

rokartur67c0cbedcc9e
diff --git a/native/crates/app/src/terminal/profiles.rs b/native/crates/app/src/terminal/profiles.rs
index db84dd190a4..37a79ae3f57 100644
--- a/native/crates/app/src/terminal/profiles.rs
+++ b/native/crates/app/src/terminal/profiles.rs
@@ -92,9 +92,25 @@ fn validate(name: String, value: &Value, env_path: Option<&str>) -> Option<Profi
})
}
-/// processes.ts `findExecutable` without a cwd: the first PATH entry holding the file.
+/// processes.ts `findExecutable` without a cwd: the first PATH entry holding the file, on Windows first with each
+/// `PATHEXT` extension.
pub fn find_executable(name: &str, env_path: Option<&str>) -> Option<PathBuf> {
- env_path?.split(':').map(|dir| Path::new(dir).join(name)).find(|candidate| candidate.is_file())
+ let extensions = if cfg!(windows) { std::env::var("PATHEXT").unwrap_or_else(|_| ".COM;.EXE;.BAT;.CMD".into()) } else { String::new() };
+ for dir in std::env::split_paths(env_path?) {
+ let full_path = dir.join(name);
+ for extension in extensions.split(';').filter(|extension| !extension.is_empty()) {
+ let mut with_extension = full_path.clone().into_os_string();
+ with_extension.push(extension);
+ let with_extension = PathBuf::from(with_extension);
+ if with_extension.is_file() {
+ return Some(with_extension);
+ }
+ }
+ if full_path.is_file() {
+ return Some(full_path);
+ }
+ }
+ None
}
/// `getDefaultProfile`: the configured `terminal.integrated.defaultProfile.osx` if it names a configured profile,