diff --git a/CHANGELOG.md b/CHANGELOG.md index 6cf5be627..8cc1e9f68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,12 @@ - [Rust](https://github.com/moonrepo/tools/blob/master/tools/rust/CHANGELOG.md) - [TOML schema](https://github.com/moonrepo/tools/blob/master/tools/internal-schema/CHANGELOG.md) +## Unreleased + +#### 🐞 Fixes + +- Fixed an issue where command lookup within `PATH` may return an invalid result. + ## 0.41.6 #### 🚀 Updates diff --git a/crates/system-env/src/helpers.rs b/crates/system-env/src/helpers.rs index d6d3de960..8af5fd997 100644 --- a/crates/system-env/src/helpers.rs +++ b/crates/system-env/src/helpers.rs @@ -1,4 +1,3 @@ -use std::env; use std::ffi::OsStr; use std::path::PathBuf; use std::process::Command; @@ -7,6 +6,8 @@ use std::process::Command; /// by checking `PATH` and cycling through `PATHEXT` extensions. #[cfg(windows)] pub fn find_command_on_path>(name: T) -> Option { + use std::env; + let Ok(system_path) = env::var("PATH") else { return None; }; @@ -23,7 +24,7 @@ pub fn find_command_on_path>(name: T) -> Option { if has_ext { let path = path_dir.join(name); - if path.exists() { + if path.exists() && path.is_file() { return Some(path); } } else { @@ -33,7 +34,7 @@ pub fn find_command_on_path>(name: T) -> Option { let path = path_dir.join(file_name); - if path.exists() { + if path.exists() && path.is_file() { return Some(path); } } @@ -44,8 +45,10 @@ pub fn find_command_on_path>(name: T) -> Option { } /// Return an absolute path to the provided command by checking `PATH`. -#[cfg(not(windows))] +#[cfg(unix)] pub fn find_command_on_path>(name: T) -> Option { + use std::env; + let Ok(system_path) = env::var("PATH") else { return None; }; @@ -55,7 +58,7 @@ pub fn find_command_on_path>(name: T) -> Option { for path_dir in env::split_paths(&system_path) { let path = path_dir.join(name); - if path.exists() { + if path.exists() && path.is_file() { return Some(path); } } @@ -63,6 +66,11 @@ pub fn find_command_on_path>(name: T) -> Option { None } +#[cfg(target_arch = "wasm32")] +pub fn find_command_on_path>(_name: T) -> Option { + None +} + /// Return true if the provided command/program (without extension) /// is available on `PATH`. pub fn is_command_on_path>(name: T) -> bool { @@ -91,12 +99,8 @@ pub fn create_process_command, I: IntoIterator, A: AsR find_command_on_path(bin).unwrap_or_else(|| bin.into()) }; - let bin_ext = bin_path - .extension() - .map(|ext| ext.to_string_lossy().to_lowercase()); - // If a Windows script, we must execute the command through powershell - match bin_ext.as_deref() { + match bin_path.extension().and_then(|ext| ext.to_str()) { Some("ps1" | "cmd" | "bat") => { // This conversion is unfortunate... let args = args diff --git a/plugins/Cargo.lock b/plugins/Cargo.lock index 4c2126902..a6d9863a7 100644 --- a/plugins/Cargo.lock +++ b/plugins/Cargo.lock @@ -2001,7 +2001,7 @@ dependencies = [ [[package]] name = "proto_core" -version = "0.41.5" +version = "0.41.6" dependencies = [ "indexmap", "miette", @@ -3317,7 +3317,7 @@ dependencies = [ [[package]] name = "warpgate" -version = "0.18.0" +version = "0.18.1" dependencies = [ "extism", "miette",