From e0e83409933c8550607e3ea94df7290997c34c49 Mon Sep 17 00:00:00 2001 From: fufesou Date: Fri, 27 Nov 2026 17:50:41 +0800 Subject: [PATCH] refactor(config): keep option-preserving setters beside the bulk setters Signed-off-by: fufesou --- src/config.rs | 32 ++++++++++++++++++++++++++++- src/config/preserved_option.rs | 37 ---------------------------------- 2 files changed, 31 insertions(+), 38 deletions(-) delete mode 100644 src/config/preserved_option.rs diff --git a/src/config.rs b/src/config.rs index 94a166525..b7ffdaf1c 100644 --- a/src/config.rs +++ b/src/config.rs @@ -19,7 +19,6 @@ use sodiumoxide::base64; use sodiumoxide::crypto::sign; mod permanent_password; -mod preserved_option; pub use permanent_password::{ compute_permanent_password_h1, decode_permanent_password_h1_from_storage, @@ -641,6 +640,26 @@ impl Config2 { lock.store(); true } + + /// Replaces the configuration while retaining the locally stored entry for `key`. + pub fn set_preserving_option(mut incoming: Self, key: &str) -> bool { + let mut current = CONFIG2.write().unwrap(); + current.preserve_option(&mut incoming.options, key); + if *current == incoming { + return false; + } + *current = incoming; + current.store(); + true + } + + fn preserve_option(&self, options: &mut HashMap, key: &str) { + if let Some(value) = self.options.get(key) { + options.insert(key.to_owned(), value.clone()); + } else { + options.remove(key); + } + } } fn keep_encrypted_storage_if_plaintext_unchanged(plain: &str, stored: &str) -> String { @@ -1379,6 +1398,17 @@ impl Config { config.store(); } + /// Replaces the options while retaining the locally stored entry for `key`. + pub fn set_options_preserving_option(mut options: HashMap, key: &str) { + Self::purify_options(&mut options); + let mut current = CONFIG2.write().unwrap(); + current.preserve_option(&mut options, key); + if current.options != options { + current.options = options; + current.store(); + } + } + pub fn get_option(k: &str) -> String { get_or( &OVERWRITE_SETTINGS, diff --git a/src/config/preserved_option.rs b/src/config/preserved_option.rs deleted file mode 100644 index 704359474..000000000 --- a/src/config/preserved_option.rs +++ /dev/null @@ -1,37 +0,0 @@ -use super::{Config, Config2, CONFIG2}; -use std::collections::HashMap; - -impl Config2 { - fn preserve_option(&self, options: &mut HashMap, key: &str) { - if let Some(value) = self.options.get(key) { - options.insert(key.to_owned(), value.clone()); - } else { - options.remove(key); - } - } - - /// Replaces the configuration while retaining the locally stored entry for `key`. - pub fn set_preserving_option(mut incoming: Self, key: &str) -> bool { - let mut current = CONFIG2.write().unwrap(); - current.preserve_option(&mut incoming.options, key); - if *current == incoming { - return false; - } - *current = incoming; - current.store(); - true - } -} - -impl Config { - /// Replaces the options while retaining the locally stored entry for `key`. - pub fn set_options_preserving_option(mut options: HashMap, key: &str) { - Self::purify_options(&mut options); - let mut current = CONFIG2.write().unwrap(); - current.preserve_option(&mut options, key); - if current.options != options { - current.options = options; - current.store(); - } - } -}