Verified Commit 6f0b779d authored by Jelle van der Waa's avatar Jelle van der Waa 🚧
Browse files

Use a DfsPostOrder visitor for rebuild order

To generate the correct order a topologic order traversal should be
used, but that doesn't handle cycles, while a visitor such as
DfsPostOrder does. But it emits the graph in a visual wrong order so
store the results in a vector and reverse them before displaying.

Closes #1
parent beff45a1
Pipeline #2311 passed with stages
in 2 minutes and 18 seconds
use alpm::{Package, SigLevel};
use petgraph::dot::{Config, Dot};
use petgraph::graph::DiGraph;
use petgraph::visit::Bfs;
use petgraph::visit::DfsPostOrder;
use std::collections::{HashMap, HashSet, VecDeque};
use std::error::Error;
use std::fs::File;
......@@ -126,19 +126,28 @@ pub fn run(
let mut output = String::new();
let mut rebuild_order_packages = Vec::new();
for pkg in &pkgnames {
if let Some(pkgname) = cache_node.get(pkg.as_str()) {
let mut bfs = Bfs::new(&graph, *pkgname);
let mut bfs = DfsPostOrder::new(&graph, *pkgname);
while let Some(nx) = {
let node = graph[nx];
output.push(' ');
// Reverse the rebuilder order as DfsPostOrder starts with the first pkgname and therefore
// shows it as last package
let mut output = String::new();
for elem in rebuild_order_packages.iter() {
output.push(' ');
if let Some(filename) = dotfile {
if let Err(e) = write_dotfile(filename, graph) {
eprintln!("Could not write to file");
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment