@@ -10,9 +10,10 @@ use crate::dscerror::DscError;
10
10
use indicatif:: ProgressStyle ;
11
11
use regex:: RegexBuilder ;
12
12
use semver:: Version ;
13
- use std:: collections:: { BTreeMap , HashSet } ;
13
+ use std:: collections:: { BTreeMap , HashSet , HashMap } ;
14
14
use std:: env;
15
15
use std:: ffi:: OsStr ;
16
+ use std:: fs;
16
17
use std:: fs:: File ;
17
18
use std:: io:: BufReader ;
18
19
use std:: path:: { Path , PathBuf } ;
@@ -279,6 +280,8 @@ impl ResourceDiscovery for CommandDiscovery {
279
280
}
280
281
281
282
self . adapted_resources = adapted_resources;
283
+ save_adapted_resources_lookup_table ( & self . adapted_resources ) ;
284
+
282
285
Ok ( ( ) )
283
286
}
284
287
@@ -496,3 +499,39 @@ fn load_manifest(path: &Path) -> Result<DscResource, DscError> {
496
499
497
500
Ok ( resource)
498
501
}
502
+
503
+ fn save_adapted_resources_lookup_table ( adapted_resources : & BTreeMap < String , Vec < DscResource > > )
504
+ {
505
+ let mut lookup_table: HashMap < String , String > = HashMap :: new ( ) ;
506
+ for ( resource_name, res_vec) in adapted_resources {
507
+ let adapter_name = & res_vec[ 0 ] . require_adapter . as_ref ( ) . unwrap ( ) ;
508
+ lookup_table. insert ( resource_name. to_string ( ) , adapter_name. to_string ( ) ) ;
509
+ }
510
+
511
+ debug ! ( "============ABC==========" ) ;
512
+
513
+ match serde_json:: to_string_pretty ( & lookup_table) {
514
+ Ok ( lookup_table_json) => {
515
+ debug ! ( "{:?}" , lookup_table_json) ;
516
+
517
+ let file_path = get_lookup_table_file_path ( ) ;
518
+ debug ! ( "{:?}" , file_path) ;
519
+
520
+ fs:: write ( file_path, lookup_table_json) . expect ( "Unable to write lookup_table file" ) ;
521
+ } ,
522
+ Err ( _) => { }
523
+ }
524
+
525
+ }
526
+
527
+ #[ cfg( target_os = "windows" ) ]
528
+ fn get_lookup_table_file_path ( ) -> String
529
+ {
530
+ // $env:LocalAppData+"dsc\AdaptedResourcesLookupTable.json"
531
+ let local_app_data_path = match std:: env:: var ( "LocalAppData" ) {
532
+ Ok ( path) => path,
533
+ Err ( _) => { return "" . to_string ( ) ; }
534
+ } ;
535
+
536
+ Path :: new ( & local_app_data_path) . join ( "dsc" ) . join ( "AdaptedResourcesLookupTable.json" ) . display ( ) . to_string ( )
537
+ }
0 commit comments