mirror of
https://github.com/Corfirean/coa-server-manager.git
synced 2026-11-22 11:25:56 +00:00
Rebuild installed modules for the new core during an update
The core changes almost daily and a plugin loads only into the core it was built for. update::apply now brings every enabled plugin to the new core before the trial start: a build already in the store is reused, otherwise it is rebuilt from the sources recorded at its last build (build recipe). A plugin that cannot be rebuilt is switched off with the reason (and plugins that depend on it); the core update always goes ahead. A rollback puts the builds for the restored core back. The update result lists rebuilt and switched-off modules. Also: plugin.json records the real compiler instead of a fixed string. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
76be1d3238
commit
da94fb49a4
16 files changed
+424
-33
No files matched your search
@@ -57,6 +57,10 @@ pub struct PluginEntry {
|
||||
pub deps: Vec<String>,
|
||||
#[serde(default = "yes")]
|
||||
pub required: bool,
|
||||
/// Why the manager switched this plugin off by itself (it could not be rebuilt for the current
|
||||
/// core). Such a plugin is rebuilt and switched back on after the next core change.
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub disabled_reason: Option<String>,
|
||||
}
|
||||
|
||||
/// The root registry document in `.manager/plugins.json`.
|
||||
@@ -776,6 +780,7 @@ pub fn install(
|
||||
conf_files: meta.conf_files.clone(),
|
||||
deps: meta.deps.clone(),
|
||||
required: meta.required,
|
||||
disabled_reason: None,
|
||||
};
|
||||
|
||||
reg.plugins.insert(meta.id.clone(), entry);
|
||||
@@ -830,6 +835,14 @@ pub fn set_enabled(server: &Path, id: &str, enabled: bool) -> Result<()> {
|
||||
if id == "playerbots" && reg.plugins.get("companions").map(|p| p.enabled).unwrap_or(false) {
|
||||
return Err(Error::BotModulesConflict);
|
||||
}
|
||||
// The core refuses a plugin built for another core: it has to be rebuilt first.
|
||||
if let (Some(host), Some(built)) = (crate::provenance::realm_host_fingerprint(server), installed_plugin_fingerprint(server, id)) {
|
||||
if host != built {
|
||||
return Err(Error::Invalid(format!(
|
||||
"Plugin '{id}' was built for a previous core; rebuild it before switching it on"
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
for dep in &entry.deps {
|
||||
if !reg.plugins.get(dep).map(|p| p.enabled).unwrap_or(false) {
|
||||
@@ -849,7 +862,9 @@ pub fn set_enabled(server: &Path, id: &str, enabled: bool) -> Result<()> {
|
||||
}
|
||||
|
||||
tx.set_phase(TransactionPhase::Applying)?;
|
||||
reg.plugins.get_mut(id).unwrap().enabled = enabled;
|
||||
let e = reg.plugins.get_mut(id).unwrap();
|
||||
e.enabled = enabled;
|
||||
e.disabled_reason = None;
|
||||
save_registry(server, ®)?;
|
||||
check_crash_injection("after_registry_write");
|
||||
|
||||
@@ -882,6 +897,39 @@ pub fn set_enabled(server: &Path, id: &str, enabled: bool) -> Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Switches a plugin off because it cannot run on the current core, together with every enabled plugin
|
||||
/// that depends on it, and records why. The core itself is never held back by a plugin.
|
||||
pub fn disable_with_reason(server: &Path, id: &str, reason: &str) -> Result<Vec<String>> {
|
||||
require_server_stopped(server)?;
|
||||
let mut tx = TxGuard::begin_op(server, PluginOpType::Disable, id)?;
|
||||
let mut reg = load_registry_direct(server)?;
|
||||
if !reg.plugins.contains_key(id) {
|
||||
return Err(Error::Invalid(format!("Plugin '{id}' is not installed")));
|
||||
}
|
||||
let mut off = vec![id.to_string()];
|
||||
let mut i = 0;
|
||||
while i < off.len() {
|
||||
let cur = off[i].clone();
|
||||
for (other_id, other) in ®.plugins {
|
||||
if other.enabled && other.deps.contains(&cur) && !off.contains(other_id) {
|
||||
off.push(other_id.clone());
|
||||
}
|
||||
}
|
||||
i += 1;
|
||||
}
|
||||
tx.set_phase(TransactionPhase::Applying)?;
|
||||
for (n, pid) in off.iter().enumerate() {
|
||||
let e = reg.plugins.get_mut(pid).unwrap();
|
||||
e.enabled = false;
|
||||
e.disabled_reason = Some(if n == 0 { reason.to_string() } else { format!("depends on '{id}', which was switched off: {reason}") });
|
||||
}
|
||||
save_registry(server, ®)?;
|
||||
regenerate_lockfile(server, ®)?;
|
||||
tx.set_phase(TransactionPhase::Validating)?;
|
||||
tx.commit()?;
|
||||
Ok(off)
|
||||
}
|
||||
|
||||
/// Update an installed plugin to a new version with 3-way configuration merge.
|
||||
pub fn update(
|
||||
server: &Path,
|
||||
@@ -941,6 +989,7 @@ pub fn update(
|
||||
conf_files: new_meta.conf_files,
|
||||
deps: new_meta.deps,
|
||||
required: new_meta.required,
|
||||
disabled_reason: None,
|
||||
};
|
||||
|
||||
reg.plugins.insert(new_meta.id, updated_entry);
|
||||
|
||||
Reference in new issue
Block a user