api2/admin/datastore: refactor list_dir_content in catalog_reader

we will reuse that later in the client, so we need it somewhere
we can use from there

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>

[add strongly typed ArchiveEntry and put api code into helpers.rs]
Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
This commit is contained in:
Dominik Csapak authored and Thomas Lamprecht committed 2021-02-17 08:32:41 +01:00
1 parent 89d25b1931
commit 227501c063
4 files changed
+108 -45

No files matched your search

+26
View File
@@ -468,6 +468,32 @@ impl <R: Read + Seek> CatalogReader<R> {
Ok(entry_list)
}
/// Lookup a DirEntry from an absolute path
pub fn lookup_recursive(
&mut self,
path: &[u8],
) -> Result<DirEntry, Error> {
let mut current = self.root()?;
if path == b"/" {
return Ok(current);
}
let components = if !path.is_empty() && path[0] == b'/' {
&path[1..]
} else {
path
}.split(|c| *c == b'/');
for comp in components {
if let Some(entry) = self.lookup(&current, comp)? {
current = entry;
} else {
bail!("path {:?} not found in catalog", String::from_utf8_lossy(&path));
}
}
Ok(current)
}
/// Lockup a DirEntry inside a parent directory
pub fn lookup(
&mut self,