Fix bugs due to translation mistakes

This commit is contained in:
Oliver Hamlet
2025-03-25 20:56:11 +00:00
parent 051372318d
commit 2a19d0cad8
5 changed files with 34 additions and 8 deletions
+1 -1
View File
@@ -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)
}
+23 -2
View File
@@ -23,7 +23,7 @@ use super::{
static MERGE_KEY: LazyLock<MarkedYaml> = LazyLock::new(|| as_string_node("<<"));
#[derive(Clone, Debug, Default, Eq, PartialEq)]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct MetadataDocument {
bash_tags: Vec<String>,
groups: Vec<Group>,
@@ -287,7 +287,16 @@ impl MetadataDocument {
}
pub fn set_groups(&mut self, groups: Vec<Group>) {
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<MarkedYaml, YamlMergeKeyError> {
match yaml.data {
YamlData::Array(a) => {
+4
View File
@@ -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()]);
+5 -4
View File
@@ -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) {
+1 -1
View File
@@ -39,7 +39,7 @@ pub fn validate_specific_and_hardcoded_edges<T: SortingPlugin>(
log::trace!("Validating specific and early-loading plugin edges...");
let non_masters_set: HashSet<UniCase<&str>> =
masters.iter().map(|p| UniCase::new(p.name())).collect();
non_masters.iter().map(|p| UniCase::new(p.name())).collect();
let blueprint_masters_set: HashSet<UniCase<&str>> = blueprint_masters
.iter()
.map(|p| UniCase::new(p.name()))