@@ -48,7 +48,7 @@ impl CommandDiscovery {
48
48
trace ! ( "DSC_RESOURCE_PATH not set, trying PATH" ) ;
49
49
match env:: var_os ( "PATH" ) {
50
50
Some ( value) => {
51
- trace ! ( "Using PATH: {:?}" , value. to_string_lossy( ) ) ;
51
+ trace ! ( "Original PATH: {:?}" , value. to_string_lossy( ) ) ;
52
52
value
53
53
} ,
54
54
None => {
@@ -58,18 +58,27 @@ impl CommandDiscovery {
58
58
} ;
59
59
60
60
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 ( ) ) ) ;
61
64
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
63
66
if !using_custom_path {
64
67
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 ( ) ) ;
67
- }
68
- }
68
+ let exe_home_pb = exe_home. to_path_buf ( ) ;
69
+ if paths. contains ( & exe_home_pb) {
70
+ trace ! ( "Exe home is already in path: {}" , exe_home. to_string_lossy( ) ) ;
71
+ } else {
72
+ trace ! ( "Adding exe home to path: {}" , exe_home. to_string_lossy( ) ) ;
73
+ paths. push ( exe_home_pb) ;
69
74
70
- // remove duplicate entries to improve perf of resource search
71
- let mut uniques = HashSet :: new ( ) ;
72
- paths. retain ( |e|uniques. insert ( ( * e) . clone ( ) ) ) ;
75
+ if let Ok ( new_path) = env:: join_paths ( paths. clone ( ) ) {
76
+ debug ! ( "Using PATH: {:?}" , new_path. to_string_lossy( ) ) ;
77
+ env:: set_var ( "PATH" , & new_path) ;
78
+ }
79
+ }
80
+ }
81
+ } ;
73
82
74
83
Ok ( paths)
75
84
}
0 commit comments