For archive listings, print '-' as the size for nodes other than regular files

This commit is contained in:
Nathan Fisher 2024-01-15 00:45:59 -05:00
parent d3ea6c0971
commit 01d5da2d89

View File

@ -147,7 +147,7 @@ impl fmt::Display for Listing {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
write!( write!(
f, f,
"{}{}{}{}{}{}{}{}{}{} {:>4}:{:<4} {:>10} ", "{}{}{}{}{}{}{}{}{}{} {:>4}:{:<4} ",
match self.kind { match self.kind {
Kind::Normal(_) => "-", Kind::Normal(_) => "-",
Kind::HardLink(_) => "L", Kind::HardLink(_) => "L",
@ -199,11 +199,11 @@ impl fmt::Display for Listing {
}, },
self.uid, self.uid,
self.gid, self.gid,
match self.kind {
Kind::Normal(s) => s,
_ => 0,
},
)?; )?;
match self.kind {
Kind::Normal(s) => write!(f, "{s:>10} "),
_ => write!(f, "{:>10}", "-"),
}?;
match NaiveDateTime::from_timestamp_opt(self.mtime as i64, 0) { match NaiveDateTime::from_timestamp_opt(self.mtime as i64, 0) {
Some(dt) => write!(f, "{dt} ")?, Some(dt) => write!(f, "{dt} ")?,
_ => write!(f, "{:>19} ", self.mtime)?, _ => write!(f, "{:>19} ", self.mtime)?,
@ -266,7 +266,7 @@ impl Listing {
#[cfg(feature = "color")] #[cfg(feature = "color")]
pub fn print_color(&self) -> Result<(), Error> { pub fn print_color(&self) -> Result<(), Error> {
print!( print!(
"{}{}{}{}{}{}{}{}{}{} {:>4}:{:<4} {:>10} ", "{}{}{}{}{}{}{}{}{}{} {:>4}:{:<4} ",
match self.kind { match self.kind {
Kind::Normal(_) => "-", Kind::Normal(_) => "-",
Kind::HardLink(_) => "L", Kind::HardLink(_) => "L",
@ -318,11 +318,11 @@ impl Listing {
}, },
self.uid, self.uid,
self.gid, self.gid,
match self.kind {
Kind::Normal(s) => s,
_ => 0,
},
); );
match self.kind {
Kind::Normal(s) => write!(f, "{s:>10} "),
_ => write!(f, "{:>10}", "-"),
}?;
match NaiveDateTime::from_timestamp_opt(self.mtime as i64, 0) { match NaiveDateTime::from_timestamp_opt(self.mtime as i64, 0) {
Some(dt) => print!("{dt} "), Some(dt) => print!("{dt} "),
_ => print!("{:>19} ", self.mtime), _ => print!("{:>19} ", self.mtime),