@@ -280,7 +280,6 @@ impl ResourceDiscovery for CommandDiscovery {
280
280
}
281
281
282
282
self . adapted_resources = adapted_resources;
283
- save_adapted_resources_lookup_table ( & self . adapted_resources ) ;
284
283
285
284
Ok ( ( ) )
286
285
}
@@ -297,6 +296,11 @@ impl ResourceDiscovery for CommandDiscovery {
297
296
} else {
298
297
self . discover_resources ( "*" ) ?;
299
298
self . discover_adapted_resources ( type_name_filter, adapter_name_filter) ?;
299
+
300
+ // add found adapted resources to the lookup_table
301
+ add_resources_to_lookup_table ( & self . adapted_resources ) ;
302
+
303
+ // note: in next line 'BTreeMap::append' will leave self.adapted_resources empty
300
304
resources. append ( & mut self . adapted_resources ) ;
301
305
}
302
306
@@ -356,6 +360,8 @@ impl ResourceDiscovery for CommandDiscovery {
356
360
}
357
361
358
362
self . discover_adapted_resources ( "*" , & adapter_name) ?;
363
+ // add found adapted resources to the lookup_table
364
+ add_resources_to_lookup_table ( & self . adapted_resources ) ;
359
365
360
366
// now go through the adapter resources and add them to the list of resources
361
367
for ( adapted_name, adapted_resource) in & self . adapted_resources {
@@ -500,28 +506,47 @@ fn load_manifest(path: &Path) -> Result<DscResource, DscError> {
500
506
Ok ( resource)
501
507
}
502
508
503
- fn save_adapted_resources_lookup_table ( adapted_resources : & BTreeMap < String , Vec < DscResource > > )
509
+ fn add_resources_to_lookup_table ( adapted_resources : & BTreeMap < String , Vec < DscResource > > )
504
510
{
505
- let mut lookup_table: HashMap < String , String > = HashMap :: new ( ) ;
511
+ let mut lookup_table: HashMap < String , String > = load_adapted_resources_lookup_table ( ) ;
512
+
506
513
for ( resource_name, res_vec) in adapted_resources {
507
514
let adapter_name = & res_vec[ 0 ] . require_adapter . as_ref ( ) . unwrap ( ) ;
508
- lookup_table. insert ( resource_name. to_string ( ) , adapter_name. to_string ( ) ) ;
509
- }
515
+ lookup_table. insert ( resource_name. to_string ( ) . to_lowercase ( ) , adapter_name. to_string ( ) ) ;
516
+ } ;
510
517
511
- debug ! ( "============ABC==========" ) ;
518
+ save_adapted_resources_lookup_table ( & lookup_table) ;
519
+ }
512
520
521
+ fn save_adapted_resources_lookup_table ( lookup_table : & HashMap < String , String > )
522
+ {
513
523
match serde_json:: to_string_pretty ( & lookup_table) {
514
524
Ok ( lookup_table_json) => {
515
- debug ! ( "{:?}" , lookup_table_json) ;
516
525
517
526
let file_path = get_lookup_table_file_path ( ) ;
518
- debug ! ( "{ :?}" , file_path) ;
527
+ debug ! ( "Saving lookup table with {} items to { :?}" , lookup_table . len ( ) , file_path) ;
519
528
520
529
fs:: write ( file_path, lookup_table_json) . expect ( "Unable to write lookup_table file" ) ;
521
530
} ,
522
531
Err ( _) => { }
523
532
}
533
+ }
534
+
535
+ fn load_adapted_resources_lookup_table ( ) -> HashMap < String , String >
536
+ {
537
+ let file_path = get_lookup_table_file_path ( ) ;
524
538
539
+ let lookup_table: HashMap < String , String > = match fs:: read ( file_path. clone ( ) ) {
540
+ Ok ( data) => { match serde_json:: from_slice ( & data) {
541
+ Ok ( lt) => { lt } ,
542
+ Err ( _) => { HashMap :: new ( ) }
543
+ }
544
+ } ,
545
+ Err ( _) => { HashMap :: new ( ) }
546
+ } ;
547
+
548
+ debug ! ( "Read {} items into lookup table from {:?}" , lookup_table. len( ) , file_path) ;
549
+ lookup_table
525
550
}
526
551
527
552
#[ cfg( target_os = "windows" ) ]
0 commit comments