Fixed how ensuring config save directory exists

This commit is contained in:
Jedrzej Stuczynski
2020-01-31 12:40:16 +00:00
parent f8a468135a
commit 65772cdc1e
+11 -1
View File
@@ -34,7 +34,17 @@ pub trait NymConfig: Default + Serialize + DeserializeOwned {
let templated_config = reg.render_template(Self::template(), self).unwrap();
// make sure the whole directory structure actually exists
fs::create_dir_all(custom_location.clone().unwrap_or(self.config_directory()))?;
match custom_location.clone() {
Some(loc) => {
if let Some(parent_dir) = loc.parent() {
fs::create_dir_all(parent_dir)
} else {
Ok(())
}
}
None => fs::create_dir_all(self.config_directory()),
}?;
fs::write(
custom_location.unwrap_or(self.config_directory().join(Self::config_file_name())),
templated_config,