diff options
author | Florian Klink <flokli@flokli.de> | 2023-06-08T20·00+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-06-12T10·15+0000 |
commit | 8d05c0ceaa9bddb7fdaab436730f093eb16374a2 (patch) | |
tree | 33e034ae01b219d413247f1f93ea383133bd8062 /tvix/store/src/store_io.rs | |
parent | 27ff98000b0cdf0ed30eb8837c7d44cd3e79d32f (diff) |
refactor(tvix/src/nar): drop NARCalculationService r/6270
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>
Diffstat (limited to 'tvix/store/src/store_io.rs')
-rw-r--r-- | tvix/store/src/store_io.rs | 25 |
1 files changed, 10 insertions, 15 deletions
diff --git a/tvix/store/src/store_io.rs b/tvix/store/src/store_io.rs index a2967c06ff98..3820931e281f 100644 --- a/tvix/store/src/store_io.rs +++ b/tvix/store/src/store_io.rs @@ -16,7 +16,7 @@ use crate::{ blobservice::BlobService, directoryservice::{self, DirectoryService}, import, - nar::NARCalculationService, + nar::calculate_size_and_sha256, pathinfoservice::PathInfoService, proto::NamedNode, B3Digest, @@ -29,28 +29,23 @@ 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<DS: DirectoryService, PS: PathInfoService, NCS: NARCalculationService> { +pub struct TvixStoreIO<DS: DirectoryService, PS: PathInfoService> { blob_service: Box<dyn BlobService>, directory_service: DS, path_info_service: PS, - nar_calculation_service: NCS, std_io: StdIO, } -impl<DS: DirectoryService, PS: PathInfoService, NCS: NARCalculationService> - TvixStoreIO<DS, PS, NCS> -{ +impl<DS: DirectoryService + Clone, PS: PathInfoService> TvixStoreIO<DS, PS> { pub fn new( blob_service: Box<dyn BlobService>, directory_service: DS, path_info_service: PS, - nar_calculation_service: NCS, ) -> Self { Self { blob_service, directory_service, path_info_service, - nar_calculation_service, std_io: StdIO {}, } } @@ -109,10 +104,12 @@ impl<DS: DirectoryService, PS: PathInfoService, NCS: NARCalculationService> .expect("error during import_path"); // Render the NAR - let (nar_size, nar_sha256) = self - .nar_calculation_service - .calculate_nar(&root_node) - .expect("error during nar calculation"); // TODO: handle error + let (nar_size, nar_sha256) = calculate_size_and_sha256( + &root_node, + &self.blob_service, + self.directory_service.clone(), + ) + .expect("error during nar calculation"); // TODO: handle error // For given NAR sha256 digest and name, return the new [StorePath] this would have. let nar_hash_with_mode = @@ -178,9 +175,7 @@ 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<DS: DirectoryService, PS: PathInfoService, NCS: NARCalculationService> EvalIO - for TvixStoreIO<DS, PS, NCS> -{ +impl<DS: DirectoryService + Clone, PS: PathInfoService> EvalIO for TvixStoreIO<DS, PS> { #[instrument(skip(self), ret, err)] fn path_exists(&self, path: &Path) -> Result<bool, io::Error> { if let Ok((store_path, sub_path)) = |