diff --git a/Cargo.lock b/Cargo.lock index 9f28bfbf..fa25d978 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1333,7 +1333,7 @@ checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" [[package]] name = "hipcheck" -version = "3.7.0" +version = "3.8.0" dependencies = [ "anyhow", "async-stream", diff --git a/hipcheck/src/plugin/manager.rs b/hipcheck/src/plugin/manager.rs index 142ea0ca..77c774a1 100644 --- a/hipcheck/src/plugin/manager.rs +++ b/hipcheck/src/plugin/manager.rs @@ -86,30 +86,35 @@ impl PluginExecutor { )); }; + let Ok(canon_working_dir) = plugin.working_dir.canonicalize() else { + return Err(hc_error!( + "Failed to canonicalize plugin working dir: {:?}", + &plugin.working_dir + )); + }; + // Entrypoints are often "" which can overlap with existing binaries on the // system like "git", "npm", so we must search for from within the plugin // cache subfolder. First, grab the existing path. - let Some(mut os_paths) = + let Some(mut which_os_paths) = std::env::var_os("PATH").map(|s| std::env::split_paths(&s).collect::>()) else { return Err(hc_error!("Unable to get system PATH var")); }; - let Ok(canon_working_dir) = plugin.working_dir.canonicalize() else { - return Err(hc_error!( - "Failed to canonicalize plugin working dir: {:?}", - &plugin.working_dir - )); - }; + // Add canonicalized plugin cache dir to end of PATH for plugin exec + let mut cmd_os_paths = which_os_paths.clone(); + cmd_os_paths.push(canon_working_dir.clone()); + let cmd_path = std::env::join_paths(cmd_os_paths).unwrap(); - // Add canonicalized plugin cache dir to temp PATH - os_paths.insert(0, canon_working_dir.clone()); - let search_path = std::env::join_paths(os_paths).unwrap(); + // Add canonicalized plugin cache dir to front of PATH for bin-searching + which_os_paths.insert(0, canon_working_dir.clone()); + let which_path = std::env::join_paths(which_os_paths).unwrap(); // Find the binary_str using temp PATH let Ok(canon_bin_path) = which::which_in::<&str, &OsString, &Path>( bin_path_str, - Some(&search_path), + Some(&which_path), canon_working_dir.as_ref(), ) else { return Err(hc_error!( @@ -138,6 +143,7 @@ impl PluginExecutor { // Spawn plugin process log::debug!("Spawning '{}' on port {}", &plugin.entrypoint, port_str); let Ok(mut proc) = Command::new(&canon_bin_path) + .env("PATH", &cmd_path) .args(spawn_args) // @Temporary - directly forward stdout/stderr from plugin to shell .stdout(std::io::stdout())