Skip to content

Commit acefdeb

Browse files
authored
Merge branch 'main' into include-content
2 parents 3e272ee + ee86c76 commit acefdeb

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

README.md

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@ With DSCv3, you can:
1818

1919
### Differences from PowerShell DSC
2020

21-
This project is the next generation of DSC and leverages the
22-
[PSDesiredStateConfiguration module][00] to maintain compatibility with existing PowerShell based
23-
resources.
24-
2521
DSCv3 differs from PowerShell DSC in a few important ways:
2622

2723
- DSCv3 doesn't depend on PowerShell. You can use DSCv3 without PowerShell installed and manage
2824
resources written in bash, python, C#, Go, or any other language.
25+
- DSCv3 use of PowerShell based resources does not depend on PSDesiredStateConfiguration module
2926
- DSCv3 doesn't include a local configuration manager. DSCv3 is invoked as a command. It doesn't
3027
run as a service.
3128
- Non-PowerShell resources define their schemas with JSON files, not MOF files.

dsc_lib/src/discovery/command_discovery.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use tracing::{debug, info, trace, warn, warn_span};
2424
use tracing_indicatif::span_ext::IndicatifSpanExt;
2525

2626
use crate::util::get_setting;
27+
use crate::util::get_exe_path;
2728

2829
pub struct CommandDiscovery {
2930
// use BTreeMap so that the results are sorted by the typename, the Vec is sorted by version
@@ -135,7 +136,7 @@ impl CommandDiscovery {
135136

136137
// if exe home is not already in PATH env var then add it to env var and list of searched paths
137138
if !using_custom_path {
138-
if let Some(exe_home) = env::current_exe()?.parent() {
139+
if let Some(exe_home) = get_exe_path()?.parent() {
139140
let exe_home_pb = exe_home.to_path_buf();
140141
if paths.contains(&exe_home_pb) {
141142
trace!("Exe home is already in path: {}", exe_home.to_string_lossy());

dsc_lib/src/util.rs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use crate::dscerror::DscError;
55
use serde_json::Value;
6+
use std::fs;
67
use std::fs::File;
78
use std::io::BufReader;
89
use std::path::PathBuf;
@@ -79,7 +80,7 @@ pub fn get_setting(value_name: &str) -> Result<DscSettingValue, DscError> {
7980
let mut result: DscSettingValue = DscSettingValue::default();
8081
let mut settings_file_path : PathBuf;
8182

82-
if let Some(exe_home) = env::current_exe()?.parent() {
83+
if let Some(exe_home) = get_exe_path()?.parent() {
8384
// First, get setting from the default settings file
8485
settings_file_path = exe_home.join(DEFAULT_SETTINGS_FILE_NAME);
8586
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<serde_json::
141142
Err(DscError::NotSupported(value_name.to_string()))
142143
}
143144

145+
/// Gets path to the current dsc process.
146+
/// If dsc is started using a symlink, this functon returns target of the symlink.
147+
///
148+
/// # Errors
149+
///
150+
/// Will return `Err` if path to the current exe can't be retrived.
151+
pub fn get_exe_path() -> Result<PathBuf, DscError> {
152+
if let Ok(exe) = env::current_exe() {
153+
if let Ok(target_path) = fs::read_link(exe.clone()) {
154+
return Ok(target_path);
155+
};
156+
157+
return Ok(exe);
158+
}
159+
160+
Err(DscError::NotSupported("Can't get the path to dsc executable".to_string()))
161+
}
162+
144163
#[cfg(target_os = "windows")]
145164
fn get_settings_policy_file_path() -> String
146165
{

0 commit comments

Comments
 (0)