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:
parent
5d3f3158d6
commit
3ca0b53840
53 changed files with 1429 additions and 1377 deletions
|
|
@ -179,9 +179,7 @@ pub(crate) mod derivation_builtins {
|
|||
use nix_compat::nixhash::CAHash;
|
||||
use nix_compat::store_path::{build_ca_path, hash_placeholder};
|
||||
use sha2::Sha256;
|
||||
use tvix_castore::proto as castorepb;
|
||||
use tvix_castore::proto::node::Node;
|
||||
use tvix_castore::proto::FileNode;
|
||||
use tvix_castore::directoryservice::{FileNode, Node};
|
||||
use tvix_eval::generators::Gen;
|
||||
use tvix_eval::{NixContext, NixContextElement, NixString};
|
||||
use tvix_store::proto::{NarInfo, PathInfo};
|
||||
|
|
@ -579,12 +577,10 @@ pub(crate) mod derivation_builtins {
|
|||
})
|
||||
.map_err(DerivationError::InvalidDerivation)?;
|
||||
|
||||
let root_node = Node::File(FileNode {
|
||||
name: store_path.to_string().into(),
|
||||
digest: blob_digest.into(),
|
||||
size: blob_size,
|
||||
executable: false,
|
||||
});
|
||||
let root_node = Node::File(
|
||||
FileNode::new(store_path.to_string().into(), blob_digest, blob_size, false)
|
||||
.map_err(|e| ErrorKind::TvixError(Rc::new(e)))?,
|
||||
);
|
||||
|
||||
// calculate the nar hash
|
||||
let (nar_size, nar_sha256) = state
|
||||
|
|
@ -604,9 +600,7 @@ pub(crate) mod derivation_builtins {
|
|||
state
|
||||
.path_info_service
|
||||
.put(PathInfo {
|
||||
node: Some(castorepb::Node {
|
||||
node: Some(root_node),
|
||||
}),
|
||||
node: Some((&root_node).into()),
|
||||
references: reference_paths
|
||||
.iter()
|
||||
.map(|x| bytes::Bytes::copy_from_slice(x.digest()))
|
||||
|
|
|
|||
|
|
@ -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<tvix_castore::proto::node::Node, ErrorKind> {
|
||||
) -> Result<Node, ErrorKind> {
|
||||
let mut entries: Vec<walkdir::DirEntry> = 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue