Skip to content

Commit 92ea9fb

Browse files
author
Andrew
authored
Merge branch 'main' into issue_592
2 parents 097b71b + ee86c76 commit 92ea9fb

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
@@ -25,6 +25,7 @@ use tracing::{debug, info, trace, warn, warn_span};
2525
use tracing_indicatif::span_ext::IndicatifSpanExt;
2626

2727
use crate::util::{get_setting, ProgressBar};
28+
use crate::util::get_exe_path;
2829

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

137138
// if exe home is not already in PATH env var then add it to env var and list of searched paths
138139
if !using_custom_path {
139-
if let Some(exe_home) = env::current_exe()?.parent() {
140+
if let Some(exe_home) = get_exe_path()?.parent() {
140141
let exe_home_pb = exe_home.to_path_buf();
141142
if paths.contains(&exe_home_pb) {
142143
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
@@ -5,6 +5,7 @@ use crate::dscerror::DscError;
55
use clap::ValueEnum;
66
use serde_json::Value;
77
use serde::Serialize;
8+
use std::fs;
89
use std::fs::File;
910
use std::io::BufReader;
1011
use std::path::PathBuf;
@@ -179,7 +180,7 @@ pub fn get_setting(value_name: &str) -> Result<DscSettingValue, DscError> {
179180
let mut result: DscSettingValue = DscSettingValue::default();
180181
let mut settings_file_path : PathBuf;
181182

182-
if let Some(exe_home) = env::current_exe()?.parent() {
183+
if let Some(exe_home) = get_exe_path()?.parent() {
183184
// First, get setting from the default settings file
184185
settings_file_path = exe_home.join(DEFAULT_SETTINGS_FILE_NAME);
185186
if let Ok(v) = load_value_from_json(&settings_file_path, DEFAULT_SETTINGS_SCHEMA_VERSION) {
@@ -241,6 +242,24 @@ fn load_value_from_json(path: &PathBuf, value_name: &str) -> Result<serde_json::
241242
Err(DscError::NotSupported(value_name.to_string()))
242243
}
243244

245+
/// Gets path to the current dsc process.
246+
/// If dsc is started using a symlink, this functon returns target of the symlink.
247+
///
248+
/// # Errors
249+
///
250+
/// Will return `Err` if path to the current exe can't be retrived.
251+
pub fn get_exe_path() -> Result<PathBuf, DscError> {
252+
if let Ok(exe) = env::current_exe() {
253+
if let Ok(target_path) = fs::read_link(exe.clone()) {
254+
return Ok(target_path);
255+
};
256+
257+
return Ok(exe);
258+
}
259+
260+
Err(DscError::NotSupported("Can't get the path to dsc executable".to_string()))
261+
}
262+
244263
#[cfg(target_os = "windows")]
245264
fn get_settings_policy_file_path() -> String
246265
{

0 commit comments

Comments
 (0)