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());
}
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(