[pbs-devel] [PATCH v3 pxar 2/6] format: add helper for payload header consistency checks
Christian Ebner
c.ebner at proxmox.com
Wed Jun 12 10:23:56 CEST 2024
The helper method will be used to check the payload header being
consistent with what was encoded as paylaod reference for split
pxar archives.
Signed-off-by: Christian Ebner <c.ebner at proxmox.com>
---
changes since version 2:
- limit to be pub(crate)
src/format/mod.rs | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
diff --git a/src/format/mod.rs b/src/format/mod.rs
index 59d40e1..0648924 100644
--- a/src/format/mod.rs
+++ b/src/format/mod.rs
@@ -823,3 +823,24 @@ pub fn check_file_name(path: &Path) -> io::Result<()> {
Ok(())
}
}
+
+/// Check if provided header is of type payload and the headers content size matches given size.
+///
+/// Returns an [`io::Error`](std::io::Error) of type [`Other`](std::io::ErrorKind::Other) if that's
+/// not the case.
+pub(crate) fn check_payload_header_and_size(header: &Header, size: u64) -> io::Result<()> {
+ header.check_header_size()?;
+
+ if header.htype != PXAR_PAYLOAD {
+ io_bail!("unexpected header: expected {PXAR_PAYLOAD:x?} , got {header:x?}");
+ }
+
+ if header.content_size() != size {
+ io_bail!(
+ "encountered size mismatch: expected {}, got {size}",
+ header.content_size()
+ );
+ }
+
+ Ok(())
+}
--
2.39.2
More information about the pbs-devel
mailing list