[pbs-devel] [PATCH v6 proxmox-backup 27/65] api: datastore: attach optional payload chunk reader

Dominik Csapak d.csapak at proxmox.com
Tue May 21 15:12:25 CEST 2024


On 5/14/24 12:33, Christian Ebner wrote:
> Attach the payload chunk reader for pxar archives which have been
> uploaded using split streams for metadata and payload data.
> 
> Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
> ---
>   src/api2/admin/datastore.rs | 10 +++++++++-
>   1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
> index 505a6883f..c818a49b9 100644
> --- a/src/api2/admin/datastore.rs
> +++ b/src/api2/admin/datastore.rs
> @@ -1813,7 +1813,15 @@ pub fn pxar_file_download(
>           let (reader, archive_size) =
>               get_local_pxar_reader(datastore.clone(), &manifest, &backup_dir, pxar_name)?;
>   
> -        let decoder = Accessor::new(reader, archive_size, None).await?;
> +        let decoder = if let Some(archive_base_name) = pxar_name.strip_suffix(".mpxar.didx") {
> +            let payload_archive_name = format!("{archive_base_name}.ppxar.didx");
> +            let (payload_reader, payload_size) =
> +                get_local_pxar_reader(datastore, &manifest, &backup_dir, &payload_archive_name)?;
> +            Accessor::new(reader, archive_size, Some((payload_reader, payload_size))).await?
> +        } else {
> +            Accessor::new(reader, archive_size, None).await?
> +        };
> +

nit: this could be a bit more readable (IMHO) with 'transpose' (not tested):

let payload_input = pxar_name.strip_suffix(".mpxar.didx").map(|archive_base_name| {
     let payload_archive_name = ....
     get_local_pxar_reader(....)
}).transpose()?;

let decoder = Accessor::new(reader, archive_size, payload_input).await?;

I generally find it more readable not calling a function twice in the code in such cases,
but let only the parameter change

>           let root = decoder.open_root().await?;
>           let path = OsStr::from_bytes(file_path).to_os_string();
>           let file = root





More information about the pbs-devel mailing list