refactor(tvix/src/nar): drop NARCalculationService

There's only one way to calculate NAR files, by walking through them.

Things like caching such replies should be done closer to where we use
these, composing NARCalculationService doesn't actually give us much.

Instead, expose two functions, `nar::calculate_size_and_sha256` and
`nar::writer_nar`, the latter writing NAR to a writer, the former using
write_nar to only keeping the NAR size and digest.

Change-Id: Ie5d2cfea35470fdbb5cbf9da1136b0cdf0250266
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8723
Reviewed-by: tazjin <tazjin@tvl.su>
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
This commit is contained in:
Florian Klink 2023-06-08 23:00:37 +03:00 committed by clbot
parent 27ff98000b
commit 8d05c0ceaa
11 changed files with 258 additions and 346 deletions

View file

@ -1,14 +1,10 @@
use crate::{proto, B3Digest};
use crate::B3Digest;
use data_encoding::BASE64;
use thiserror::Error;
mod grpc_nar_calculation_service;
mod non_caching_calculation_service;
mod renderer;
pub use grpc_nar_calculation_service::GRPCNARCalculationService;
pub use non_caching_calculation_service::NonCachingNARCalculationService;
pub use renderer::NARRenderer;
pub use renderer::calculate_size_and_sha256;
pub use renderer::writer_nar;
/// Errors that can encounter while rendering NARs.
#[derive(Debug, Error)]
@ -28,8 +24,3 @@ pub enum RenderError {
#[error("failure using the NAR writer: {0}")]
NARWriterError(std::io::Error),
}
/// The base trait for something calculating NARs, and returning their size and sha256.
pub trait NARCalculationService {
fn calculate_nar(&self, root_node: &proto::node::Node) -> Result<(u64, [u8; 32]), RenderError>;
}