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 <flokli@flokli.de>
This commit is contained in:
Yureka 2024-07-29 14:34:50 +02:00 committed by yuka
parent 5d3f3158d6
commit 3ca0b53840
53 changed files with 1429 additions and 1377 deletions

View file

@ -1,8 +1,9 @@
use std::path::Path;
use tracing::{debug, instrument};
use tvix_castore::{
blobservice::BlobService, directoryservice::DirectoryService, import::fs::ingest_path,
proto::node::Node, B3Digest,
blobservice::BlobService,
directoryservice::{DirectoryService, NamedNode, Node},
import::fs::ingest_path,
};
use nix_compat::{
@ -32,24 +33,24 @@ pub fn log_node(node: &Node, path: &Path) {
Node::Directory(directory_node) => {
debug!(
path = ?path,
name = ?directory_node.name,
digest = %B3Digest::try_from(directory_node.digest.clone()).unwrap(),
name = ?directory_node.get_name(),
digest = %directory_node.digest(),
"import successful",
)
}
Node::File(file_node) => {
debug!(
path = ?path,
name = ?file_node.name,
digest = %B3Digest::try_from(file_node.digest.clone()).unwrap(),
name = ?file_node.get_name(),
digest = %file_node.digest(),
"import successful"
)
}
Node::Symlink(symlink_node) => {
debug!(
path = ?path,
name = ?symlink_node.name,
target = ?symlink_node.target,
name = ?symlink_node.get_name(),
target = ?symlink_node.target(),
"import successful"
)
}
@ -87,7 +88,7 @@ pub fn derive_nar_ca_path_info(
// assemble the [crate::proto::PathInfo] object.
PathInfo {
node: Some(tvix_castore::proto::Node {
node: Some(root_node),
node: Some((&root_node).into()),
}),
// There's no reference scanning on path contents ingested like this.
references: vec![],