This commit is contained in:
2023-10-06 08:34:42 +02:00
parent 6a8c11b101
commit 4bdecabbe5
3 changed files with 21 additions and 12 deletions

View File

@@ -13,17 +13,18 @@ pub fn load(config_path: PathBuf) -> Config {
}
pub fn save(config_path: PathBuf, config: Config) {
match fs::write(config_path.clone(), serde_json::to_string_pretty(&config).unwrap()) {
match fs::write(
config_path.clone(),
serde_json::to_string_pretty(&config).unwrap(),
) {
Ok(_) => (),
Err(e) => {
match e.kind() {
std::io::ErrorKind::NotFound => {
fs::create_dir_all(config_path.parent().unwrap()).unwrap();
return save(config_path, config);
}
_ => println!("Could not save config file, got:\n{}\n", e),
Err(e) => match e.kind() {
std::io::ErrorKind::NotFound => {
fs::create_dir_all(config_path.parent().unwrap()).unwrap();
save(config_path, config);
}
}
_ => println!("Could not save config file, got:\n{}\n", e),
},
}
}