diff --git a/dsc_lib/src/discovery/command_discovery.rs b/dsc_lib/src/discovery/command_discovery.rs index 61f9a682..060536e1 100644 --- a/dsc_lib/src/discovery/command_discovery.rs +++ b/dsc_lib/src/discovery/command_discovery.rs @@ -24,6 +24,7 @@ use tracing::{debug, info, trace, warn, warn_span}; use tracing_indicatif::span_ext::IndicatifSpanExt; use crate::util::get_setting; +use crate::util::get_exe_path; pub struct CommandDiscovery { // use BTreeMap so that the results are sorted by the typename, the Vec is sorted by version @@ -135,7 +136,7 @@ impl CommandDiscovery { // if exe home is not already in PATH env var then add it to env var and list of searched paths if !using_custom_path { - if let Some(exe_home) = env::current_exe()?.parent() { + if let Some(exe_home) = get_exe_path()?.parent() { let exe_home_pb = exe_home.to_path_buf(); if paths.contains(&exe_home_pb) { trace!("Exe home is already in path: {}", exe_home.to_string_lossy()); diff --git a/dsc_lib/src/util.rs b/dsc_lib/src/util.rs index 177d9549..0ff323a9 100644 --- a/dsc_lib/src/util.rs +++ b/dsc_lib/src/util.rs @@ -3,6 +3,7 @@ use crate::dscerror::DscError; use serde_json::Value; +use std::fs; use std::fs::File; use std::io::BufReader; use std::path::PathBuf; @@ -79,7 +80,7 @@ pub fn get_setting(value_name: &str) -> Result { let mut result: DscSettingValue = DscSettingValue::default(); let mut settings_file_path : PathBuf; - if let Some(exe_home) = env::current_exe()?.parent() { + if let Some(exe_home) = get_exe_path()?.parent() { // First, get setting from the default settings file settings_file_path = exe_home.join(DEFAULT_SETTINGS_FILE_NAME); if let Ok(v) = load_value_from_json(&settings_file_path, DEFAULT_SETTINGS_SCHEMA_VERSION) { @@ -141,6 +142,24 @@ fn load_value_from_json(path: &PathBuf, value_name: &str) -> Result Result { + if let Ok(exe) = env::current_exe() { + if let Ok(target_path) = fs::read_link(exe.clone()) { + return Ok(target_path); + }; + + return Ok(exe); + } + + Err(DscError::NotSupported("Can't get the path to dsc executable".to_string())) +} + #[cfg(target_os = "windows")] fn get_settings_policy_file_path() -> String {