[pbs-devel] [PATCH v7 proxmox-backup 23/69] client: tools: helper to check pxar filename extensions

Christian Ebner c.ebner at proxmox.com
Mon May 27 16:32:37 CEST 2024


With the introduction of split pxar archives, the allowed extensions
are now `.pxar`, `.mpxar` and `.ppxar`. Add a helper function to
allow to check for all valid variants, including the optional
additional `.didx` in case of a server archive name.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
changes since version 6:
- not present in previous version

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

diff --git a/pbs-client/src/tools/mod.rs b/pbs-client/src/tools/mod.rs
index 1b0123a39..6a9d1992d 100644
--- a/pbs-client/src/tools/mod.rs
+++ b/pbs-client/src/tools/mod.rs
@@ -526,3 +526,16 @@ 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))
 }
+
+/// Check if the given filename has a valid pxar filename extension variant
+///
+/// If `with_didx_extension` is `true`, check the additional `.didx` ending.
+pub fn has_pxar_filename_extension(name: &str, with_didx_extension: bool) -> bool {
+    if with_didx_extension {
+        name.ends_with(".pxar.didx")
+            || name.ends_with(".mpxar.didx")
+            || name.ends_with(".ppxar.didx")
+    } else {
+        name.ends_with(".pxar") || name.ends_with(".mpxar") || name.ends_with(".ppxar")
+    }
+}
-- 
2.39.2





More information about the pbs-devel mailing list