From 116a137be082547de08bd13382fc31e925ca6217 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sat, 2 Sep 2023 20:23:04 +0300 Subject: refactor(tvix/store): implement rename for node::Node This returns a node with a new name. Change-Id: Iebcab537f8dd63d826b9841d4d0181fcb941afdd Reviewed-on: https://cl.tvl.fyi/c/depot/+/9211 Reviewed-by: tazjin Autosubmit: flokli Tested-by: BuildkiteCI --- tvix/store/src/proto/mod.rs | 11 +++++++++++ tvix/store/src/store_io.rs | 18 ++---------------- 2 files changed, 13 insertions(+), 16 deletions(-) (limited to 'tvix/store/src') diff --git a/tvix/store/src/proto/mod.rs b/tvix/store/src/proto/mod.rs index 9ee98d8c1c51..c502befe7db1 100644 --- a/tvix/store/src/proto/mod.rs +++ b/tvix/store/src/proto/mod.rs @@ -203,6 +203,17 @@ impl NamedNode for node::Node { } } +impl node::Node { + /// Returns the node with a new name. + pub fn rename(self, name: bytes::Bytes) -> Self { + match self { + node::Node::Directory(n) => node::Node::Directory(DirectoryNode { name, ..n }), + node::Node::File(n) => node::Node::File(FileNode { name, ..n }), + node::Node::Symlink(n) => node::Node::Symlink(SymlinkNode { name, ..n }), + } + } +} + /// Accepts a name, and a mutable reference to the previous name. /// If the passed name is larger than the previous one, the reference is updated. /// If it's not, an error is returned. diff --git a/tvix/store/src/store_io.rs b/tvix/store/src/store_io.rs index 615d1f50f4a3..024d90576f06 100644 --- a/tvix/store/src/store_io.rs +++ b/tvix/store/src/store_io.rs @@ -131,26 +131,12 @@ impl TvixStoreIO { build_regular_ca_path(name, &nar_hash_with_mode, Vec::::new(), false).unwrap(); // assemble a new root_node with a name that is derived from the nar hash. - let renamed_root_node = { - let name = output_path.to_string().into_bytes().into(); - - match root_node { - crate::proto::node::Node::Directory(n) => { - crate::proto::node::Node::Directory(crate::proto::DirectoryNode { name, ..n }) - } - crate::proto::node::Node::File(n) => { - crate::proto::node::Node::File(crate::proto::FileNode { name, ..n }) - } - crate::proto::node::Node::Symlink(n) => { - crate::proto::node::Node::Symlink(crate::proto::SymlinkNode { name, ..n }) - } - } - }; + let root_node = root_node.rename(output_path.to_string().into_bytes().into()); // assemble the [crate::proto::PathInfo] object. let path_info = crate::proto::PathInfo { node: Some(crate::proto::Node { - node: Some(renamed_root_node), + node: Some(root_node), }), // There's no reference scanning on path contents ingested like this. references: vec![], -- cgit 1.4.1