From 628f6e7dcc0c15c1afc4c0b7b1d27210725d90ad Mon Sep 17 00:00:00 2001 From: Ikey Doherty Date: Thu, 28 Sep 2023 00:41:14 +0100 Subject: [PATCH] moss/registry/transaction: Avoid adding cyclical deps This fixes the majority of *acceptable* cyclical dependencies and allows installation to proceed! Signed-off-by: Ikey Doherty --- dag/src/lib.rs | 1 + moss/src/registry/transaction.rs | 16 +++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/dag/src/lib.rs b/dag/src/lib.rs index 80fa653d..fd43480e 100644 --- a/dag/src/lib.rs +++ b/dag/src/lib.rs @@ -9,4 +9,5 @@ pub use self::reexport::*; pub mod reexport { pub use petgraph::algo::{toposort, Cycle}; pub use petgraph::graph::DiGraph; + pub use petgraph::visit::Dfs; } diff --git a/moss/src/registry/transaction.rs b/moss/src/registry/transaction.rs index 138c356c..eed2c1a0 100644 --- a/moss/src/registry/transaction.rs +++ b/moss/src/registry/transaction.rs @@ -4,7 +4,7 @@ use std::collections::HashSet; -use dag::{toposort, DiGraph}; +use dag::{toposort, Dfs, DiGraph}; use futures::{StreamExt, TryFutureExt}; use itertools::Itertools; use serde::{Deserialize, Serialize}; @@ -116,8 +116,18 @@ impl<'a> Transaction<'a> { next.push(search.clone()); } - // Connect w/ edges - graph.add_edge(check_node, dep_node, 1); + // Connect w/ edges if non cyclical + let mut dfs = Dfs::new(&graph, dep_node); + let mut add_edge = true; + while let Some(item) = dfs.next(&graph) { + if item == dep_node { + add_edge = false; + break; + } + } + if graph.find_edge_undirected(check_node, dep_node).is_none() && add_edge { + graph.add_edge(check_node, dep_node, 1); + } } } items = next;