MCPcopy Create free account
hub / github.com/PowerShell/DSC / canonicalize_which

Function canonicalize_which

lib/dsc-lib/src/util.rs:236–252  ·  view source on GitHub ↗
(executable: &str, cwd: Option<&Path>)

Source from the content-addressed store, hash-verified

234}
235
236pub 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]
255macro_rules! locked_clear {

Callers 2

invoke_commandFunction · 0.85
verify_executableFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected