diff options
author | Yureka <tvl@yuka.dev> | 2024-05-16T20·44+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-05-16T22·06+0000 |
commit | 4c062d5c9242d9c63e104e58db52ee780e0eefa6 (patch) | |
tree | ad596dfef1dc053f409e4977284e3ff6adc3f4bc /tvix/castore/src/directoryservice/closure_validator.rs | |
parent | 9a704acda52537a9d5f4c2a8cad24d1eaff9d6f7 (diff) |
fix(castore/directory/objectstore): fix responses for deduplicated dirs r/8153
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>
Diffstat (limited to 'tvix/castore/src/directoryservice/closure_validator.rs')
-rw-r--r-- | tvix/castore/src/directoryservice/closure_validator.rs | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/tvix/castore/src/directoryservice/closure_validator.rs b/tvix/castore/src/directoryservice/closure_validator.rs index 6281d247021c..b9746a5a0501 100644 --- a/tvix/castore/src/directoryservice/closure_validator.rs +++ b/tvix/castore/src/directoryservice/closure_validator.rs @@ -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()) } |