delete multiple files with selection
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
use anyhow::{Context as _, anyhow, bail};
|
||||
use futures_util::TryStreamExt;
|
||||
use futures_util::{TryStreamExt, future::join_all};
|
||||
use rustix::fs::{Statx, statx};
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
@@ -182,10 +182,10 @@ impl FileSystem {
|
||||
|
||||
/// Actually removes a file or directory from the underlying file system
|
||||
///
|
||||
/// * `path`: The directory's absolute path (absolute not in relation to the root file system but `self.base_directory`)
|
||||
/// * `path`: The file's absolute path (absolute not in relation to the root file system but `self.base_directory`)
|
||||
/// * `force`: Whether to delete directories that are not empty
|
||||
async fn rm(&self, path: &AbsoluteFilePath, force: bool) -> io::Result<()> {
|
||||
let file_path = self.get_target_path(path);
|
||||
let file_path = self.get_target_path(&path);
|
||||
|
||||
if fs::metadata(&file_path).await?.is_file() {
|
||||
return fs::remove_file(&file_path).await;
|
||||
@@ -412,14 +412,34 @@ impl FileSystemRepository for FileSystem {
|
||||
})
|
||||
}
|
||||
|
||||
async fn rm(&self, request: RmRequest) -> Result<(), RmError> {
|
||||
self.rm(request.path(), request.force())
|
||||
.await
|
||||
.map_err(|e| match e.kind() {
|
||||
std::io::ErrorKind::NotFound => RmError::NotFound,
|
||||
std::io::ErrorKind::DirectoryNotEmpty => RmError::NotEmpty,
|
||||
_ => anyhow!("Failed to delete file at {}: {e:?}", request.path()).into(),
|
||||
})
|
||||
async fn rm(&self, request: RmRequest) -> Vec<Result<AbsoluteFilePath, RmError>> {
|
||||
let force = request.force();
|
||||
let paths: Vec<AbsoluteFilePath> = request.into_paths().into();
|
||||
|
||||
async fn _rm(
|
||||
fs: &FileSystem,
|
||||
path: AbsoluteFilePath,
|
||||
force: bool,
|
||||
) -> Result<AbsoluteFilePath, RmError> {
|
||||
fs.rm(&path, force)
|
||||
.await
|
||||
.map(|_| path.clone())
|
||||
.map_err(|e| match e.kind() {
|
||||
std::io::ErrorKind::NotFound => RmError::NotFound(path),
|
||||
std::io::ErrorKind::DirectoryNotEmpty => RmError::NotEmpty(path),
|
||||
_ => anyhow!("Failed to delete file at {}: {e:?}", path).into(),
|
||||
})
|
||||
}
|
||||
|
||||
let results: Vec<Result<AbsoluteFilePath, RmError>> = join_all(
|
||||
paths
|
||||
.into_iter()
|
||||
.map(|path| _rm(&self, path, force))
|
||||
.collect::<Vec<_>>(),
|
||||
)
|
||||
.await;
|
||||
|
||||
results
|
||||
}
|
||||
|
||||
async fn mv(&self, request: MvRequest) -> Result<(), MvError> {
|
||||
|
||||
Reference in New Issue
Block a user