Skip to content

Commit a83d5c0

Browse files
Steve Lee (POWERSHELL HE/HIM) (from Dev Box)SteveL-MSFT
authored andcommitted
Fix detection of relative path
1 parent d74420b commit a83d5c0

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

lib/dsc-lib/locales/en-us.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ invalidKey = "Unsupported value for key '%{key}'. Only string, bool, number, an
169169
inDesiredStateNotBool = "'_inDesiredState' is not a boolean"
170170
exportNotSupportedUsingGet = "Export is not supported by resource '%{resource}' using get operation"
171171
runProcessError = "Failed to run process '%{executable}': %{error}"
172+
executableNotFound = "Executable '%{executable}' not found"
172173

173174
[dscresources.dscresource]
174175
invokeGet = "Invoking get for '%{resource}'"

lib/dsc-lib/src/discovery/command_discovery.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -804,17 +804,17 @@ fn load_extension_manifest(path: &Path, manifest: &ExtensionManifest) -> Result<
804804
}
805805

806806
fn verify_executable(resource: &str, operation: &str, executable: &str, directory: &Path) {
807-
// check if executable has a relative path
808-
if !Path::new(executable).is_absolute() {
809-
// combine with directory and see if it exists
810-
let exe_path = directory.join(executable);
811-
if exe_path.exists() {
807+
if which(executable).is_err() {
808+
if !Path::new(executable).is_absolute() {
809+
// combine with directory and see if it exists
810+
let exe_path = directory.join(executable);
811+
if exe_path.exists() {
812+
return;
813+
}
814+
info!("{}", t!("discovery.commandDiscovery.executableNotFound", resource = resource, operation = operation, executable = exe_path.to_string_lossy()));
812815
return;
813816
}
814-
info!("{}", t!("discovery.commandDiscovery.executableNotFound", resource = resource, operation = operation, executable = exe_path.to_string_lossy()));
815-
return;
816-
}
817-
if which(executable).is_err() {
817+
818818
info!("{}", t!("discovery.commandDiscovery.executableNotFound", resource = resource, operation = operation, executable = executable));
819819
}
820820
}

lib/dsc-lib/src/dscresources/command_resource.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use crate::dscerror::DscError;
1212
use super::{dscresource::{get_diff, redact}, invoke_result::{ExportResult, GetResult, ResolveResult, SetResult, TestResult, ValidateResult, ResourceGetResponse, ResourceSetResponse, ResourceTestResponse, get_in_desired_state}, resource_manifest::{ArgKind, InputKind, Kind, ResourceManifest, ReturnKind, SchemaKind}};
1313
use tracing::{error, warn, info, debug, trace};
1414
use tokio::{io::{AsyncBufReadExt, AsyncWriteExt, BufReader}, process::Command};
15+
use which::which;
1516

1617
pub const EXIT_PROCESS_TERMINATED: i32 = 0x102;
1718

@@ -764,7 +765,7 @@ fn convert_hashmap_string_keys_to_i32(input: Option<&HashMap<String, String>>) -
764765
pub fn invoke_command(executable: &str, args: Option<Vec<String>>, input: Option<&str>, cwd: Option<&str>, env: Option<HashMap<String, String>>, exit_codes: Option<&HashMap<String, String>>) -> Result<(i32, String, String), DscError> {
765766
let exit_codes = convert_hashmap_string_keys_to_i32(exit_codes)?;
766767
let mut executable = executable.to_string();
767-
if !Path::new(&executable).is_absolute() && cwd.is_some() {
768+
if which(&executable).is_err() && !Path::new(&executable).is_absolute() && cwd.is_some() {
768769
if let Some(cwd) = cwd {
769770
let cwd_path = Path::new(cwd);
770771
let executable_path = cwd_path.join(&executable);

0 commit comments

Comments
 (0)