5
0
mirror of git://git.proxmox.com/git/proxmox-backup.git synced 2025-01-08 21:18:07 +03:00

client: helper: add method for split archive name mapping

Helper method that takes an archive name as input and checks if the
given archive is present in the manifest, by also taking possible
split archive extensions into account.
Returns the pxar archive name if found or the split archive names if
the split archive variant is present in the manifest.

If neither is matched, an error is returned signaling that nothing
matched entries in the manifest.

Signed-off-by: Christian Ebner <c.ebner@proxmox.com>
This commit is contained in:
Christian Ebner 2024-03-19 09:43:22 +01:00 committed by Fabian Grünbichler
parent 488872e461
commit 4d1831ef56

View File

@ -16,6 +16,7 @@ use proxmox_schema::*;
use proxmox_sys::fs::file_get_json;
use pbs_api_types::{Authid, BackupNamespace, RateLimitConfig, UserWithTokens, BACKUP_REPO_URL};
use pbs_datastore::BackupManifest;
use crate::{BackupRepository, HttpClient, HttpClientOptions};
@ -526,3 +527,39 @@ pub fn place_xdg_file(
.and_then(|base| base.place_config_file(file_name).map_err(Error::from))
.with_context(|| format!("failed to place {} in xdg home", description))
}
pub fn get_pxar_archive_names(
archive_name: &str,
manifest: &BackupManifest,
) -> Result<(String, Option<String>), Error> {
let (filename, ext) = match archive_name.strip_suffix(".didx") {
Some(filename) => (filename, ".didx"),
None => (archive_name, ""),
};
// Check if archive with given extension is present
if manifest
.files()
.iter()
.any(|fileinfo| fileinfo.filename == format!("{filename}.didx"))
{
// check if already given as one of split archive name variants
if let Some(base) = filename
.strip_suffix(".mpxar")
.or_else(|| filename.strip_suffix(".ppxar"))
{
return Ok((
format!("{base}.mpxar{ext}"),
Some(format!("{base}.ppxar{ext}")),
));
}
return Ok((archive_name.to_owned(), None));
}
// if not, try fallback from regular to split archive
if let Some(base) = filename.strip_suffix(".pxar") {
return get_pxar_archive_names(&format!("{base}.mpxar{ext}"), manifest);
}
bail!("archive not found in manifest");
}