From 02b6955a50d655d7a125777dcb539ac61e8b10ec Mon Sep 17 00:00:00 2001 From: _ <> Date: Tue, 13 Jul 2021 16:02:49 -0500 Subject: [PATCH] :bug: bug: allow `auto-gen-key` to also recreate the file and fix permissions --- crates/ptth_server/src/bin/ptth_server.rs | 27 ++++++++++++++--------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/crates/ptth_server/src/bin/ptth_server.rs b/crates/ptth_server/src/bin/ptth_server.rs index b8915b2..4a47bc6 100644 --- a/crates/ptth_server/src/bin/ptth_server.rs +++ b/crates/ptth_server/src/bin/ptth_server.rs @@ -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)?; - - load_toml::load (&path)? + let config_file: ConfigFile = if opt.auto_gen_key { + // If we're in autonomous mode, try harder to fix things + + 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 {