diff options
author | Florian Klink <flokli@flokli.de> | 2023-10-05T15·00+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-10-05T18·58+0000 |
commit | 96c0b3f069b007c9c2f05d3252a0715ea6d90fff (patch) | |
tree | 010d2ad42ec0ed83f6691f5a8b86f740b1e233e4 /tvix/store/src/proto/mod.rs | |
parent | a2c81de4cb11757642a12b941ef6caa5f78cf3bb (diff) |
refactor(tvix/store/proto): use NamedNode trait r/6715
This saves us writing the name parsing code three times. We can also delay parsing until we did other (cheaper) checks. Change-Id: I1abe3f20dba4215b38839cf7466297e028d64656 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9548 Tested-by: BuildkiteCI Reviewed-by: Connor Brewster <cbrewster@hey.com> Autosubmit: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/store/src/proto/mod.rs')
-rw-r--r-- | tvix/store/src/proto/mod.rs | 59 |
1 files changed, 28 insertions, 31 deletions
diff --git a/tvix/store/src/proto/mod.rs b/tvix/store/src/proto/mod.rs index 3bc4c2114e40..c1d9d0c46eb5 100644 --- a/tvix/store/src/proto/mod.rs +++ b/tvix/store/src/proto/mod.rs @@ -3,7 +3,10 @@ use data_encoding::BASE64; // https://github.com/hyperium/tonic/issues/1056 use nix_compat::store_path::{self, StorePath}; use thiserror::Error; -use tvix_castore::{proto as castorepb, B3Digest, B3_LEN}; +use tvix_castore::{ + proto::{self as castorepb, NamedNode}, + B3Digest, B3_LEN, +}; mod grpc_pathinfoservice_wrapper; @@ -135,37 +138,31 @@ impl PathInfo { None => { return Err(ValidatePathInfoError::NoNodePresent()); } - Some(castorepb::node::Node::Directory(directory_node)) => { - // ensure the digest has the appropriate size. - if TryInto::<B3Digest>::try_into(directory_node.digest.clone()).is_err() { - return Err(ValidatePathInfoError::InvalidNodeDigestLen( - directory_node.digest.len(), - )); + Some(node) => { + match node { + // for a directory root node, ensure the digest has the appropriate size. + castorepb::node::Node::Directory(directory_node) => { + if TryInto::<B3Digest>::try_into(directory_node.digest.clone()).is_err() + { + return Err(ValidatePathInfoError::InvalidNodeDigestLen( + directory_node.digest.len(), + )); + } + } + // for a file root node, ensure the digest has the appropriate size. + castorepb::node::Node::File(file_node) => { + // ensure the digest has the appropriate size. + if TryInto::<B3Digest>::try_into(file_node.digest.clone()).is_err() { + return Err(ValidatePathInfoError::InvalidNodeDigestLen( + file_node.digest.len(), + )); + } + } + // nothing to do specifically for symlinks + castorepb::node::Node::Symlink(_) => {} } - - // parse the name - parse_node_name_root( - &directory_node.name, - ValidatePathInfoError::InvalidNodeName, - )? - } - Some(castorepb::node::Node::File(file_node)) => { - // ensure the digest has the appropriate size. - if TryInto::<B3Digest>::try_into(file_node.digest.clone()).is_err() { - return Err(ValidatePathInfoError::InvalidNodeDigestLen( - file_node.digest.len(), - )); - } - - // parse the name - parse_node_name_root(&file_node.name, ValidatePathInfoError::InvalidNodeName)? - } - Some(castorepb::node::Node::Symlink(symlink_node)) => { - // parse the name - parse_node_name_root( - &symlink_node.name, - ValidatePathInfoError::InvalidNodeName, - )? + // parse the name of the node itself and return + parse_node_name_root(&node.get_name(), ValidatePathInfoError::InvalidNodeName)? } }, }; |