refactor(tvix/store/proto): merge two match statements into one

Change-Id: I3daca008dff5527169f5916f4845234e8f3263cd
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9711
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: edef <edef@edef.eu>
Tested-by: BuildkiteCI
This commit is contained in:
Florian Klink 2023-10-12 19:46:56 +02:00 committed by flokli
parent 3dd5ba042b
commit 4da906bf34

View file

@ -142,40 +142,34 @@ impl PathInfo {
// Ensure there is a (root) node present, and it properly parses to a [StorePath]. // Ensure there is a (root) node present, and it properly parses to a [StorePath].
let root_nix_path = match &self.node { let root_nix_path = match &self.node {
None => { None | Some(castorepb::Node { node: None }) => {
return Err(ValidatePathInfoError::NoNodePresent()); Err(ValidatePathInfoError::NoNodePresent())?
} }
Some(castorepb::Node { node }) => match node { Some(castorepb::Node { node: Some(node) }) => {
None => { match node {
return Err(ValidatePathInfoError::NoNodePresent()); // for a directory root node, ensure the digest has the appropriate size.
} castorepb::node::Node::Directory(directory_node) => {
Some(node) => { if TryInto::<B3Digest>::try_into(directory_node.digest.clone()).is_err() {
match node { return Err(ValidatePathInfoError::InvalidNodeDigestLen(
// for a directory root node, ensure the digest has the appropriate size. directory_node.digest.len(),
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 of the node itself and return // for a file root node, ensure the digest has the appropriate size.
parse_node_name_root(node.get_name(), ValidatePathInfoError::InvalidNodeName)? 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 of the node itself and return
parse_node_name_root(node.get_name(), ValidatePathInfoError::InvalidNodeName)?
}
}; };
// return the root nix path // return the root nix path