diff options
author | Florian Klink <flokli@flokli.de> | 2023-12-31T20·30+0200 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-01-01T00·54+0000 |
commit | ddae4860c261bdcdcfd02876e7b40b775e643912 (patch) | |
tree | 62a07da18530b4081d482f5d228b83aff9402dbb | |
parent | fdd7817aad18346197a521593bdafdae4045aeb6 (diff) |
feat(tvix/castore/import): generalize ingest_path r/7300
We don't actually care if it's an Arc<dyn BlobService>, or something else, as long as we can Deref to a BlobService and clone. Change-Id: I0852aaf723f51c5e6b820be8db1199d17309ab08 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10510 Reviewed-by: raitobezarius <tvl@lahfa.xyz> Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
-rw-r--r-- | tvix/castore/src/import.rs | 24 |
1 files changed, 16 insertions, 8 deletions
diff --git a/tvix/castore/src/import.rs b/tvix/castore/src/import.rs index e933205ab6bd..1b8c4ec5a54e 100644 --- a/tvix/castore/src/import.rs +++ b/tvix/castore/src/import.rs @@ -7,8 +7,8 @@ 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::sync::Arc; use std::{ collections::HashMap, fmt::Debug, @@ -61,12 +61,15 @@ impl From<CastoreError> for Error { // // It assumes the caller adds returned nodes to the directories it assembles. #[instrument(skip_all, fields(entry.file_type=?&entry.file_type(),entry.path=?entry.path()))] -async fn process_entry<'a>( - blob_service: Arc<dyn BlobService>, +async fn process_entry<'a, BS>( + blob_service: BS, directory_putter: &'a mut Box<dyn DirectoryPutter>, entry: &'a walkdir::DirEntry, maybe_directory: Option<Directory>, -) -> Result<Node, Error> { +) -> Result<Node, Error> +where + BS: Deref<Target = dyn BlobService> + Clone, +{ let file_type = entry.file_type(); if file_type.is_dir() { @@ -146,11 +149,16 @@ async fn process_entry<'a>( /// It's up to the caller to possibly register it somewhere (and potentially /// rename it based on some naming scheme) #[instrument(skip(blob_service, directory_service), fields(path=?p), err)] -pub async fn ingest_path<P: AsRef<Path> + Debug>( - blob_service: Arc<dyn BlobService>, - directory_service: Arc<dyn DirectoryService>, +pub async fn ingest_path<BS, DS, P>( + blob_service: BS, + directory_service: DS, p: P, -) -> Result<Node, Error> { +) -> Result<Node, Error> +where + P: AsRef<Path> + Debug, + BS: Deref<Target = dyn BlobService> + Clone, + DS: Deref<Target = dyn DirectoryService>, +{ let mut directories: HashMap<PathBuf, Directory> = HashMap::default(); let mut directory_putter = directory_service.put_multiple_start(); |