aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlukeflo2025-03-26 19:05:29 +0000
committerlukeflo2025-03-26 19:05:29 +0000
commitece98eb7564b295c5e9d649731229c73a563b0db (patch)
treeef14796784424b33c44ed4242419c66db09d602e
parent7f00fe5861cc5024fb41c4620357b47f5ad71019 (diff)
parent19ffe771d4b4c2c4690bc9dfb3fc640449761aef (diff)
downloadbibiman-ece98eb7564b295c5e9d649731229c73a563b0db.tar.gz
bibiman-ece98eb7564b295c5e9d649731229c73a563b0db.zip
Merge pull request 'Fix: Creating default config fails if ~/.config/bibiman does not exist yet.' (#19) from Klimperfix/bibiman:fix-create-conf-dir-#18 into main
Reviewed-on: https://codeberg.org/lukeflo/bibiman/pulls/19 Reviewed-by: lukeflo <lukeflo@noreply.codeberg.org>
-rw-r--r--src/config.rs10
1 files changed, 9 insertions, 1 deletions
diff --git a/src/config.rs b/src/config.rs
index ce3b874..d554c58 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -16,9 +16,10 @@
/////
use std::{
- fs::File,
+ fs::{create_dir_all, File},
io::{stdin, Write},
path::PathBuf,
+ str::FromStr,
};
use color_eyre::{eyre::Result, owo_colors::OwoColorize};
@@ -198,6 +199,13 @@ impl BibiConfig {
}
}
+ {
+ // Ignore any errors of this function, if something goes wrong creating a file will fail too.
+ let mut dirpath = PathBuf::from_str(path.unwrap()).unwrap_or_else(|_| PathBuf::new());
+ dirpath.pop();
+ let _ = create_dir_all(dirpath);
+ }
+
let cfg_file = File::create_new(path.unwrap());
match cfg_file {