feat(tvix/store): eliminate generics in BlobStore

To construct various stores at runtime, we need to eliminate associated
types from the BlobService trait, and return Box<dyn …> instead of
specific types.

This also means we can't consume self in the close() method, so
everything we write to is put in an Option<>, and during the first close
we take from there.

Change-Id: Ia523b6ab2f2a5276f51cb5d17e81a5925bce69b6
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8647
Autosubmit: flokli <flokli@flokli.de>
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
This commit is contained in:
Florian Klink 2023-05-25 17:52:08 +03:00 committed by clbot
parent 5139cc45c2
commit 27ff98000b
15 changed files with 227 additions and 140 deletions

View file

@ -29,24 +29,19 @@ use crate::{
/// This is to both cover cases of syntactically valid store paths, that exist
/// on the filesystem (still managed by Nix), as well as being able to read
/// files outside store paths.
pub struct TvixStoreIO<
BS: BlobService,
DS: DirectoryService,
PS: PathInfoService,
NCS: NARCalculationService,
> {
blob_service: BS,
pub struct TvixStoreIO<DS: DirectoryService, PS: PathInfoService, NCS: NARCalculationService> {
blob_service: Box<dyn BlobService>,
directory_service: DS,
path_info_service: PS,
nar_calculation_service: NCS,
std_io: StdIO,
}
impl<BS: BlobService, DS: DirectoryService, PS: PathInfoService, NCS: NARCalculationService>
TvixStoreIO<BS, DS, PS, NCS>
impl<DS: DirectoryService, PS: PathInfoService, NCS: NARCalculationService>
TvixStoreIO<DS, PS, NCS>
{
pub fn new(
blob_service: BS,
blob_service: Box<dyn BlobService>,
directory_service: DS,
path_info_service: PS,
nar_calculation_service: NCS,
@ -183,8 +178,8 @@ fn calculate_nar_based_store_path(nar_sha256_digest: &[u8; 32], name: &str) -> S
build_regular_ca_path(name, &nar_hash_with_mode, Vec::<String>::new(), false).unwrap()
}
impl<BS: BlobService, DS: DirectoryService, PS: PathInfoService, NCS: NARCalculationService> EvalIO
for TvixStoreIO<BS, DS, PS, NCS>
impl<DS: DirectoryService, PS: PathInfoService, NCS: NARCalculationService> EvalIO
for TvixStoreIO<DS, PS, NCS>
{
#[instrument(skip(self), ret, err)]
fn path_exists(&self, path: &Path) -> Result<bool, io::Error> {