Add the ability to remove regex plugin metadata

This commit is contained in:
Oliver Hamlet
2026-01-02 16:45:31 +00:00
parent 96b2ed2373
commit 12a0407b4c
2 changed files with 38 additions and 8 deletions
+8 -7
View File
@@ -327,14 +327,15 @@ impl Database {
self.userlist.set_plugin_metadata(plugin_metadata);
}
/// Discards all loaded user metadata that is specific to the plugin with
/// the given filename. Does not discard any plugin metadata with plugin
/// name regexes that match the given filename.
/// Discards all loaded user metadata that is specific to the plugin
/// metadata entry (or entries) with the given name.
///
/// Has no effect if the given plugin name contains any of the characters
/// `:\*?|`.
pub fn discard_plugin_user_metadata(&mut self, plugin: &str) {
self.userlist.remove_plugin_metadata(plugin);
/// If there is a specific plugin metadata entry with the given name, it
/// will be removed. Otherwise, all regex plugin metadata entries with names
/// equal to the given name will be removed. Regex name matching is not
/// performed.
pub fn discard_plugin_user_metadata(&mut self, plugin_name: &str) {
self.userlist.remove_plugin_metadata(plugin_name);
}
/// Discards all loaded user metadata for all groups, plugins, and any
+30 -1
View File
@@ -343,7 +343,13 @@ impl MetadataDocument {
}
pub(crate) fn remove_plugin_metadata(&mut self, plugin_name: &str) {
self.plugins.remove(&Filename::new(plugin_name.to_owned()));
let removed = self.plugins.remove(&Filename::new(plugin_name.to_owned()));
// Only remove regex plugins if no specific plugin was removed, because
// they're mutually exclusive.
if removed.is_none() {
self.regex_plugins.retain(|p| p.name() != plugin_name);
}
}
pub(crate) fn clear(&mut self) {
@@ -1084,6 +1090,29 @@ plugins:
assert!(metadata.find_plugin(name).unwrap().is_none());
}
#[test]
fn remove_plugin_metadata_should_remove_regex_entries_with_the_given_plugin_name() {
let mut metadata = MetadataDocument::default();
let regex_name = "Blank.*\\.esp";
let mut plugin = PluginMetadata::new(regex_name).unwrap();
plugin.set_load_after_files(vec![File::new("A".to_owned())]);
metadata.set_plugin_metadata(plugin.clone());
let mut plugin = PluginMetadata::new(regex_name).unwrap();
plugin.set_load_after_files(vec![File::new("B".to_owned())]);
metadata.set_plugin_metadata(plugin.clone());
let name = "Blank.esp";
assert!(metadata.find_plugin(name).unwrap().is_some());
metadata.remove_plugin_metadata(regex_name);
assert!(metadata.find_plugin(name).unwrap().is_none());
}
#[test]
fn remove_plugin_metadata_should_not_remove_matching_regex_plugin_metadata() {
let mut metadata = MetadataDocument::default();