Reduce some repetitive code in files.rs (#1692)

This commit is contained in:
Joseph T. Lyons 2020-05-02 11:14:29 -04:00 committed by GitHub
parent 1dab82ffa1
commit ef3049f5a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -63,29 +63,24 @@ pub(crate) fn dir_entry_dict(
dict.insert_untagged("type", UntaggedValue::nothing()); dict.insert_untagged("type", UntaggedValue::nothing());
} }
let mut symlink_target_untagged_value: UntaggedValue = UntaggedValue::nothing();
if full || with_symlink_targets { if full || with_symlink_targets {
if let Some(md) = metadata { if let Some(md) = metadata {
let ft = md.file_type(); if md.file_type().is_symlink() {
if ft.is_symlink() {
if let Ok(path_to_link) = filename.read_link() { if let Ok(path_to_link) = filename.read_link() {
dict.insert_untagged( symlink_target_untagged_value =
"target", UntaggedValue::string(path_to_link.to_string_lossy());
UntaggedValue::string(path_to_link.to_string_lossy()),
);
} else { } else {
dict.insert_untagged( symlink_target_untagged_value =
"target", UntaggedValue::string("Could not obtain target file's path");
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 full {
if let Some(md) = metadata { if let Some(md) = metadata {
dict.insert_untagged( dict.insert_untagged(