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 <cbrewster@hey.com> Tested-by: BuildkiteCI
This commit is contained in:
parent
173641ed37
commit
5f8eb4eeaa
3 changed files with 137 additions and 48 deletions
|
|
@ -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<E>(
|
||||
name: &[u8],
|
||||
err: fn(Vec<u8>, store_path::Error) -> E,
|
||||
) -> Result<StorePath, E> {
|
||||
match StorePath::from_bytes(name) {
|
||||
) -> Result<store_path::StorePath, E> {
|
||||
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<E>(
|
|||
|
||||
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<StorePath, ValidatePathInfoError> {
|
||||
pub fn validate(&self) -> Result<store_path::StorePath, ValidatePathInfoError> {
|
||||
// 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())?
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue