make api2::helpers::list_dir_content a CatalogReader method

this is its natural place and everything required is already
part of the catalog module

Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
This commit is contained in:
Wolfgang Bumiller
2021-08-31 10:56:41 +02:00
parent 013b1e8bca
commit 86582454e8
4 changed files with 26 additions and 34 deletions

View File

@ -622,6 +622,30 @@ impl <R: Read + Seek> CatalogReader<R> {
Ok(())
}
/// Returns the list of content of the given path
pub fn list_dir_contents(&mut self, path: &[u8]) -> Result<Vec<ArchiveEntry>, Error> {
let dir = self.lookup_recursive(path)?;
let mut res = vec![];
let mut path = path.to_vec();
if !path.is_empty() && path[0] == b'/' {
path.remove(0);
}
for direntry in self.read_dir(&dir)? {
let mut components = path.clone();
components.push(b'/');
components.extend(&direntry.name);
let mut entry = ArchiveEntry::new(&components, Some(&direntry.attr));
if let DirEntryAttribute::File { size, mtime } = direntry.attr {
entry.size = size.into();
entry.mtime = mtime.into();
}
res.push(entry);
}
Ok(res)
}
}
/// Serialize i64 as short, variable length byte sequence