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:
parent
013b1e8bca
commit
86582454e8
|
@ -622,6 +622,30 @@ impl <R: Read + Seek> CatalogReader<R> {
|
||||||
|
|
||||||
Ok(())
|
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
|
/// Serialize i64 as short, variable length byte sequence
|
||||||
|
|
|
@ -52,7 +52,6 @@ use crate::api2::types::{
|
||||||
VERIFICATION_OUTDATED_AFTER_SCHEMA
|
VERIFICATION_OUTDATED_AFTER_SCHEMA
|
||||||
};
|
};
|
||||||
use crate::api2::node::rrd::create_value_from_rrd;
|
use crate::api2::node::rrd::create_value_from_rrd;
|
||||||
use crate::api2::helpers;
|
|
||||||
use crate::backup::{
|
use crate::backup::{
|
||||||
check_backup_owner, verify_all_backups, verify_backup_group, verify_backup_dir, verify_filter,
|
check_backup_owner, verify_all_backups, verify_backup_group, verify_backup_dir, verify_filter,
|
||||||
DataStore, LocalChunkReader,
|
DataStore, LocalChunkReader,
|
||||||
|
@ -1409,7 +1408,7 @@ pub fn catalog(
|
||||||
vec![b'/']
|
vec![b'/']
|
||||||
};
|
};
|
||||||
|
|
||||||
helpers::list_dir_content(&mut catalog_reader, &path)
|
catalog_reader.list_dir_contents(&path)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[sortable]
|
#[sortable]
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
use std::io::{Read, Seek};
|
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
|
|
||||||
use anyhow::Error;
|
use anyhow::Error;
|
||||||
|
@ -7,8 +6,6 @@ use hyper::{Body, Response, StatusCode, header};
|
||||||
|
|
||||||
use proxmox::http_bail;
|
use proxmox::http_bail;
|
||||||
|
|
||||||
use pbs_datastore::catalog::{ArchiveEntry, CatalogReader, DirEntryAttribute};
|
|
||||||
|
|
||||||
pub async fn create_download_response(path: PathBuf) -> Result<Response<Body>, Error> {
|
pub async fn create_download_response(path: PathBuf) -> Result<Response<Body>, Error> {
|
||||||
let file = match tokio::fs::File::open(path.clone()).await {
|
let file = match tokio::fs::File::open(path.clone()).await {
|
||||||
Ok(file) => file,
|
Ok(file) => file,
|
||||||
|
@ -30,30 +27,3 @@ pub async fn create_download_response(path: PathBuf) -> Result<Response<Body>, E
|
||||||
.body(body)
|
.body(body)
|
||||||
.unwrap())
|
.unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns the list of content of the given path
|
|
||||||
pub fn list_dir_content<R: Read + Seek>(
|
|
||||||
reader: &mut CatalogReader<R>,
|
|
||||||
path: &[u8],
|
|
||||||
) -> Result<Vec<ArchiveEntry>, 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)
|
|
||||||
}
|
|
||||||
|
|
|
@ -34,7 +34,6 @@ use pbs_client::tools::{
|
||||||
REPO_URL_SCHEMA,
|
REPO_URL_SCHEMA,
|
||||||
};
|
};
|
||||||
|
|
||||||
use proxmox_backup::api2::helpers;
|
|
||||||
use proxmox_backup::tools;
|
use proxmox_backup::tools;
|
||||||
|
|
||||||
mod proxmox_file_restore;
|
mod proxmox_file_restore;
|
||||||
|
@ -218,7 +217,7 @@ async fn list(
|
||||||
let mut fullpath = file.into_bytes();
|
let mut fullpath = file.into_bytes();
|
||||||
fullpath.append(&mut path);
|
fullpath.append(&mut path);
|
||||||
|
|
||||||
helpers::list_dir_content(&mut catalog_reader, &fullpath)
|
catalog_reader.list_dir_contents(&fullpath)
|
||||||
}
|
}
|
||||||
ExtractPath::VM(file, path) => {
|
ExtractPath::VM(file, path) => {
|
||||||
let details = SnapRestoreDetails {
|
let details = SnapRestoreDetails {
|
||||||
|
|
Loading…
Reference in New Issue