]> git.proxmox.com Git - pxar.git/commitdiff
header: implement Display
authorFabian Grünbichler <f.gruenbichler@proxmox.com>
Fri, 12 Jun 2020 07:21:40 +0000 (09:21 +0200)
committerWolfgang Bumiller <w.bumiller@proxmox.com>
Fri, 12 Jun 2020 07:46:04 +0000 (09:46 +0200)
for nicer/readable error messages.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Wolfgang Bumiller <w.bumiller@proxmox.com>
src/accessor/mod.rs
src/decoder/mod.rs
src/format/mod.rs

index 9e997b6c486a50fd12064506f589176fb385b113..2678351260d8858cf990307876fec923668ea168 100644 (file)
@@ -204,8 +204,8 @@ async fn get_decoder_at_filename<T: ReadAt>(
     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 {
@@ -608,7 +608,7 @@ impl<T: Clone + ReadAt> DirectoryImpl<T> {
     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(
index 22f069b0c6fce1d9a26731066319d6efa43d77c8..c6a8e8fa807da8e11d5e8f7ecee9b0656242582d 100644 (file)
@@ -279,9 +279,9 @@ impl<I: SeqRead> DecoderImpl<I> {
                         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,
                 ),
             }
         }
@@ -380,8 +380,8 @@ impl<I: SeqRead> DecoderImpl<I> {
             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,
             );
         }
     }
@@ -498,7 +498,7 @@ impl<I: SeqRead> DecoderImpl<I> {
                     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)
index 57f7dc48c7d2d1a176418cdd7760c998df47f970..6a779006d8316784f318dc6ce31800b92bf681a0 100644 (file)
@@ -7,6 +7,8 @@
 
 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;
@@ -128,6 +130,30 @@ impl Header {
         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)]