Skip to content

Commit 89cf583

Browse files
sylvestrecakebaker
authored andcommitted
ls: simplify symlink target indicator logic
1 parent e50a178 commit 89cf583

1 file changed

Lines changed: 14 additions & 24 deletions

File tree

src/uu/ls/src/display.rs

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -717,23 +717,20 @@ fn display_item_name(
717717

718718
let dired_name_len = if config.dired { name.len() } else { 0 };
719719

720-
let has_mi_or_or = style_manager.as_ref().is_some_and(|sm| {
721-
sm.has_indicator_style(Indicator::OrphanedSymbolicLink)
722-
|| sm.has_indicator_style(Indicator::MissingFile)
723-
});
724-
// Only stat symlink target when:
725-
// 1. Color is enabled AND LS_COLORS has mi= or or=, OR
726-
// 2. Long format AND (--classify or --file-type)
727-
let should_stat_target = has_mi_or_or
728-
|| matches!(
729-
config.indicator_style,
730-
Some(IndicatorStyle::Classify) | Some(IndicatorStyle::FileType)
731-
);
720+
if is_long_symlink {
721+
let has_mi_or_or = style_manager.as_ref().is_some_and(|sm| {
722+
sm.has_indicator_style(Indicator::OrphanedSymbolicLink)
723+
|| sm.has_indicator_style(Indicator::MissingFile)
724+
});
725+
// Only stat symlink target when:
726+
// 1. Color is enabled AND LS_COLORS has mi= or or=, OR
727+
// 2. Long format AND (--classify or --file-type)
728+
let should_stat_target = has_mi_or_or
729+
|| matches!(
730+
config.indicator_style,
731+
Some(IndicatorStyle::Classify) | Some(IndicatorStyle::FileType)
732+
);
732733

733-
if config.format == Format::Long
734-
&& path.file_type().is_some_and(FileType::is_symlink)
735-
&& !path.must_dereference
736-
{
737734
match path.path().read_link() {
738735
Ok(target_path) => {
739736
name.push(" -> ");
@@ -796,14 +793,7 @@ fn display_item_name(
796793
name.push(target_display);
797794
// Add appropriate indicator based on indicator_style
798795
if let Some(c) = indicator_char(&target_data, config.indicator_style) {
799-
if matches!(
800-
config.indicator_style,
801-
Some(IndicatorStyle::Classify)
802-
| Some(IndicatorStyle::FileType)
803-
| Some(IndicatorStyle::Slash)
804-
) {
805-
let _ = name.write_char(c);
806-
}
796+
let _ = name.write_char(c);
807797
}
808798
}
809799
Err(_) => {

0 commit comments

Comments
 (0)