feat(tvix/castore/import): generalize ingest_path

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
This commit is contained in:
Florian Klink 2023-12-31 22:30:56 +02:00 committed by clbot
parent fdd7817aad
commit ddae4860c2

View file

@ -7,8 +7,8 @@ use crate::proto::DirectoryNode;
use crate::proto::FileNode; use crate::proto::FileNode;
use crate::proto::SymlinkNode; use crate::proto::SymlinkNode;
use crate::Error as CastoreError; use crate::Error as CastoreError;
use std::ops::Deref;
use std::os::unix::ffi::OsStrExt; use std::os::unix::ffi::OsStrExt;
use std::sync::Arc;
use std::{ use std::{
collections::HashMap, collections::HashMap,
fmt::Debug, fmt::Debug,
@ -61,12 +61,15 @@ impl From<CastoreError> for Error {
// //
// It assumes the caller adds returned nodes to the directories it assembles. // 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()))] #[instrument(skip_all, fields(entry.file_type=?&entry.file_type(),entry.path=?entry.path()))]
async fn process_entry<'a>( async fn process_entry<'a, BS>(
blob_service: Arc<dyn BlobService>, blob_service: BS,
directory_putter: &'a mut Box<dyn DirectoryPutter>, directory_putter: &'a mut Box<dyn DirectoryPutter>,
entry: &'a walkdir::DirEntry, entry: &'a walkdir::DirEntry,
maybe_directory: Option<Directory>, maybe_directory: Option<Directory>,
) -> Result<Node, Error> { ) -> Result<Node, Error>
where
BS: Deref<Target = dyn BlobService> + Clone,
{
let file_type = entry.file_type(); let file_type = entry.file_type();
if file_type.is_dir() { 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 /// It's up to the caller to possibly register it somewhere (and potentially
/// rename it based on some naming scheme) /// rename it based on some naming scheme)
#[instrument(skip(blob_service, directory_service), fields(path=?p), err)] #[instrument(skip(blob_service, directory_service), fields(path=?p), err)]
pub async fn ingest_path<P: AsRef<Path> + Debug>( pub async fn ingest_path<BS, DS, P>(
blob_service: Arc<dyn BlobService>, blob_service: BS,
directory_service: Arc<dyn DirectoryService>, directory_service: DS,
p: P, 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 directories: HashMap<PathBuf, Directory> = HashMap::default();
let mut directory_putter = directory_service.put_multiple_start(); let mut directory_putter = directory_service.put_multiple_start();