use crate::error::BatchError;
use crate::handle::Handle;
use crate::pipeline::BatchOp;
use std::sync::Arc;
impl Handle {
pub async fn write_batch_async(
self: Arc<Self>,
batch: Vec<(std::path::PathBuf, Vec<u8>)>,
) -> std::result::Result<(), BatchError> {
let mut ops: Vec<BatchOp> = Vec::with_capacity(batch.len());
for (i, (path, data)) in batch.into_iter().enumerate() {
let resolved = self.resolve_path(&path).map_err(|e| BatchError {
failed_at: i,
completed: 0,
source: Box::new(e),
})?;
ops.push(BatchOp::Write {
path: resolved,
data,
});
}
self.submit_batch_async(ops).await
}
pub async fn delete_batch_async(
self: Arc<Self>,
batch: Vec<std::path::PathBuf>,
) -> std::result::Result<(), BatchError> {
let mut ops: Vec<BatchOp> = Vec::with_capacity(batch.len());
for (i, path) in batch.into_iter().enumerate() {
let resolved = self.resolve_path(&path).map_err(|e| BatchError {
failed_at: i,
completed: 0,
source: Box::new(e),
})?;
ops.push(BatchOp::Delete { path: resolved });
}
self.submit_batch_async(ops).await
}
pub async fn copy_batch_async(
self: Arc<Self>,
batch: Vec<(std::path::PathBuf, std::path::PathBuf)>,
) -> std::result::Result<(), BatchError> {
let mut ops: Vec<BatchOp> = Vec::with_capacity(batch.len());
for (i, (src, dst)) in batch.into_iter().enumerate() {
let resolved_src = self.resolve_path(&src).map_err(|e| BatchError {
failed_at: i,
completed: 0,
source: Box::new(e),
})?;
let resolved_dst = self.resolve_path(&dst).map_err(|e| BatchError {
failed_at: i,
completed: 0,
source: Box::new(e),
})?;
ops.push(BatchOp::Copy {
src: resolved_src,
dst: resolved_dst,
});
}
self.submit_batch_async(ops).await
}
}