From 8ffffe9bcc94f2a4121af6b8ea9864dd3db94ca9 Mon Sep 17 00:00:00 2001 From: Justin Ma Date: Tue, 10 May 2022 19:39:37 +0800 Subject: [PATCH] Improve #4975 of filtering `ls` output by size issue (#5494) * Improve #4975 of filtering `ls` output by size issue * cargo fmt --- crates/nu-command/src/filesystem/ls.rs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/crates/nu-command/src/filesystem/ls.rs b/crates/nu-command/src/filesystem/ls.rs index bfa02a771d..0b4780d8c7 100644 --- a/crates/nu-command/src/filesystem/ls.rs +++ b/crates/nu-command/src/filesystem/ls.rs @@ -449,6 +449,11 @@ pub(crate) fn dir_entry_dict( cols.push("size".to_string()); if let Some(md) = metadata { + #[cfg(unix)] + let zero_sized = md.file_type().is_socket() + || md.file_type().is_char_device() + || md.file_type().is_block_device(); + if md.is_dir() { if du { let params = DirBuilder::new(Span { start: 0, end: 2 }, None, false, None, false); @@ -481,7 +486,15 @@ pub(crate) fn dir_entry_dict( vals.push(Value::nothing(span)); } } else { - vals.push(Value::nothing(span)); + #[cfg(not(unix))] + let value = Value::nothing(span); + #[cfg(unix)] + let value = if zero_sized { + Value::Filesize { val: 0, span } + } else { + Value::nothing(span) + }; + vals.push(value); } } else { vals.push(Value::nothing(span));