From ae99a9fc57c6ae210d18f0c47bf7aa57212d8b33 Mon Sep 17 00:00:00 2001 From: Anton Yemelyanov Date: Sat, 3 Aug 2024 13:40:31 +0300 Subject: [PATCH] Update startup config file logic --- src/config.rs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/config.rs b/src/config.rs index 8739edd..46b46f3 100644 --- a/src/config.rs +++ b/src/config.rs @@ -255,8 +255,19 @@ pub fn load_global_config() -> Result>> { pub fn load_default_config() -> Result>> { let local_config_folder = local_config_folder().ok_or(Error::LocalConfigNotFound)?; let local_config = local_config_folder.join(local_config_file()); - let toml = fs::read_to_string(local_config)?; - Config::try_parse(toml.as_str()) + + if local_config.exists() { + log_info!("Config", "Using local config: `{}`", local_config.display()); + let toml = fs::read_to_string(local_config)?; + Config::try_parse(toml.as_str()) + } else { + let local_config = local_config_folder.join(global_config_file()); + log_info!("Config", "Using local config: `{}`", local_config.display()); + let key = load_key()?; + let data = fs::read(local_config)?; + let toml = chacha20poly1305::decrypt_slice(&data, &key)?; + Config::try_parse(toml.as_str()?) + } } pub async fn update_global_config() -> Result>>> {