From 5f8eb4eeaaad31aedc45efee3143e6b0bbc982a4 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Tue, 10 Oct 2023 23:06:42 +0200 Subject: feat(tvix/store/protos): add StorePath message This encodes a store path a bit more concise, which is used in the Deriver field. Change-Id: Ibfb54d3b206917e51970d1d5fe94fcedb901704b Reviewed-on: https://cl.tvl.fyi/c/depot/+/9646 Reviewed-by: Connor Brewster Tested-by: BuildkiteCI --- tvix/store/src/proto/mod.rs | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'tvix/store/src/proto') diff --git a/tvix/store/src/proto/mod.rs b/tvix/store/src/proto/mod.rs index 7921adc4062e..718e24912de1 100644 --- a/tvix/store/src/proto/mod.rs +++ b/tvix/store/src/proto/mod.rs @@ -1,7 +1,7 @@ #![allow(clippy::derive_partial_eq_without_eq, non_snake_case)] use data_encoding::BASE64; // https://github.com/hyperium/tonic/issues/1056 -use nix_compat::store_path::{self, StorePath}; +use nix_compat::store_path; use thiserror::Error; use tvix_castore::proto::{self as castorepb, NamedNode, ValidateNodeError}; @@ -64,13 +64,13 @@ pub enum ValidatePathInfoError { /// Parses a root node name. /// -/// On success, this returns the parsed [StorePath]. +/// On success, this returns the parsed [store_path::StorePath]. /// On error, it returns an error generated from the supplied constructor. fn parse_node_name_root( name: &[u8], err: fn(Vec, store_path::Error) -> E, -) -> Result { - match StorePath::from_bytes(name) { +) -> Result { + match store_path::StorePath::from_bytes(name) { Ok(np) => Ok(np), Err(e) => Err(err(name.to_vec(), e)), } @@ -78,9 +78,9 @@ fn parse_node_name_root( impl PathInfo { /// validate performs some checks on the PathInfo struct, - /// Returning either a [StorePath] of the root node, or a + /// Returning either a [store_path::StorePath] of the root node, or a /// [ValidatePathInfoError]. - pub fn validate(&self) -> Result { + pub fn validate(&self) -> Result { // ensure the references have the right number of bytes. for (i, reference) in self.references.iter().enumerate() { if reference.len() != store_path::DIGEST_SIZE { @@ -111,13 +111,15 @@ impl PathInfo { // parse references in reference_names. for (i, reference_name_str) in narinfo.reference_names.iter().enumerate() { // ensure thy parse as (non-absolute) store path - let reference_names_store_path = - StorePath::from_bytes(reference_name_str.as_bytes()).map_err(|_| { - ValidatePathInfoError::InvalidNarinfoReferenceName( - i, - reference_name_str.to_owned(), - ) - })?; + let reference_names_store_path = store_path::StorePath::from_bytes( + reference_name_str.as_bytes(), + ) + .map_err(|_| { + ValidatePathInfoError::InvalidNarinfoReferenceName( + i, + reference_name_str.to_owned(), + ) + })?; // ensure their digest matches the one at self.references[i]. { @@ -137,7 +139,7 @@ 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 [store_path::StorePath]. let root_nix_path = match &self.node { None | Some(castorepb::Node { node: None }) => { Err(ValidatePathInfoError::NoNodePresent())? -- cgit 1.4.1