Improve #4975 of filtering ls output by size issue (#5494)

* Improve #4975 of filtering `ls` output by size issue

* cargo fmt
This commit is contained in:
Justin Ma 2022-05-10 19:39:37 +08:00 committed by GitHub
parent 8030f7e9f0
commit 8ffffe9bcc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -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));