fix(castore/directory/objectstore): fix responses for deduplicated dirs
Using remove_node messed up the extraction of nodes from the graph. Use into_nodes_edges() instead, to remove the nodes without cloning. Change-Id: Id76c7935d082d6f26192cc3cd490483594f1d1e2 Reviewed-on: https://cl.tvl.fyi/c/depot/+/11684 Tested-by: BuildkiteCI Autosubmit: yuka <yuka@yuka.dev> Reviewed-by: flokli <flokli@flokli.de>
This commit is contained in:
parent
9a704acda5
commit
4c062d5c92
1 changed files with 13 additions and 7 deletions
|
@ -141,20 +141,26 @@ impl ClosureValidator {
|
|||
/// In case no elements have been inserted, returns an empty list.
|
||||
#[instrument(level = "trace", skip_all, err)]
|
||||
pub(crate) fn finalize_root_to_leaves(self) -> Result<Vec<Directory>, Error> {
|
||||
let (mut graph, root) = match self.finalize_raw()? {
|
||||
let (graph, root) = match self.finalize_raw()? {
|
||||
None => return Ok(vec![]),
|
||||
Some(v) => v,
|
||||
};
|
||||
|
||||
// do a BFS traversal of the graph, starting with the root node to get
|
||||
// (the count of) all nodes reachable from there.
|
||||
// all nodes reachable from there.
|
||||
let traversal = Bfs::new(&graph, root);
|
||||
|
||||
Ok(traversal
|
||||
.iter(&graph)
|
||||
.collect::<Vec<_>>()
|
||||
.into_iter()
|
||||
.filter_map(|i| graph.remove_node(i))
|
||||
let order = traversal.iter(&graph).collect::<Vec<_>>();
|
||||
|
||||
let (nodes, _edges) = graph.into_nodes_edges();
|
||||
|
||||
// Convert to option, so that we can take individual nodes out without messing up the
|
||||
// indices
|
||||
let mut nodes = nodes.into_iter().map(Some).collect::<Vec<_>>();
|
||||
|
||||
Ok(order
|
||||
.iter()
|
||||
.map(|i| nodes[i.index()].take().unwrap().weight)
|
||||
.collect())
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue