diff options
Diffstat (limited to 'tvix/castore/src')
-rw-r--r-- | tvix/castore/src/fs/mod.rs | 13 | ||||
-rw-r--r-- | tvix/castore/src/fs/root_nodes.rs | 10 | ||||
-rw-r--r-- | tvix/castore/src/fs/tests.rs | 5 | ||||
-rw-r--r-- | tvix/castore/src/import.rs | 11 | ||||
-rw-r--r-- | tvix/castore/src/tests/import.rs | 26 |
5 files changed, 29 insertions, 36 deletions
diff --git a/tvix/castore/src/fs/mod.rs b/tvix/castore/src/fs/mod.rs index 2da072329d34..632dad84cf86 100644 --- a/tvix/castore/src/fs/mod.rs +++ b/tvix/castore/src/fs/mod.rs @@ -23,7 +23,6 @@ use fuse_backend_rs::abi::fuse_abi::stat64; use fuse_backend_rs::api::filesystem::{Context, FileSystem, FsOptions, ROOT_ID}; use futures::StreamExt; use parking_lot::RwLock; -use std::ops::Deref; use std::{ collections::HashMap, io, @@ -101,8 +100,8 @@ pub struct TvixStoreFs<BS, DS, RN> { impl<BS, DS, RN> TvixStoreFs<BS, DS, RN> where - BS: Deref<Target = dyn BlobService> + Clone + Send, - DS: Deref<Target = dyn DirectoryService> + Clone + Send + 'static, + BS: AsRef<dyn BlobService> + Clone + Send, + DS: AsRef<dyn DirectoryService> + Clone + Send + 'static, RN: RootNodes + Clone + 'static, { pub fn new( @@ -157,7 +156,7 @@ where .block_on(self.tokio_handle.spawn({ let directory_service = self.directory_service.clone(); let parent_digest = parent_digest.to_owned(); - async move { directory_service.get(&parent_digest).await } + async move { directory_service.as_ref().get(&parent_digest).await } })) .unwrap()? .ok_or_else(|| { @@ -270,8 +269,8 @@ where impl<BS, DS, RN> FileSystem for TvixStoreFs<BS, DS, RN> where - BS: Deref<Target = dyn BlobService> + Clone + Send + 'static, - DS: Deref<Target = dyn DirectoryService> + Send + Clone + 'static, + BS: AsRef<dyn BlobService> + Clone + Send + 'static, + DS: AsRef<dyn DirectoryService> + Send + Clone + 'static, RN: RootNodes + Clone + 'static, { type Handle = u64; @@ -496,7 +495,7 @@ where let task = self .tokio_handle - .spawn(async move { blob_service.open_read(&blob_digest).await }); + .spawn(async move { blob_service.as_ref().open_read(&blob_digest).await }); let blob_reader = self.tokio_handle.block_on(task).unwrap(); diff --git a/tvix/castore/src/fs/root_nodes.rs b/tvix/castore/src/fs/root_nodes.rs index 312a0b2cdd7e..a603fd1b37d5 100644 --- a/tvix/castore/src/fs/root_nodes.rs +++ b/tvix/castore/src/fs/root_nodes.rs @@ -1,4 +1,4 @@ -use std::{collections::BTreeMap, ops::Deref, pin::Pin}; +use std::{collections::BTreeMap, pin::Pin}; use crate::{proto::node::Node, Error}; use bytes::Bytes; @@ -23,13 +23,15 @@ pub trait RootNodes: Send + Sync { /// the key is the node name. impl<T> RootNodes for T where - T: Deref<Target = BTreeMap<Bytes, Node>> + Send + Sync, + T: AsRef<BTreeMap<Bytes, Node>> + Send + Sync, { async fn get_by_basename(&self, name: &[u8]) -> Result<Option<Node>, Error> { - Ok(self.get(name).cloned()) + Ok(self.as_ref().get(name).cloned()) } fn list(&self) -> Pin<Box<dyn Stream<Item = Result<Node, Error>> + Send + '_>> { - Box::pin(tokio_stream::iter(self.iter().map(|(_, v)| Ok(v.clone())))) + Box::pin(tokio_stream::iter( + self.as_ref().iter().map(|(_, v)| Ok(v.clone())), + )) } } diff --git a/tvix/castore/src/fs/tests.rs b/tvix/castore/src/fs/tests.rs index 5f2916abd44f..2f27c3c1c8e4 100644 --- a/tvix/castore/src/fs/tests.rs +++ b/tvix/castore/src/fs/tests.rs @@ -1,7 +1,6 @@ use std::{ collections::BTreeMap, io::{self, Cursor}, - ops::Deref, os::unix::fs::MetadataExt, path::Path, sync::Arc, @@ -43,8 +42,8 @@ fn do_mount<P: AsRef<Path>, BS, DS>( list_root: bool, ) -> io::Result<FuseDaemon> where - BS: Deref<Target = dyn BlobService> + Send + Sync + Clone + 'static, - DS: Deref<Target = dyn DirectoryService> + Send + Sync + Clone + 'static, + BS: AsRef<dyn BlobService> + Send + Sync + Clone + 'static, + DS: AsRef<dyn DirectoryService> + Send + Sync + Clone + 'static, { let fs = TvixStoreFs::new( blob_service, diff --git a/tvix/castore/src/import.rs b/tvix/castore/src/import.rs index c4d410497235..cf4b42fb6826 100644 --- a/tvix/castore/src/import.rs +++ b/tvix/castore/src/import.rs @@ -7,7 +7,6 @@ use crate::proto::DirectoryNode; use crate::proto::FileNode; use crate::proto::SymlinkNode; use crate::Error as CastoreError; -use std::ops::Deref; use std::os::unix::ffi::OsStrExt; use std::{ collections::HashMap, @@ -68,7 +67,7 @@ async fn process_entry<'a, BS>( maybe_directory: Option<Directory>, ) -> Result<Node, Error> where - BS: Deref<Target = dyn BlobService> + Clone, + BS: AsRef<dyn BlobService> + Clone, { let file_type = entry.file_type(); @@ -114,7 +113,7 @@ where .await .map_err(|e| Error::UnableToOpen(entry.path().to_path_buf(), e))?; - let mut writer = blob_service.open_write().await; + let mut writer = blob_service.as_ref().open_write().await; if let Err(e) = tokio::io::copy(&mut file, &mut writer).await { return Err(Error::UnableToRead(entry.path().to_path_buf(), e)); @@ -156,12 +155,12 @@ pub async fn ingest_path<'a, BS, DS, P>( ) -> Result<Node, Error> where P: AsRef<Path> + Debug, - BS: Deref<Target = dyn BlobService> + Clone, - DS: Deref<Target = &'a dyn DirectoryService>, + BS: AsRef<dyn BlobService> + Clone, + DS: AsRef<dyn DirectoryService>, { let mut directories: HashMap<PathBuf, Directory> = HashMap::default(); - let mut directory_putter = directory_service.put_multiple_start(); + let mut directory_putter = directory_service.as_ref().put_multiple_start(); for entry in WalkDir::new(p.as_ref()) .follow_links(false) diff --git a/tvix/castore/src/tests/import.rs b/tvix/castore/src/tests/import.rs index 333254706d61..99e993f36da3 100644 --- a/tvix/castore/src/tests/import.rs +++ b/tvix/castore/src/tests/import.rs @@ -1,10 +1,8 @@ use crate::blobservice::BlobService; -use crate::directoryservice::DirectoryService; use crate::fixtures::*; use crate::import::ingest_path; use crate::proto; use crate::utils::{gen_blob_service, gen_directory_service}; -use std::ops::Deref; use std::sync::Arc; use tempfile::TempDir; @@ -14,8 +12,8 @@ use std::os::unix::ffi::OsStrExt; #[cfg(target_family = "unix")] #[tokio::test] async fn symlink() { - let blob_service: Arc<dyn BlobService> = gen_blob_service().into(); - let directory_service: Arc<dyn DirectoryService> = gen_directory_service().into(); + let blob_service = gen_blob_service(); + let directory_service = gen_directory_service(); let tmpdir = TempDir::new().unwrap(); @@ -27,8 +25,8 @@ async fn symlink() { .unwrap(); let root_node = ingest_path( - blob_service, - &directory_service.deref(), + Arc::from(blob_service), + directory_service, tmpdir.path().join("doesntmatter"), ) .await @@ -46,7 +44,7 @@ async fn symlink() { #[tokio::test] async fn single_file() { let blob_service: Arc<dyn BlobService> = gen_blob_service().into(); - let directory_service: Arc<dyn DirectoryService> = gen_directory_service().into(); + let directory_service = gen_directory_service(); let tmpdir = TempDir::new().unwrap(); @@ -54,7 +52,7 @@ async fn single_file() { let root_node = ingest_path( blob_service.clone(), - &directory_service.deref(), + directory_service, tmpdir.path().join("root"), ) .await @@ -78,7 +76,7 @@ async fn single_file() { #[tokio::test] async fn complicated() { let blob_service: Arc<dyn BlobService> = gen_blob_service().into(); - let directory_service: Arc<dyn DirectoryService> = gen_directory_service().into(); + let directory_service = gen_directory_service(); let tmpdir = TempDir::new().unwrap(); @@ -91,13 +89,9 @@ async fn complicated() { // File ``keep/.keep` std::fs::write(tmpdir.path().join("keep").join(".keep"), vec![]).unwrap(); - let root_node = ingest_path( - blob_service.clone(), - &directory_service.deref(), - tmpdir.path(), - ) - .await - .expect("must succeed"); + let root_node = ingest_path(blob_service.clone(), &directory_service, tmpdir.path()) + .await + .expect("must succeed"); // ensure root_node matched expectations assert_eq!( |