file-restore: Add 'v' (Virtual) ArchiveEntry type

For the actual partitions and blockdevices in a backup, which the
user sees like folders in the file-restore ui

Encoded as "None", to avoid cluttering DirEntryAttribute, where it
wouldn't make any sense to have.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Stefan Reiter
2021-04-21 15:18:08 +02:00
committed by Thomas Lamprecht
parent 1011fb552b
commit 4d0dc29951
4 changed files with 21 additions and 12 deletions

View File

@ -1354,19 +1354,22 @@ pub struct ArchiveEntry {
}
impl ArchiveEntry {
pub fn new(filepath: &[u8], entry_type: &DirEntryAttribute) -> Self {
pub fn new(filepath: &[u8], entry_type: Option<&DirEntryAttribute>) -> Self {
Self {
filepath: base64::encode(filepath),
text: String::from_utf8_lossy(filepath.split(|x| *x == b'/').last().unwrap())
.to_string(),
entry_type: CatalogEntryType::from(entry_type).to_string(),
leaf: !matches!(entry_type, DirEntryAttribute::Directory { .. }),
entry_type: match entry_type {
Some(entry_type) => CatalogEntryType::from(entry_type).to_string(),
None => "v".to_owned(),
},
leaf: !matches!(entry_type, None | Some(DirEntryAttribute::Directory { .. })),
size: match entry_type {
DirEntryAttribute::File { size, .. } => Some(*size),
Some(DirEntryAttribute::File { size, .. }) => Some(*size),
_ => None
},
mtime: match entry_type {
DirEntryAttribute::File { mtime, .. } => Some(*mtime),
Some(DirEntryAttribute::File { mtime, .. }) => Some(*mtime),
_ => None
},
}