[pbs-devel] [PATCH v9 proxmox-backup 05/58] client: helper: add method for split archive name mapping

Christian Ebner c.ebner at proxmox.com
Wed Jun 5 12:53:23 CEST 2024


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 at proxmox.com>
---
changes since version 8:
- move method to pbs-client's tools, so it can be reused from within
  crate
- lookup archive name in manifest, return with error if not present

 pbs-client/src/tools/mod.rs | 50 +++++++++++++++++++++++++++++++++++++
 1 file changed, 50 insertions(+)

diff --git a/pbs-client/src/tools/mod.rs b/pbs-client/src/tools/mod.rs
index 1b0123a39..fdce33914 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,52 @@ 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 = archive_name.strip_suffix(".didx").unwrap_or(archive_name);
+
+    // Check if archive with given extension is present, otherwise fallback to split archive naming
+    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"))
+        {
+            if archive_name.ends_with(".didx") {
+                return Ok((
+                    format!("{base}.mpxar.didx"),
+                    Some(format!("{base}.ppxar.didx")),
+                ));
+            }
+            return Ok((format!("{base}.mpxar"), Some(format!("{base}.ppxar"))));
+        }
+        return Ok((archive_name.to_owned(), None));
+    }
+
+    if let Some(base) = filename.strip_suffix(".pxar") {
+        let filename = format!("{base}.mpxar");
+        // check if present with split archive name variant
+        if manifest
+            .files()
+            .iter()
+            .any(|fileinfo| fileinfo.filename == format!("{filename}.didx"))
+        {
+            if archive_name.ends_with(".didx") {
+                return Ok((
+                    format!("{base}.mpxar.didx"),
+                    Some(format!("{base}.ppxar.didx")),
+                ));
+            }
+            return Ok((format!("{base}.mpxar"), Some(format!("{base}.ppxar"))));
+        }
+    }
+
+    bail!("archive not found in manifest");
+}
-- 
2.39.2





More information about the pbs-devel mailing list