file-restore: add size to image files and components

Read image sizes (.pxar.fidx/.img.didx) from manifest and partition
sizes from /sys/...

Requires a change to ArchiveEntry, as DirEntryAttribute::Directory
does not have a size associated with it (and that's probably good).

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
This commit is contained in:
Stefan Reiter
2021-04-26 15:04:14 +02:00
committed by Thomas Lamprecht
parent 1ed9069ad3
commit 6a59fa0e18
4 changed files with 37 additions and 12 deletions

View File

@ -1354,6 +1354,18 @@ pub struct ArchiveEntry {
impl ArchiveEntry {
pub fn new(filepath: &[u8], entry_type: Option<&DirEntryAttribute>) -> Self {
let size = match entry_type {
Some(DirEntryAttribute::File { size, .. }) => Some(*size),
_ => None,
};
Self::new_with_size(filepath, entry_type, size)
}
pub fn new_with_size(
filepath: &[u8],
entry_type: Option<&DirEntryAttribute>,
size: Option<u64>,
) -> Self {
Self {
filepath: base64::encode(filepath),
text: String::from_utf8_lossy(filepath.split(|x| *x == b'/').last().unwrap())
@ -1363,13 +1375,10 @@ impl ArchiveEntry {
None => "v".to_owned(),
},
leaf: !matches!(entry_type, None | Some(DirEntryAttribute::Directory { .. })),
size: match entry_type {
Some(DirEntryAttribute::File { size, .. }) => Some(*size),
_ => None
},
size,
mtime: match entry_type {
Some(DirEntryAttribute::File { mtime, .. }) => Some(*mtime),
_ => None
_ => None,
},
}
}