api: datastore: factor out path decoding for catalog

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@proxmox.com>
This commit is contained in:
Christian Ebner 2024-06-07 13:37:44 +02:00 committed by Fabian Grünbichler
parent 2baa9f8fb8
commit 30ea695518

View File

@ -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?