5
0
mirror of git://git.proxmox.com/git/proxmox-backup.git synced 2025-03-09 08:58:28 +03:00

tape: reduce indentation depth of MAM attribute decoder

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
This commit is contained in:
Thomas Lamprecht 2023-05-17 14:43:01 +02:00
parent 071d345781
commit 1787725442

View File

@ -203,15 +203,13 @@ fn decode_mam_attributes(data: &[u8]) -> Result<Vec<MamAttribute>, Error> {
let mut reader = data;
let data_len: u32 = unsafe { reader.read_be_value()? };
let expected_len = data_len as usize;
use std::cmp::Ordering;
match reader.len().cmp(&expected_len) {
Ordering::Less => bail!(
"read_mam_attributes: got unexpected data len ({} != {})",
reader.len(),
expected_len
"read_mam_attributes: got unexpected data len ({} != {expected_len})",
reader.len()
),
Ordering::Greater => {
// Note: Quantum hh7 returns the allocation_length instead of real data_len
@ -237,7 +235,10 @@ fn decode_mam_attributes(data: &[u8]) -> Result<Vec<MamAttribute>, Error> {
Vec::new()
};
if let Some(info) = MAM_ATTRIBUTE_NAMES.get(&head_id) {
let info = match MAM_ATTRIBUTE_NAMES.get(&head_id) {
None => continue, // skip unknown IDs
Some(info) => info,
};
if info.1 == 0 || info.1 == head.len {
let value = match info.2 {
MamFormat::ASCII => String::from_utf8_lossy(&data).to_string(),
@ -267,13 +268,7 @@ fn decode_mam_attributes(data: &[u8]) -> Result<Vec<MamAttribute>, Error> {
value,
});
} else {
eprintln!(
"read_mam_attributes: got starnge data len for id {:04X}",
head_id
);
}
} else {
// skip unknown IDs
eprintln!("read_mam_attributes: got strange data len for id {head_id:04X}");
}
}
Ok(list)