Skip to content

Commit 3493ca5

Browse files
author
Andrew
committed
Stage 1
1 parent d0cbc72 commit 3493ca5

File tree

1 file changed

+40
-1
lines changed

1 file changed

+40
-1
lines changed

dsc_lib/src/discovery/command_discovery.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@ use crate::dscerror::DscError;
1010
use indicatif::ProgressStyle;
1111
use regex::RegexBuilder;
1212
use semver::Version;
13-
use std::collections::{BTreeMap, HashSet};
13+
use std::collections::{BTreeMap, HashSet, HashMap};
1414
use std::env;
1515
use std::ffi::OsStr;
16+
use std::fs;
1617
use std::fs::File;
1718
use std::io::BufReader;
1819
use std::path::{Path, PathBuf};
@@ -279,6 +280,8 @@ impl ResourceDiscovery for CommandDiscovery {
279280
}
280281

281282
self.adapted_resources = adapted_resources;
283+
save_adapted_resources_lookup_table(&self.adapted_resources);
284+
282285
Ok(())
283286
}
284287

@@ -496,3 +499,39 @@ fn load_manifest(path: &Path) -> Result<DscResource, DscError> {
496499

497500
Ok(resource)
498501
}
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

Comments
 (0)