From ef3049f5a116276633645a9a2c9aa587bf3af429 Mon Sep 17 00:00:00 2001 From: "Joseph T. Lyons" Date: Sat, 2 May 2020 11:14:29 -0400 Subject: [PATCH] Reduce some repetitive code in files.rs (#1692) --- crates/nu-cli/src/data/files.rs | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/crates/nu-cli/src/data/files.rs b/crates/nu-cli/src/data/files.rs index 31a6618600..28da7254a9 100644 --- a/crates/nu-cli/src/data/files.rs +++ b/crates/nu-cli/src/data/files.rs @@ -63,29 +63,24 @@ pub(crate) fn dir_entry_dict( dict.insert_untagged("type", UntaggedValue::nothing()); } + let mut symlink_target_untagged_value: UntaggedValue = UntaggedValue::nothing(); + if full || with_symlink_targets { if let Some(md) = metadata { - let ft = md.file_type(); - if ft.is_symlink() { + if md.file_type().is_symlink() { if let Ok(path_to_link) = filename.read_link() { - dict.insert_untagged( - "target", - UntaggedValue::string(path_to_link.to_string_lossy()), - ); + symlink_target_untagged_value = + UntaggedValue::string(path_to_link.to_string_lossy()); } else { - dict.insert_untagged( - "target", - UntaggedValue::string("Could not obtain target file's path"), - ); + symlink_target_untagged_value = + UntaggedValue::string("Could not obtain target file's path"); } - } else { - dict.insert_untagged("target", UntaggedValue::nothing()); } - } else { - dict.insert_untagged("target", UntaggedValue::nothing()); } } + dict.insert_untagged("target", symlink_target_untagged_value); + if full { if let Some(md) = metadata { dict.insert_untagged(