Skip to content

Commit

Permalink
moss/registry/transaction: Avoid adding cyclical deps
Browse files Browse the repository at this point in the history
This fixes the majority of *acceptable* cyclical dependencies
and allows installation to proceed!

Signed-off-by: Ikey Doherty <ikey@serpentos.com>
  • Loading branch information
ikeycode committed Sep 27, 2023
1 parent 3bbb441 commit 628f6e7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
1 change: 1 addition & 0 deletions dag/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
16 changes: 13 additions & 3 deletions moss/src/registry/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 628f6e7

Please sign in to comment.