[pbs-devel] [PATCH proxmox-backup 1/8] api: datastore: factor out path decoding for catalog

Christian Ebner c.ebner at proxmox.com
Fri Jun 7 11:43:06 CEST 2024


The file path passed to the catalog is base64 encoded, with an exception
for the root.
Factor this check and decoding step out into a helper function to make
it reusable when doing the same for lookups via the metadata archive
instead of the catalog.

Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
 src/api2/admin/datastore.rs | 15 +++++++++------
 1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs
index 34a9105dd..854302999 100644
--- a/src/api2/admin/datastore.rs
+++ b/src/api2/admin/datastore.rs
@@ -1636,6 +1636,14 @@ pub fn upload_backup_log(
     .boxed()
 }
 
+fn decode_path(path: &str) -> Result<Vec<u8>, Error> {
+    if path != "root" && path != "/" {
+        base64::decode(path).map_err(|err| format_err!("base64 decoding of path failed - {err}"))
+    } else {
+        Ok(vec![b'/'])
+    }
+}
+
 #[api(
     input: {
         properties: {
@@ -1709,12 +1717,7 @@ pub async fn catalog(
 
         let mut catalog_reader = CatalogReader::new(reader);
 
-        let path = if filepath != "root" && filepath != "/" {
-            base64::decode(filepath)?
-        } else {
-            vec![b'/']
-        };
-
+        let path = decode_path(&filepath)?;
         catalog_reader.list_dir_contents(&path)
     })
     .await?
-- 
2.39.2





More information about the pbs-devel mailing list