From 4d1831ef56023a63f55caced0b9b4eff11636640 Mon Sep 17 00:00:00 2001 From: Christian Ebner Date: Tue, 19 Mar 2024 09:43:22 +0100 Subject: [PATCH] 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 --- pbs-client/src/tools/mod.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/pbs-client/src/tools/mod.rs b/pbs-client/src/tools/mod.rs index 1b0123a3..3e333a20 100644 --- a/pbs-client/src/tools/mod.rs +++ b/pbs-client/src/tools/mod.rs @@ -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), 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"); +}