From 95fa81250efbced764ab1ad3abf7bc63dcd77ae5 Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sat, 16 Dec 2023 17:37:57 +0100 Subject: [PATCH] ls/color_name: use the DirEntry if available --- src/uu/ls/src/ls.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index 04b5a4ebc..b91d44d72 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -3271,6 +3271,17 @@ fn color_name( ls_colors: &LsColors, style_manager: &mut StyleManager, ) -> String { + if !path.must_dereference { + // If we need to dereference (follow) a symlink, we will need to get the metadata + if let Some(de) = &path.de { + // There is a DirEntry, we don't need to get the metadata for the color + return match ls_colors.style_for(de) { + Some(style) => style_manager.apply_style(style, &name), + None => name, + }; + } + } + match ls_colors.style_for_path_with_metadata(&path.p_buf, md) { Some(style) => style_manager.apply_style(style, &name), None => name,