From 8d197e1b2f8e447e7dc1512829b4b1cb50886c4c Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Wed, 29 Apr 2020 03:23:26 -0400 Subject: [PATCH] Show symlink sizes in ls (#1680) * Show symlink sizes in ls * Reduce redundancy in the size code of ls --- crates/nu-cli/src/data/files.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/crates/nu-cli/src/data/files.rs b/crates/nu-cli/src/data/files.rs index 95cbcfd0c9..31a6618600 100644 --- a/crates/nu-cli/src/data/files.rs +++ b/crates/nu-cli/src/data/files.rs @@ -127,16 +127,20 @@ pub(crate) fn dir_entry_dict( } } + let mut size_untagged_value: UntaggedValue = UntaggedValue::nothing(); + if let Some(md) = metadata { if md.is_file() { - dict.insert_untagged("size", UntaggedValue::bytes(md.len() as u64)); - } else { - dict.insert_untagged("size", UntaggedValue::nothing()); + size_untagged_value = UntaggedValue::bytes(md.len() as u64); + } else if md.file_type().is_symlink() { + if let Ok(symlink_md) = filename.symlink_metadata() { + size_untagged_value = UntaggedValue::bytes(symlink_md.len() as u64); + } } - } else { - dict.insert_untagged("size", UntaggedValue::nothing()); } + dict.insert_untagged("size", size_untagged_value); + if let Some(md) = metadata { if full { if let Ok(c) = md.created() {