From ddae4860c261bdcdcfd02876e7b40b775e643912 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Sun, 31 Dec 2023 22:30:56 +0200 Subject: feat(tvix/castore/import): generalize ingest_path We don't actually care if it's an Arc, 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 Autosubmit: flokli Tested-by: BuildkiteCI --- tvix/castore/src/import.rs | 24 ++++++++++++++++-------- 1 file 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 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, +async fn process_entry<'a, BS>( + blob_service: BS, directory_putter: &'a mut Box, entry: &'a walkdir::DirEntry, maybe_directory: Option, -) -> Result { +) -> Result +where + BS: Deref + 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 + Debug>( - blob_service: Arc, - directory_service: Arc, +pub async fn ingest_path( + blob_service: BS, + directory_service: DS, p: P, -) -> Result { +) -> Result +where + P: AsRef + Debug, + BS: Deref + Clone, + DS: Deref, +{ let mut directories: HashMap = HashMap::default(); let mut directory_putter = directory_service.put_multiple_start(); -- cgit 1.4.1