Create config path if it doesn't exist; don't panic
This commit is contained in:
parent
96c3e504f8
commit
6f92e1fb71
@ -13,7 +13,18 @@ pub fn load(config_path: PathBuf) -> Config {
|
||||
}
|
||||
|
||||
pub fn save(config_path: PathBuf, config: Config) {
|
||||
fs::write(config_path, serde_json::to_string_pretty(&config).unwrap()).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),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn save_value(config_path: PathBuf, key: &str, value: bool) {
|
||||
|
Loading…
Reference in New Issue
Block a user