abstract the config reload checks

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2025-01-28 19:42:09 +00:00
parent 99fe88c21e
commit ed3cd99781
3 changed files with 28 additions and 10 deletions

View file

@ -32,13 +32,15 @@ pub(super) async fn reload_config(
&self,
path: Option<PathBuf>,
) -> Result<RoomMessageEventContent> {
let path = path.as_deref().into_iter();
let config = Config::load(path).and_then(|raw| Config::new(&raw))?;
if config.server_name != self.services.server.name {
return Err!("You can't change the server name.");
}
use conduwuit::config::check;
let _old = self.services.server.config.update(config)?;
let path = path.as_deref().into_iter();
let new = Config::load(path).and_then(|raw| Config::new(&raw))?;
let old = &self.services.server.config;
check::reload(old, &new)?;
self.services.server.config.update(new)?;
Ok(RoomMessageEventContent::text_plain("Successfully reconfigured."))
}

View file

@ -6,8 +6,24 @@ use figment::Figment;
use super::DEPRECATED_KEYS;
use crate::{debug, debug_info, debug_warn, error, warn, Config, Err, Result, Server};
/// Performs check() with additional checks specific to reloading old config
/// with new config.
pub fn reload(old: &Config, new: &Config) -> Result {
check(new)?;
if new.server_name != old.server_name {
return Err!(Config(
"server_name",
"You can't change the server's name from {:?}.",
old.server_name
));
}
Ok(())
}
#[allow(clippy::cognitive_complexity)]
pub fn check(config: &Config) -> Result<()> {
pub fn check(config: &Config) -> Result {
if cfg!(debug_assertions) {
warn!("Note: conduwuit was built without optimisations (i.e. debug build)");
}

View file

@ -46,14 +46,14 @@ impl Server {
.and_then(|raw| crate::clap::update(raw, args))
.and_then(|raw| Config::new(&raw))?;
#[cfg(feature = "sentry_telemetry")]
let sentry_guard = crate::sentry::init(&config);
let (tracing_reload_handle, tracing_flame_guard, capture) =
crate::logging::init(&config)?;
config.check()?;
#[cfg(feature = "sentry_telemetry")]
let sentry_guard = crate::sentry::init(&config);
#[cfg(unix)]
sys::maximize_fd_limit()
.expect("Unable to increase maximum soft and hard file descriptor limit");