🐛 bug: allow `auto-gen-key` to also recreate the file and fix permissions

main
_ 2021-07-13 16:02:49 -05:00
parent 3054991c5e
commit 02b6955a50
1 changed files with 17 additions and 10 deletions

View File

@ -81,17 +81,24 @@ async fn main () -> Result <(), anyhow::Error> {
let path = opt.config_path.clone ().unwrap_or_else (|| PathBuf::from ("./config/ptth_server.toml"));
let config_file: ConfigFile = match load_toml::load (&path) {
Err (ptth_server::errors::LoadTomlError::Io (_)) => if opt.auto_gen_key {
gen_and_save_key (&path)?;
let config_file: ConfigFile = if opt.auto_gen_key {
// If we're in autonomous mode, try harder to fix things
load_toml::load (&path)?
match load_toml::load (&path) {
Err (_) => {
gen_and_save_key (&path)?;
load_toml::load (&path)?
},
Ok (x) => x,
}
}
else {
match load_toml::load (&path) {
Err (ptth_server::errors::LoadTomlError::Io (_)) => bail! ("API key not provided in config file and auto-gen-key not provided"),
Ok (x) => x,
Err (e) => return Err (e.into ()),
}
else {
bail! ("API key not provided in config file and auto-gen-key not provided");
},
Ok (x) => x,
Err (e) => return Err (e.into ()),
};
let config_file = ptth_server::ConfigFile {