for nicer/readable error messages.
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
decoder.read_next_header().await?;
if decoder.current_header.htype != format::PXAR_FILENAME {
io_bail!(
- "expected filename entry, got {:?}",
- decoder.current_header.htype
+ "expected filename entry, got {}",
+ decoder.current_header,
);
}
if decoder.read_current_item().await? != decoder::ItemResult::Entry {
async fn read_filename_entry(&self, file_ofs: u64) -> io::Result<(PathBuf, u64)> {
let head: format::Header = read_entry_at(&self.input, file_ofs).await?;
if head.htype != format::PXAR_FILENAME {
- io_bail!("expected PXAR_FILENAME header, found: {:x}", head.htype);
+ io_bail!("expected PXAR_FILENAME header, found: {}", head);
}
let mut path = read_exact_data_at(
continue;
}
}
- h => io_bail!(
- "expected filename or directory-goodbye pxar entry, got: {:x}",
- h
+ _ => io_bail!(
+ "expected filename or directory-goodbye pxar entry, got: {}",
+ self.current_header,
),
}
}
Ok(Some(self.entry.take()))
} else {
io_bail!(
- "expected pxar entry of type 'Entry', got: {:x}",
- header.htype
+ "expected pxar entry of type 'Entry', got: {}",
+ header,
);
}
}
return Ok(ItemResult::Entry);
}
}
- _ => io_bail!("unexpected entry type: {:x}", self.current_header.htype),
+ _ => io_bail!("unexpected entry type: {}", self.current_header),
}
Ok(ItemResult::Attribute)
use std::cmp::Ordering;
use std::ffi::{CStr, OsStr};
+use std::fmt;
+use std::fmt::Display;
use std::io;
use std::mem::size_of;
use std::os::unix::ffi::OsStrExt;
Ok(())
}
}
+
+impl Display for Header {
+ fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
+ let readable = match self.htype {
+ PXAR_FILENAME => "FILENAME",
+ PXAR_SYMLINK => "SYMLINK",
+ PXAR_HARDLINK => "HARDLINK",
+ PXAR_DEVICE => "DEVICE",
+ PXAR_XATTR => "XATTR",
+ PXAR_FCAPS => "FCAPS",
+ PXAR_ACL_USER => "ACL_USER",
+ PXAR_ACL_DEFAULT_USER => "ACL_DEFAULT_USER",
+ PXAR_ACL_GROUP => "ACL_GROUP",
+ PXAR_ACL_DEFAULT_GROUP => "ACL_DEFAULT_GROUP",
+ PXAR_ACL_DEFAULT => "ACL_DEFAULT",
+ PXAR_ACL_GROUP_OBJ => "ACL_GROUP_OBJ",
+ PXAR_QUOTA_PROJID => "QUOTA_PROJID",
+ PXAR_ENTRY => "ENTRY",
+ PXAR_PAYLOAD => "PAYLOAD",
+ PXAR_GOODBYE => "GOODBYE",
+ _ => "UNKNOWN",
+ };
+ write!(f, "{} header ({:x})", readable, self.htype)
+ }
}
#[derive(Clone, Debug, Default, Endian)]