From 30e3e214bcac43ce5c34669217804e890545bf78 Mon Sep 17 00:00:00 2001 From: fdai7375 Date: Tue, 24 Jan 2023 11:18:01 +0100 Subject: [PATCH] refactoring: remove unneeded metadata call --- src/builtins/ls.rs | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/builtins/ls.rs b/src/builtins/ls.rs index 7822da6..0f0dac8 100644 --- a/src/builtins/ls.rs +++ b/src/builtins/ls.rs @@ -23,17 +23,21 @@ impl Builtin for Ls { continue; } }; + let metadata = match metadata(entry.path()) { + Ok(m) => m, + Err(_) => { + continue; + } + }; let file_name = entry.file_name().to_string_lossy().to_string(); let mut file_type = "unknown"; - let tmp = entry.file_type().unwrap(); - if tmp.is_dir() { + if metadata.file_type().is_dir() { file_type = "dir" - } else if tmp.is_file() { + } else if metadata.file_type().is_file() { file_type = "file" - } else if tmp.is_symlink() { + } else if metadata.file_type().is_symlink() { file_type = "link" } - let metadata = metadata(entry.path()).unwrap(); println!( "{:} | {:4} | {}", right_padding(&file_name, 16),