diff --git a/crates/coa-core/src/config/mod.rs b/crates/coa-core/src/config/mod.rs index 52dcb96..5296d6a 100644 --- a/crates/coa-core/src/config/mod.rs +++ b/crates/coa-core/src/config/mod.rs @@ -131,6 +131,17 @@ pub struct SettingsView { /// so a server updated to a build with a new setting gets that setting's documented default. Files the launcher writes /// itself are skipped. Returns what was created (`name.conf`) or extended (`name.conf (+n keys)`). pub fn materialize_module_configs(root: &Path) -> Result> { + materialize(root, true) +} + +/// Only the missing active files, created from their `.dist`; a file that exists is not touched at all. This is what a +/// server the Manager imported (not installed) gets: without its file a module logs a "missing property" line for every +/// setting it reads, and some modules read them on every world tick. +pub fn create_missing_module_configs(root: &Path) -> Result> { + materialize(root, false) +} + +fn materialize(root: &Path, extend_existing: bool) -> Result> { let dir = root.join("Core").join("configs").join("modules"); let mut created = Vec::new(); let Ok(entries) = fs::read_dir(&dir) else { return Ok(created) }; @@ -155,6 +166,8 @@ pub fn materialize_module_configs(root: &Path) -> Result> { } } created.push(format!("{stem}.conf")); + } else if !extend_existing { + continue; } else if let (Ok(have), Ok(dist)) = (fs::read(&active), fs::read(e.path())) { if let (Ok(mut conf), Ok(dist)) = (parser::ConfFile::parse_bytes(&have), parser::ConfFile::parse_bytes(&dist)) { let plan = merge::apply(&mut conf, &dist); @@ -630,6 +643,24 @@ Spellbook.New = 5 assert!(materialize_module_configs(&root).unwrap().is_empty()); } + #[test] + fn an_imported_server_only_gets_the_files_it_lacks() { + let (_d, root, _m) = fixture(); + let m = root.join("Core/configs/modules"); + fs::create_dir_all(&m).unwrap(); + fs::write(m.join("dynamicxp.conf.dist"), "Dynamic.XP.Reminder.Interval = 40 +").unwrap(); + fs::write(m.join("spellbook.conf.dist"), "Spellbook.Enable = 1 +Spellbook.New = 5 +").unwrap(); + fs::write(m.join("spellbook.conf"), "Spellbook.Enable = 0 +").unwrap(); + assert_eq!(create_missing_module_configs(&root).unwrap(), vec!["dynamicxp.conf".to_string()]); + assert!(fs::read_to_string(m.join("dynamicxp.conf")).unwrap().contains("Dynamic.XP.Reminder.Interval = 40")); + assert_eq!(fs::read_to_string(m.join("spellbook.conf")).unwrap(), "Spellbook.Enable = 0 +", "an existing file stays byte for byte"); + } + #[test] fn schemas_and_presets_are_self_consistent() { for scope in [Scope::Bots, Scope::Server] { diff --git a/crates/coa-core/src/update.rs b/crates/coa-core/src/update.rs index 2d9be39..d1fe9fa 100644 --- a/crates/coa-core/src/update.rs +++ b/crates/coa-core/src/update.rs @@ -486,10 +486,14 @@ impl Env for RepackEnv<'_> { use crate::process::{observe, ServiceState}; // The check start is the first start of the new build: give the module configs the settings the update added // (as a normal start does), or the server logs a "missing property" line for every one of them. - if let Ok((_, meta)) = crate::registry::MetaDir::open(self.meta_dir) { - if meta.kind == crate::registry::InstallKind::New { + match crate::registry::MetaDir::open(self.meta_dir) { + Ok((_, meta)) if meta.kind == crate::registry::InstallKind::New => { let _ = crate::config::materialize_module_configs(self.root); } + // An imported server gets the files it lacks (nothing it has is changed). + _ => { + let _ = crate::config::create_missing_module_configs(self.root); + } } let started = crate::driver::run(self.root, crate::driver::Verb::StartAll)?; let ports = crate::layout::read_ports(self.root); diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index ba059f4..ac98b30 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -190,12 +190,15 @@ async fn run_verb(state: &AppState, id: String, verb: Verb) -> std::result::Resu #[tauri::command] async fn start_server(state: State<'_, AppState>, id: String) -> std::result::Result { // Servers installed before module configs were created automatically get them now (missing files only). Imported - // servers are never written to by the Manager outside the launcher's own start-up. + // servers only get the module files they lack (see below); nothing they have is changed. if let Ok(root) = path_of(&state, &id) { let _ = tauri::async_runtime::spawn_blocking(move || { let (_, meta) = install_meta(&root)?; if meta.kind == coa_core::registry::InstallKind::New { coa_core::config::materialize_module_configs(&root)?; + } else { + // Imported: only the module files that are missing (a module without its file logs every setting it reads). + let _ = coa_core::config::create_missing_module_configs(&root); } let dir = meta_dir(&root)?; coa_core::friends::ensure_bind(&root, &dir)?;