From ad1c184104334db02814e5ea9b3e7a851ffb1005 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Tue, 22 Oct 2024 11:23:21 -0700 Subject: [PATCH 1/3] Fix lookup. --- crates/system-env/src/helpers.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/crates/system-env/src/helpers.rs b/crates/system-env/src/helpers.rs index d6d3de960..293afc327 100644 --- a/crates/system-env/src/helpers.rs +++ b/crates/system-env/src/helpers.rs @@ -23,7 +23,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 +33,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,7 +44,7 @@ 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 { let Ok(system_path) = env::var("PATH") else { return None; @@ -55,7 +55,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); } } @@ -91,12 +91,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 From 92bf6693dcb075375876aa3d3f99c9147a372610 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Tue, 22 Oct 2024 11:24:46 -0700 Subject: [PATCH 2/3] Update changelog. --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) 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 From 7e13b0449d72ee13af5c82cfdf8084a90611bda5 Mon Sep 17 00:00:00 2001 From: Miles Johnson Date: Tue, 22 Oct 2024 11:29:14 -0700 Subject: [PATCH 3/3] Fix wasm. --- crates/system-env/src/helpers.rs | 10 +++++++++- plugins/Cargo.lock | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/crates/system-env/src/helpers.rs b/crates/system-env/src/helpers.rs index 293afc327..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; }; @@ -46,6 +47,8 @@ pub fn find_command_on_path>(name: T) -> Option { /// Return an absolute path to the provided command by checking `PATH`. #[cfg(unix)] pub fn find_command_on_path>(name: T) -> Option { + use std::env; + let Ok(system_path) = env::var("PATH") else { return None; }; @@ -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 { 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",