diff --git a/src/database/mod.rs b/src/database/mod.rs index 5641ffff..c293cc09 100644 --- a/src/database/mod.rs +++ b/src/database/mod.rs @@ -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 diff --git a/src/metadata/metadata_document.rs b/src/metadata/metadata_document.rs index d5236439..2e09f08f 100644 --- a/src/metadata/metadata_document.rs +++ b/src/metadata/metadata_document.rs @@ -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();