about summary refs log tree commit diff
path: root/tvix/store/src/store_io.rs
diff options
context:
space:
mode:
authorFlorian Klink <flokli@flokli.de>2023-06-09T15·22+0300
committerclbot <clbot@tvl.fyi>2023-06-12T10·24+0000
commitaa7bdc1199bfbb69091dda942a82812257e30bc4 (patch)
tree933964562f5746274ef6df59cfa956aca73b0807 /tvix/store/src/store_io.rs
parent7725eb53ad67730e92a3839a6c10925c668e5586 (diff)
refactor(tvix/store): use Arc instead of Box r/6273
This allows us to blob services without closing them before putting them
in a box.
We currently need to use Arc<_>, not Rc<_>, because the GRPC wrappers
require Sync.

Change-Id: I679c5f06b62304f5b0456cfefe25a0a881de7c84
Reviewed-on: https://cl.tvl.fyi/c/depot/+/8738
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.rs29
1 files changed, 18 insertions, 11 deletions
diff --git a/tvix/store/src/store_io.rs b/tvix/store/src/store_io.rs
index ee302f3b58ba..c35da49da998 100644
--- a/tvix/store/src/store_io.rs
+++ b/tvix/store/src/store_io.rs
@@ -8,7 +8,7 @@ use nix_compat::{
     store_path::{build_regular_ca_path, StorePath},
 };
 use smol_str::SmolStr;
-use std::{io, path::Path, path::PathBuf};
+use std::{io, path::Path, path::PathBuf, sync::Arc};
 use tracing::{error, instrument, warn};
 use tvix_eval::{EvalIO, FileType, StdIO};
 
@@ -30,16 +30,16 @@ use crate::{
 /// on the filesystem (still managed by Nix), as well as being able to read
 /// files outside store paths.
 pub struct TvixStoreIO<PS: PathInfoService> {
-    blob_service: Box<dyn BlobService>,
-    directory_service: Box<dyn DirectoryService>,
+    blob_service: Arc<dyn BlobService>,
+    directory_service: Arc<dyn DirectoryService>,
     path_info_service: PS,
     std_io: StdIO,
 }
 
 impl<PS: PathInfoService> TvixStoreIO<PS> {
     pub fn new(
-        blob_service: Box<dyn BlobService>,
-        directory_service: Box<dyn DirectoryService>,
+        blob_service: Arc<dyn BlobService>,
+        directory_service: Arc<dyn DirectoryService>,
         path_info_service: PS,
     ) -> Self {
         Self {
@@ -86,7 +86,7 @@ impl<PS: PathInfoService> TvixStoreIO<PS> {
             }
         };
 
-        directoryservice::traverse_to(&self.directory_service, root_node, sub_path)
+        directoryservice::traverse_to(self.directory_service.clone(), root_node, sub_path)
     }
 
     /// Imports a given path on the filesystem into the store, and returns the
@@ -100,13 +100,20 @@ impl<PS: PathInfoService> TvixStoreIO<PS> {
         path: &std::path::Path,
     ) -> Result<crate::proto::PathInfo, io::Error> {
         // Call [import::ingest_path], which will walk over the given path and return a root_node.
-        let root_node = import::ingest_path(&self.blob_service, &self.directory_service, path)
-            .expect("error during import_path");
+        let root_node = import::ingest_path(
+            self.blob_service.clone(),
+            self.directory_service.clone(),
+            path,
+        )
+        .expect("error during import_path");
 
         // Render the NAR
-        let (nar_size, nar_sha256) =
-            calculate_size_and_sha256(&root_node, &self.blob_service, &self.directory_service)
-                .expect("error during nar calculation"); // TODO: handle error
+        let (nar_size, nar_sha256) = calculate_size_and_sha256(
+            &root_node,
+            self.blob_service.clone(),
+            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 =