(executable: &str, cwd: Option<&Path>)
| 234 | } |
| 235 | |
| 236 | pub fn canonicalize_which(executable: &str, cwd: Option<&Path>) -> Result<String, DscError> { |
| 237 | // Use PathBuf to handle path separators robustly |
| 238 | let mut executable_path = PathBuf::from(executable); |
| 239 | if cfg!(target_os = "windows") && executable_path.extension().is_none() { |
| 240 | executable_path.set_extension("exe"); |
| 241 | } |
| 242 | if which(executable).is_err() { |
| 243 | if let Some(cwd_path) = cwd { |
| 244 | if let Ok(canonical_path) = canonicalize(cwd_path.join(&executable_path)) { |
| 245 | return Ok(canonical_path.to_string_lossy().to_string()); |
| 246 | } |
| 247 | return Err(DscError::CommandOperation(t!("util.executableNotFoundInWorkingDirectory", executable = &executable, cwd = cwd_path.display()).to_string(), executable_path.to_string_lossy().to_string())); |
| 248 | } |
| 249 | return Err(DscError::CommandOperation(t!("util.executableNotFound", executable = &executable).to_string(), executable.to_string())); |
| 250 | } |
| 251 | Ok(executable.to_string()) |
| 252 | } |
| 253 | |
| 254 | #[macro_export] |
| 255 | macro_rules! locked_clear { |
no outgoing calls
no test coverage detected