Skip to content

Commit a7ae36f

Browse files
author
Andrew
committed
create directory before saving lookup_table file
1 parent 85dbd62 commit a7ae36f

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

dsc_lib/src/discovery/command_discovery.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -549,7 +549,21 @@ fn save_adapted_resources_lookup_table(lookup_table: &HashMap<String, String>)
549549
if let Ok(lookup_table_json) = serde_json::to_string_pretty(&lookup_table) {
550550
let file_path = get_lookup_table_file_path();
551551
debug!("Saving lookup table with {} items to {:?}", lookup_table.len(), file_path);
552-
fs::write(file_path.clone(), lookup_table_json).unwrap_or_else(|_| { panic!("{}", format!("Unable to write lookup_table file {file_path:?}").to_string()) });
552+
553+
let path = std::path::Path::new(&file_path);
554+
if let Some(prefix) = path.parent() {
555+
if fs::create_dir_all(prefix).is_ok() {
556+
if !fs::write(file_path.clone(), lookup_table_json).is_ok() {
557+
debug!("Unable to write lookup_table file {file_path:?}");
558+
}
559+
} else {
560+
debug!("Unable to create parent directories of the lookup_table file {file_path:?}");
561+
}
562+
} else {
563+
debug!("Unable to get directory of the lookup_table file {file_path:?}");
564+
}
565+
} else {
566+
debug!("Unable to serialize lookup_table to json");
553567
}
554568
}
555569

0 commit comments

Comments
 (0)