mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-21 19:25:56 +00:00
fix(config): an imported server gets the module config files it lacks at start and after an update
A server without a module's active file (an old repack updated by the Manager) made two modules log a 'missing property' line on every world tick. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
375be1b2c5
commit
5c21ef106d
3 files changed
+41
-3
No files matched your search
@@ -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<Vec<String>> {
|
||||
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<Vec<String>> {
|
||||
materialize(root, false)
|
||||
}
|
||||
|
||||
fn materialize(root: &Path, extend_existing: bool) -> Result<Vec<String>> {
|
||||
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<Vec<String>> {
|
||||
}
|
||||
}
|
||||
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] {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in new issue
Block a user