From 3fda90602d3de7a720149f090422c4da9d12d31d Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Fri, 18 Oct 2024 21:42:04 +0200 Subject: refactor(tvix/castore): add try_into_anonymous_node, rename to try_* MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We have two places where we parse protos and want their names to be empty: - Receiving a root node in a nar-bridge NAR request - Processing the CalculateNAR gRPC call We don't have any place where we want to keep a name as bytes::Bytes around, yet we used the `into_name_bytes_and_node` method. It was also a bit wrongly named - it wasn't very clear the name was not validated, and that the function may fail. This moves the "splitting off the name as bytes::Bytes" part into a private helper, only leaving the `try_into_name_and_node` and `try_into_anonymous_node` methods around. Change-Id: I2c7fd9871d49ec67450d7efa6a30d96197fb319c Reviewed-on: https://cl.tvl.fyi/c/depot/+/12664 Autosubmit: flokli Tested-by: BuildkiteCI Reviewed-by: Marijan Petričević Reviewed-by: raitobezarius --- tvix/nar-bridge/src/nar.rs | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) (limited to 'tvix/nar-bridge') diff --git a/tvix/nar-bridge/src/nar.rs b/tvix/nar-bridge/src/nar.rs index d88719b02be9..abc0d854d7c7 100644 --- a/tvix/nar-bridge/src/nar.rs +++ b/tvix/nar-bridge/src/nar.rs @@ -56,16 +56,11 @@ pub async fn get_head( StatusCode::NOT_FOUND })?; - let (root_name, root_node) = root_node.into_name_bytes_and_node().map_err(|e| { + let root_node = root_node.try_into_anonymous_node().map_err(|e| { warn!(err=%e, "root node validation failed"); StatusCode::BAD_REQUEST })?; - if !root_name.as_ref().is_empty() { - warn!("root node has name, which it shouldn't"); - return Err(StatusCode::BAD_REQUEST); - } - Ok(( // headers [ -- cgit 1.4.1