From c2fe2b7cb9d5a5f2e76832f79d38b8fc9b7583c1 Mon Sep 17 00:00:00 2001 From: mhead Date: Wed, 19 Jun 2024 16:17:18 +0530 Subject: [PATCH] multi hard link regression fix --- src/uu/ls/src/ls.rs | 18 ++++++++++++++++-- util/build-gnu.sh | 7 ++++++- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/uu/ls/src/ls.rs b/src/uu/ls/src/ls.rs index a7ffda8ff11..25f7237dd31 100644 --- a/src/uu/ls/src/ls.rs +++ b/src/uu/ls/src/ls.rs @@ -3414,7 +3414,14 @@ fn apply_style_based_on_metadata( ) -> String { let path_indicator = ls_colors.indicator_for_path_with_metadata(&path.p_buf, md_option); let is_zeroed = ls_colors.zeroed_indicators.contains(&path_indicator); - match ls_colors.style_for_indicator(path_indicator) { + let style = if path_indicator == Indicator::RegularFile { + ls_colors + .style_for_str(&name) + .or_else(|| ls_colors.style_for_indicator(path_indicator)) + } else { + ls_colors.style_for_indicator(path_indicator) + }; + match style { Some(style) => style_manager.apply_style(style, name, ls_colors, is_zeroed), None => name.to_owned(), } @@ -3438,7 +3445,14 @@ fn color_name( // There is a DirEntry, we don't need to get the metadata for the color let de_indicator = ls_colors.indicator_for(de); let is_zeroed = ls_colors.zeroed_indicators.contains(&de_indicator); - return match ls_colors.style_for_indicator(de_indicator) { + let style = if de_indicator == Indicator::RegularFile { + ls_colors + .style_for_str(&name) + .or_else(|| ls_colors.style_for_indicator(de_indicator)) + } else { + ls_colors.style_for_indicator(de_indicator) + }; + return match style { Some(style) => style_manager.apply_style(style, &name, ls_colors, is_zeroed), None => name, }; diff --git a/util/build-gnu.sh b/util/build-gnu.sh index b3ef94d2e48..706278157f5 100755 --- a/util/build-gnu.sh +++ b/util/build-gnu.sh @@ -350,4 +350,9 @@ sed -i -e "s|Try 'md5sum --help' for more information.\\\n||" tests/cksum/md5su sed -i -E '65,79{s/\^\[\[([1-9]m)/^[[0\1/g; s/\^\[\[m/^[[0m/g}' tests/ls/color-norm.sh # It says in the test itself that having more than one reset is a bug, so we # don't need to replicate that behavior. -sed -i -E '73,75{s/(\^\[\[0m)+/\^\[\[0m/g}' tests/ls/color-norm.sh \ No newline at end of file +sed -i -E '73,75{s/(\^\[\[0m)+/\^\[\[0m/g}' tests/ls/color-norm.sh + +# GNU's ls seems to output color codes in the order given in the environment +# variable, but our ls seems to output them in a predefined order. Nevertheless, +# the order doesn't matter, so it's okay. +sed -i '25s/44;37/37;44/' tests/ls/multihardlink.sh \ No newline at end of file