@@ -20,14 +20,13 @@ use serde::Deserialize;
2020use std:: { collections:: { BTreeMap , HashMap , HashSet } , sync:: { LazyLock , RwLock } } ;
2121use std:: env;
2222use std:: ffi:: OsStr ;
23- use std:: fs;
23+ use std:: fs:: { create_dir_all , read , read_to_string , write } ;
2424use std:: path:: { Path , PathBuf } ;
2525use std:: str:: FromStr ;
2626use tracing:: { debug, info, trace, warn} ;
27- use which:: which;
2827
2928use crate :: util:: get_setting;
30- use crate :: util:: get_exe_path;
29+ use crate :: util:: { canonicalize_which , get_exe_path} ;
3130
3231const DSC_EXTENSION_EXTENSIONS : [ & str ; 3 ] = [ ".dsc.extension.json" , ".dsc.extension.yaml" , ".dsc.extension.yml" ] ;
3332const DSC_MANIFEST_LIST_EXTENSIONS : [ & str ; 3 ] = [ ".dsc.manifests.json" , ".dsc.manifests.yaml" , ".dsc.manifests.yml" ] ;
@@ -621,7 +620,7 @@ fn insert_resource(resources: &mut BTreeMap<String, Vec<DscResource>>, resource:
621620///
622621/// * Returns a `DscError` if the manifest could not be loaded or parsed.
623622pub fn load_manifest ( path : & Path ) -> Result < Vec < ImportedManifest > , DscError > {
624- let contents = fs :: read_to_string ( path) ?;
623+ let contents = read_to_string ( path) ?;
625624 let file_name_lowercase = path. file_name ( ) . and_then ( OsStr :: to_str) . unwrap_or ( "" ) . to_lowercase ( ) ;
626625 let extension_is_json = path. extension ( ) . is_some_and ( |ext| ext. eq_ignore_ascii_case ( "json" ) ) ;
627626 if DSC_RESOURCE_EXTENSIONS . iter ( ) . any ( |ext| file_name_lowercase. ends_with ( ext) ) {
@@ -804,17 +803,7 @@ fn load_extension_manifest(path: &Path, manifest: &ExtensionManifest) -> Result<
804803}
805804
806805fn verify_executable ( resource : & str , operation : & str , executable : & str , directory : & Path ) {
807- if which ( executable) . is_err ( ) {
808- if !Path :: new ( executable) . is_absolute ( ) {
809- // combine with directory and see if it exists
810- let exe_path = directory. join ( executable) ;
811- if exe_path. exists ( ) {
812- return ;
813- }
814- info ! ( "{}" , t!( "discovery.commandDiscovery.executableNotFound" , resource = resource, operation = operation, executable = exe_path. to_string_lossy( ) ) ) ;
815- return ;
816- }
817-
806+ if canonicalize_which ( executable, Some ( directory. to_string_lossy ( ) . as_ref ( ) ) ) . is_err ( ) {
818807 info ! ( "{}" , t!( "discovery.commandDiscovery.executableNotFound" , resource = resource, operation = operation, executable = executable) ) ;
819808 }
820809}
@@ -849,8 +838,8 @@ fn save_adapted_resources_lookup_table(lookup_table: &HashMap<String, String>)
849838
850839 let path = std:: path:: Path :: new ( & file_path) ;
851840 if let Some ( prefix) = path. parent ( ) {
852- if fs :: create_dir_all ( prefix) . is_ok ( ) {
853- if fs :: write ( file_path. clone ( ) , lookup_table_json) . is_err ( ) {
841+ if create_dir_all ( prefix) . is_ok ( ) {
842+ if write ( file_path. clone ( ) , lookup_table_json) . is_err ( ) {
854843 info ! ( "Unable to write lookup_table file {file_path:?}" ) ;
855844 }
856845 } else {
@@ -868,7 +857,7 @@ fn load_adapted_resources_lookup_table() -> HashMap<String, String>
868857{
869858 let file_path = get_lookup_table_file_path ( ) ;
870859
871- let lookup_table: HashMap < String , String > = match fs :: read ( file_path. clone ( ) ) {
860+ let lookup_table: HashMap < String , String > = match read ( file_path. clone ( ) ) {
872861 Ok ( data) => { serde_json:: from_slice ( & data) . unwrap_or_default ( ) } ,
873862 Err ( _) => { HashMap :: new ( ) }
874863 } ;
0 commit comments