From 3ca0b53840b352b24f3a315404df11458b0bdbbb Mon Sep 17 00:00:00 2001 From: Yureka Date: Mon, 29 Jul 2024 14:34:50 +0200 Subject: refactor(tvix/castore): use Directory struct separate from proto one This uses our own data type to deal with Directories in the castore model. It makes some undesired states unrepresentable, removing the need for conversions and checking in various places: - In the protobuf, blake3 digests could have a wrong length, as proto doesn't know fixed-size fields. We now use `B3Digest`, which makes cloning cheaper, and removes the need to do size-checking everywhere. - In the protobuf, we had three different lists for `files`, `symlinks` and `directories`. This was mostly a protobuf size optimization, but made interacting with them a bit awkward. This has now been replaced with a list of enums, and convenience iterators to get various nodes, and add new ones. Change-Id: I7b92691bb06d77ff3f58a5ccea94a22c16f84f04 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12057 Tested-by: BuildkiteCI Reviewed-by: flokli --- tvix/glue/src/builtins/import.rs | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'tvix/glue/src/builtins/import.rs') diff --git a/tvix/glue/src/builtins/import.rs b/tvix/glue/src/builtins/import.rs index 273be08ef7b6..aa0d0d54fc8a 100644 --- a/tvix/glue/src/builtins/import.rs +++ b/tvix/glue/src/builtins/import.rs @@ -2,6 +2,8 @@ use crate::builtins::errors::ImportError; use std::path::Path; +use tvix_castore::directoryservice::FileNode; +use tvix_castore::directoryservice::Node; use tvix_castore::import::ingest_entries; use tvix_eval::{ builtin_macros::builtins, @@ -16,7 +18,7 @@ async fn filtered_ingest( co: GenCo, path: &Path, filter: Option<&Value>, -) -> Result { +) -> Result { let mut entries: Vec = vec![]; let mut it = walkdir::WalkDir::new(path) .follow_links(false) @@ -114,8 +116,6 @@ mod import_builtins { use nix_compat::store_path::StorePath; use sha2::Digest; use tokio::io::AsyncWriteExt; - use tvix_castore::proto::node::Node; - use tvix_castore::proto::FileNode; use tvix_eval::builtins::coerce_value_to_path; use tvix_eval::generators::Gen; use tvix_eval::{generators::GenCo, ErrorKind, Value}; @@ -214,13 +214,16 @@ mod import_builtins { .tokio_handle .block_on(async { blob_writer.close().await })?; - let root_node = Node::File(FileNode { - // The name gets set further down, while constructing the PathInfo. - name: "".into(), - digest: blob_digest.into(), - size: blob_size, - executable: false, - }); + let root_node = Node::File( + FileNode::new( + // The name gets set further down, while constructing the PathInfo. + "".into(), + blob_digest, + blob_size, + false, + ) + .map_err(|e| tvix_eval::ErrorKind::TvixError(Rc::new(e)))?, + ); let ca_hash = if recursive_ingestion { let (_nar_size, nar_sha256) = state -- cgit 1.4.1