From 2a19d0cad8ca66a085613293c8b0b9c47f220e08 Mon Sep 17 00:00:00 2001 From: Oliver Hamlet Date: Sun, 2 Mar 2025 23:07:33 +0000 Subject: [PATCH] Fix bugs due to translation mistakes --- src/archive/parse.rs | 2 +- src/metadata/metadata_document.rs | 25 +++++++++++++++++++++++-- src/sorting/dfs.rs | 4 ++++ src/sorting/plugins.rs | 9 +++++---- src/sorting/validate.rs | 2 +- 5 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/archive/parse.rs b/src/archive/parse.rs index b8e3363c..639a5632 100644 --- a/src/archive/parse.rs +++ b/src/archive/parse.rs @@ -98,7 +98,7 @@ pub(super) fn to_u32(bytes: &[u8]) -> u32 { pub(super) fn to_u64(bytes: &[u8]) -> u64 { let array = - <[u8; 8]>::try_from(&bytes[..4]).expect("Bytes slice is large enough to hold a u64"); + <[u8; 8]>::try_from(&bytes[..8]).expect("Bytes slice is large enough to hold a u64"); u64::from_le_bytes(array) } diff --git a/src/metadata/metadata_document.rs b/src/metadata/metadata_document.rs index 6611cc35..16cebb3b 100644 --- a/src/metadata/metadata_document.rs +++ b/src/metadata/metadata_document.rs @@ -23,7 +23,7 @@ use super::{ static MERGE_KEY: LazyLock = LazyLock::new(|| as_string_node("<<")); -#[derive(Clone, Debug, Default, Eq, PartialEq)] +#[derive(Clone, Debug, Eq, PartialEq)] pub struct MetadataDocument { bash_tags: Vec, groups: Vec, @@ -287,7 +287,16 @@ impl MetadataDocument { } pub fn set_groups(&mut self, groups: Vec) { - self.groups = groups; + // Ensure that the default group is present. + let default_group_exists = groups.iter().any(|g| g.name() == Group::DEFAULT_NAME); + + if !default_group_exists { + self.groups.clear(); + self.groups.push(Group::default()); + self.groups.extend(groups); + } else { + self.groups = groups; + } } pub fn set_plugin_metadata(&mut self, plugin_metadata: PluginMetadata) { @@ -310,6 +319,18 @@ impl MetadataDocument { } } +impl std::default::Default for MetadataDocument { + fn default() -> Self { + Self { + bash_tags: Default::default(), + groups: vec![Group::default()], + messages: Default::default(), + plugins: Default::default(), + regex_plugins: Default::default(), + } + } +} + fn process_merge_keys(mut yaml: MarkedYaml) -> Result { match yaml.data { YamlData::Array(a) => { diff --git a/src/sorting/dfs.rs b/src/sorting/dfs.rs index c5236b09..3b5a8f15 100644 --- a/src/sorting/dfs.rs +++ b/src/sorting/dfs.rs @@ -188,6 +188,10 @@ impl<'a, N, F: FnMut(&N) -> String> DfsVisitor<'a> for CycleDetector<'a, N, F> { fn visit_forward_or_cross_edge(&mut self, _: EdgeReference<'a, EdgeType>) {} fn visit_back_edge(&mut self, edge_ref: EdgeReference<'a, EdgeType>) { + if self.found_cycle { + return; + } + self.visit_tree_edge(edge_ref); let target_name = (self.get_node_name)(&self.graph[edge_ref.target()]); diff --git a/src/sorting/plugins.rs b/src/sorting/plugins.rs index 1b590b49..17a8b90d 100644 --- a/src/sorting/plugins.rs +++ b/src/sorting/plugins.rs @@ -646,10 +646,10 @@ impl<'a, T: SortingPlugin> PluginsGraph<'a, T> { // significantly slower because it generally involves going further back // along the "new load order" path. let previous_node_position = new_load_order - .get(range_start..) - .expect("last_pos is within the new_load_order vec") .iter() - .rposition(|ni| !self.path_exists(node_index, *ni)); + .skip(range_start) + .rposition(|ni| !self.path_exists(node_index, *ni)) + .map(|p| range_start + p); // Add an edge going from the found vertex to this one, in case it // doesn't exist (we only know there's not a path going the other way). @@ -662,7 +662,7 @@ impl<'a, T: SortingPlugin> PluginsGraph<'a, T> { // Insert position is just after the found vertex, and a forward iterator // points to the element one after the element pointed to by the // corresponding reverse iterator. - let insert_position = previous_node_position.map(|i| i + 1).unwrap_or(0); + let insert_position = previous_node_position.map(|i| i + 1).unwrap_or(range_start); // Add an edge going from this vertex to the next one in the "new load // order" path, in case there isn't already one. @@ -672,6 +672,7 @@ impl<'a, T: SortingPlugin> PluginsGraph<'a, T> { // Now update newLoadOrder with the vertex's new position. new_load_order.insert(insert_position, node_index); + processed_nodes.insert(node_index); if log_enabled!(log::Level::Debug) { if let Some(next_node_index) = new_load_order.get(insert_position + 1) { diff --git a/src/sorting/validate.rs b/src/sorting/validate.rs index 0a16de9b..11068891 100644 --- a/src/sorting/validate.rs +++ b/src/sorting/validate.rs @@ -39,7 +39,7 @@ pub fn validate_specific_and_hardcoded_edges( log::trace!("Validating specific and early-loading plugin edges..."); let non_masters_set: HashSet> = - masters.iter().map(|p| UniCase::new(p.name())).collect(); + non_masters.iter().map(|p| UniCase::new(p.name())).collect(); let blueprint_masters_set: HashSet> = blueprint_masters .iter() .map(|p| UniCase::new(p.name()))