Plug-ins: a command list read during an install is not cached under the new revision

registry::install now changes the revision while it holds the plug-in set's write lock, so a reader that sees the new revision and lists the plug-ins always finds the new one. command_specs also skips caching a list when the revision changed while it was listing. Before, a menu or shortcut lookup that ran during an install could keep the old command list until the next install or removal.
This commit is contained in:
dotCooCoo
2026-11-07 17:43:02 -08:00
parent 906fd4cfad
commit ea27cc0a2e
2 changed files with 9 additions and 2 deletions
+4 -2
View File
@@ -45,11 +45,13 @@ pub fn approved(plugin: &Plugin) -> bool {
!m.asks_permissions() || granted(&m.id).is_some_and(|g| g.covers(&m.permissions()))
}
/// Installs `plugin`, replacing one with the same id.
/// Installs `plugin`, replacing one with the same id. The revision changes while the set is locked,
/// so a caller that reads the new [`revision`] and then [`list`]s always finds the plug-in.
pub fn install(mut plugin: Plugin) -> Arc<Plugin> {
let mut plugins = PLUGINS.write().unwrap_or_else(|e| e.into_inner());
plugin.set_serial(REVISION.fetch_add(1, Ordering::Relaxed) + 1);
let p = Arc::new(plugin);
PLUGINS.write().unwrap_or_else(|e| e.into_inner()).insert(p.id().to_string(), p.clone());
plugins.insert(p.id().to_string(), p.clone());
p
}