[pbs-devel] [PATCH v8 proxmox-backup 22/69] client: helper: add method for split archive name mapping

Christian Ebner c.ebner at proxmox.com
Tue May 28 11:42:16 CEST 2024


Helper method that takes the meta or payload archive name as input
and maps it to the correct archive names for metadata and payload
archive.

If neither is matched, fallback to returning the passed in archive
name as target archive and `None` for the payload archive name.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
changes since version 7:
- no changes

changes since version 6:
- extend mapping to also include `.pxar` as allowed extension, mapping
  to `.mpxar`

 proxmox-backup-client/src/helper.rs | 42 +++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/proxmox-backup-client/src/helper.rs b/proxmox-backup-client/src/helper.rs
index 5b21b6720..5589aa5b1 100644
--- a/proxmox-backup-client/src/helper.rs
+++ b/proxmox-backup-client/src/helper.rs
@@ -70,3 +70,45 @@ pub(crate) async fn get_buffered_pxar_reader(
 
     Ok(BufferedDynamicReader::new(index, chunk_reader))
 }
+
+pub(crate) fn get_pxar_archive_names(
+    archive_name: &str,
+    manifest: &BackupManifest,
+) -> (String, Option<String>) {
+    let filename = archive_name.strip_suffix(".didx").unwrap_or(archive_name);
+
+    if let Some(base) = filename
+        .strip_suffix(".mpxar")
+        .or_else(|| filename.strip_suffix(".ppxar"))
+    {
+        if archive_name.ends_with(".didx") {
+            return (
+                format!("{base}.mpxar.didx"),
+                Some(format!("{base}.ppxar.didx")),
+            );
+        } else {
+            return (format!("{base}.mpxar"), Some(format!("{base}.ppxar")));
+        }
+    }
+
+    if let Some(base) = filename.strip_suffix(".pxar") {
+        // Check if pxar is present, otherwise fallback to split archive naming
+        if manifest
+            .files()
+            .iter()
+            .find(|fileinfo| fileinfo.filename == filename)
+            .is_none()
+        {
+            if archive_name.ends_with(".didx") {
+                return (
+                    format!("{base}.mpxar.didx"),
+                    Some(format!("{base}.ppxar.didx")),
+                );
+            } else {
+                return (format!("{base}.mpxar"), Some(format!("{base}.ppxar")));
+            }
+        }
+    }
+
+    (archive_name.to_owned(), None)
+}
-- 
2.39.2





More information about the pbs-devel mailing list