Create config directory if necessary

This commit is contained in:
Dustin J. Mitchell 2021-06-13 15:40:57 -04:00
parent 8e84bf0446
commit cc5240eeec

View file

@ -186,6 +186,14 @@ impl Settings {
let exists = filename.exists(); let exists = filename.exists();
// try to create the parent directory if the file does not exist
if !exists {
if let Some(dir) = filename.parent() {
fs::create_dir_all(dir)?;
}
}
// start with the existing document, or a blank document
let mut document = if exists { let mut document = if exists {
fs::read_to_string(filename.clone()) fs::read_to_string(filename.clone())
.context("Could not read existing configuration file")? .context("Could not read existing configuration file")?