diff --git a/pbs-datastore/src/catalog.rs b/pbs-datastore/src/catalog.rs index 7a65e8d1..e82417f2 100644 --- a/pbs-datastore/src/catalog.rs +++ b/pbs-datastore/src/catalog.rs @@ -622,6 +622,30 @@ impl CatalogReader { Ok(()) } + + /// Returns the list of content of the given path + pub fn list_dir_contents(&mut self, path: &[u8]) -> Result, 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 diff --git a/src/api2/admin/datastore.rs b/src/api2/admin/datastore.rs index c181a84c..5470de73 100644 --- a/src/api2/admin/datastore.rs +++ b/src/api2/admin/datastore.rs @@ -52,7 +52,6 @@ use crate::api2::types::{ VERIFICATION_OUTDATED_AFTER_SCHEMA }; use crate::api2::node::rrd::create_value_from_rrd; -use crate::api2::helpers; use crate::backup::{ check_backup_owner, verify_all_backups, verify_backup_group, verify_backup_dir, verify_filter, DataStore, LocalChunkReader, @@ -1409,7 +1408,7 @@ pub fn catalog( vec![b'/'] }; - helpers::list_dir_content(&mut catalog_reader, &path) + catalog_reader.list_dir_contents(&path) } #[sortable] diff --git a/src/api2/helpers.rs b/src/api2/helpers.rs index 8f43cacf..2a822654 100644 --- a/src/api2/helpers.rs +++ b/src/api2/helpers.rs @@ -1,4 +1,3 @@ -use std::io::{Read, Seek}; use std::path::PathBuf; use anyhow::Error; @@ -7,8 +6,6 @@ use hyper::{Body, Response, StatusCode, header}; use proxmox::http_bail; -use pbs_datastore::catalog::{ArchiveEntry, CatalogReader, DirEntryAttribute}; - pub async fn create_download_response(path: PathBuf) -> Result, Error> { let file = match tokio::fs::File::open(path.clone()).await { Ok(file) => file, @@ -30,30 +27,3 @@ pub async fn create_download_response(path: PathBuf) -> Result, E .body(body) .unwrap()) } - -/// Returns the list of content of the given path -pub fn list_dir_content( - reader: &mut CatalogReader, - path: &[u8], -) -> Result, Error> { - let dir = reader.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 reader.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) -} diff --git a/src/bin/proxmox-file-restore.rs b/src/bin/proxmox-file-restore.rs index fa852f51..1712487b 100644 --- a/src/bin/proxmox-file-restore.rs +++ b/src/bin/proxmox-file-restore.rs @@ -34,7 +34,6 @@ use pbs_client::tools::{ REPO_URL_SCHEMA, }; -use proxmox_backup::api2::helpers; use proxmox_backup::tools; mod proxmox_file_restore; @@ -218,7 +217,7 @@ async fn list( let mut fullpath = file.into_bytes(); fullpath.append(&mut path); - helpers::list_dir_content(&mut catalog_reader, &fullpath) + catalog_reader.list_dir_contents(&fullpath) } ExtractPath::VM(file, path) => { let details = SnapRestoreDetails {