Skip to content

Commit 88d0b3a

Browse files
author
Andrew
committed
code 1
1 parent 05179d9 commit 88d0b3a

File tree

1 file changed

+18
-9
lines changed

1 file changed

+18
-9
lines changed

dsc_lib/src/discovery/command_discovery.rs

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ impl CommandDiscovery {
4848
trace!("DSC_RESOURCE_PATH not set, trying PATH");
4949
match env::var_os("PATH") {
5050
Some(value) => {
51-
trace!("Using PATH: {:?}", value.to_string_lossy());
51+
trace!("Original PATH: {:?}", value.to_string_lossy());
5252
value
5353
},
5454
None => {
@@ -58,18 +58,27 @@ impl CommandDiscovery {
5858
};
5959

6060
let mut paths = env::split_paths(&path_env).collect::<Vec<_>>();
61+
// remove duplicate entries
62+
let mut uniques = HashSet::new();
63+
paths.retain(|e|uniques.insert((*e).clone()));
6164

62-
// add exe home to start of path
65+
// if exe home is not already in PATH env var then add it to env var and list of searched paths
6366
if !using_custom_path {
6467
if let Some(exe_home) = env::current_exe()?.parent() {
65-
debug!("Adding exe home to path: {}", exe_home.to_string_lossy());
66-
paths.insert(0, exe_home.to_path_buf());
68+
let exe_home_pb = exe_home.to_path_buf();
69+
if !paths.contains(&exe_home_pb) {
70+
trace!("Adding exe home to path: {}", exe_home.to_string_lossy());
71+
paths.push(exe_home_pb);
72+
73+
if let Ok(new_path) = env::join_paths(paths.clone()) {
74+
debug!("Using PATH: {:?}", new_path.to_string_lossy());
75+
env::set_var("PATH", &new_path);
76+
}
77+
} else {
78+
trace!("Exe home is already in path: {}", exe_home.to_string_lossy());
79+
}
6780
}
68-
}
69-
70-
// remove duplicate entries to improve perf of resource search
71-
let mut uniques = HashSet::new();
72-
paths.retain(|e|uniques.insert((*e).clone()));
81+
};
7382

7483
Ok(paths)
7584
}

0 commit comments

Comments
 (0)