mirror of
https://git.proxmox.com/git/proxmox-backup
synced 2025-07-30 02:35:30 +00:00
pxar: tools: inline async recursion
this works since rustc 1.77, and makes the code less verbose. Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
This commit is contained in:
parent
5ddd59e167
commit
dd16eabe19
@ -1,16 +1,14 @@
|
|||||||
//! Some common methods used within the pxar code.
|
//! Some common methods used within the pxar code.
|
||||||
|
|
||||||
use std::ffi::OsStr;
|
use std::ffi::OsStr;
|
||||||
use std::future::Future;
|
|
||||||
use std::os::unix::ffi::OsStrExt;
|
use std::os::unix::ffi::OsStrExt;
|
||||||
use std::path::{Path, PathBuf};
|
use std::path::{Path, PathBuf};
|
||||||
use std::pin::Pin;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use anyhow::{bail, format_err, Context, Error};
|
use anyhow::{bail, format_err, Context, Error};
|
||||||
use nix::sys::stat::Mode;
|
use nix::sys::stat::Mode;
|
||||||
|
|
||||||
use pathpatterns::{MatchList, MatchType};
|
use pathpatterns::MatchType;
|
||||||
use pxar::accessor::aio::{Accessor, Directory, FileEntry};
|
use pxar::accessor::aio::{Accessor, Directory, FileEntry};
|
||||||
use pxar::accessor::ReadAt;
|
use pxar::accessor::ReadAt;
|
||||||
use pxar::format::StatxTimestamp;
|
use pxar::format::StatxTimestamp;
|
||||||
@ -415,11 +413,14 @@ pub(crate) async fn pxar_metadata_read_dir<T: Clone + Send + Sync + ReadAt>(
|
|||||||
Ok(entries)
|
Ok(entries)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Dump pxar archive entry by using the same format used to dump entries from a catalog.
|
/// Recursively iterate over pxar archive entries and dump them using the same format used to dump
|
||||||
fn pxar_metadata_catalog_dump_entry<'future, T: Clone + Send + Sync + ReadAt + 'future>(
|
/// entries from a catalog.
|
||||||
entry: FileEntry<T>,
|
pub async fn pxar_metadata_catalog_dump_dir<T: Clone + Send + Sync + ReadAt>(
|
||||||
path_prefix: Option<&'future str>,
|
parent_dir: Directory<T>,
|
||||||
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'future>> {
|
path_prefix: Option<&str>,
|
||||||
|
) -> Result<(), Error> {
|
||||||
|
let entries = pxar_metadata_read_dir(parent_dir).await?;
|
||||||
|
for entry in entries {
|
||||||
let entry_path = entry_path_with_prefix(&entry, path_prefix);
|
let entry_path = entry_path_with_prefix(&entry, path_prefix);
|
||||||
|
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
@ -442,50 +443,13 @@ fn pxar_metadata_catalog_dump_entry<'future, T: Clone + Send + Sync + ReadAt + '
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok::<(), Error>(())
|
||||||
})
|
})
|
||||||
}
|
.await?;
|
||||||
|
|
||||||
/// Recursively iterate over pxar archive entries and dump them using the same format used to dump
|
|
||||||
/// entries from a catalog.
|
|
||||||
pub async fn pxar_metadata_catalog_dump_dir<T: Clone + Send + Sync + ReadAt>(
|
|
||||||
parent_dir: Directory<T>,
|
|
||||||
path_prefix: Option<&str>,
|
|
||||||
) -> Result<(), Error> {
|
|
||||||
let entries = pxar_metadata_read_dir(parent_dir).await?;
|
|
||||||
for entry in entries {
|
|
||||||
pxar_metadata_catalog_dump_entry(entry, path_prefix).await?;
|
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Call the callback on given entry if matched by the match patterns.
|
|
||||||
fn pxar_metadata_catalog_find_entry<'future, T: Clone + Send + Sync + ReadAt + 'future>(
|
|
||||||
entry: FileEntry<T>,
|
|
||||||
match_list: &'future (impl MatchList<'future> + Sync),
|
|
||||||
callback: &'future (dyn Fn(&[u8]) -> Result<(), Error> + Send + Sync),
|
|
||||||
) -> Pin<Box<dyn Future<Output = Result<(), Error>> + Send + 'future>> {
|
|
||||||
Box::pin(async move {
|
|
||||||
let file_mode = entry.metadata().file_type() as u32;
|
|
||||||
let entry_path = entry_path_with_prefix(&entry, Some("/"))
|
|
||||||
.as_os_str()
|
|
||||||
.to_owned();
|
|
||||||
|
|
||||||
match match_list.matches(entry_path.as_bytes(), file_mode) {
|
|
||||||
Ok(Some(MatchType::Exclude)) => return Ok(()),
|
|
||||||
Ok(Some(MatchType::Include)) => callback(entry_path.as_bytes())?,
|
|
||||||
_ => (),
|
|
||||||
}
|
|
||||||
|
|
||||||
if let EntryKind::Directory = entry.kind() {
|
|
||||||
let dir_entry = entry.enter_directory().await?;
|
|
||||||
pxar_metadata_catalog_find(dir_entry, match_list, callback).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Recursively iterate over pxar archive entries and call the callback on entries matching the
|
/// Recursively iterate over pxar archive entries and call the callback on entries matching the
|
||||||
/// match patterns.
|
/// match patterns.
|
||||||
pub async fn pxar_metadata_catalog_find<'future, T: Clone + Send + Sync + ReadAt + 'future>(
|
pub async fn pxar_metadata_catalog_find<'future, T: Clone + Send + Sync + ReadAt + 'future>(
|
||||||
@ -495,7 +459,26 @@ pub async fn pxar_metadata_catalog_find<'future, T: Clone + Send + Sync + ReadAt
|
|||||||
) -> Result<(), Error> {
|
) -> Result<(), Error> {
|
||||||
let entries = pxar_metadata_read_dir(parent_dir).await?;
|
let entries = pxar_metadata_read_dir(parent_dir).await?;
|
||||||
for entry in entries {
|
for entry in entries {
|
||||||
pxar_metadata_catalog_find_entry(entry, match_list, callback).await?;
|
Box::pin(async move {
|
||||||
|
let file_mode = entry.metadata().file_type() as u32;
|
||||||
|
let entry_path = entry_path_with_prefix(&entry, Some("/"))
|
||||||
|
.as_os_str()
|
||||||
|
.to_owned();
|
||||||
|
|
||||||
|
match match_list.matches(entry_path.as_bytes(), file_mode) {
|
||||||
|
Ok(Some(MatchType::Exclude)) => return Ok::<(), Error>(()),
|
||||||
|
Ok(Some(MatchType::Include)) => callback(entry_path.as_bytes())?,
|
||||||
|
_ => (),
|
||||||
|
}
|
||||||
|
|
||||||
|
if let EntryKind::Directory = entry.kind() {
|
||||||
|
let dir_entry = entry.enter_directory().await?;
|
||||||
|
pxar_metadata_catalog_find(dir_entry, match_list, callback).await?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
.await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user