Skip to content

ls -lF symlink target indicators#11554

Open
joknarf wants to merge 1 commit intouutils:mainfrom
joknarf:classify_target
Open

ls -lF symlink target indicators#11554
joknarf wants to merge 1 commit intouutils:mainfrom
joknarf:classify_target

Conversation

@joknarf
Copy link
Copy Markdown

@joknarf joknarf commented Mar 30, 2026

Fix for #11542
gnu output incompatibility with --classify on symlink targets

before:

 • ls -lF mylink*
lrwxrwxrwx 1 user group 5 Nov 22 08:33 mylinktodir@ -> mydir
lrwxrwxrwx 1 user group 9 Nov 22 08:31 mylinktoexe@ -> myexec.sh
lrwxrwxrwx 1 user group 6 Nov 22 08:34 mylinktofile@ -> myfile
lrwxrwxrwx 1 user group 6 Nov 22 08:47 mylinktopipe@ -> mypipe
lrwxrwxrwx 1 user group 6 Mar 29 10:42 mylinktosock@ -> mysock

after (gnu identical output):

 • gnuls -lF mylink*
lrwxrwxrwx 1 user group 5 Nov 22 09:33 mylinktodir -> mydir/
lrwxrwxrwx 1 user group 9 Nov 22 09:31 mylinktoexe -> myexec.sh*
lrwxrwxrwx 1 user group 6 Nov 22 09:34 mylinktofile -> myfile
lrwxrwxrwx 1 user group 6 Nov 22 09:47 mylinktopipe -> mypipe|
lrwxrwxrwx 1 user group 6 Mar 29 10:42 mylinktosock -> mysock=

Copy link
Copy Markdown
Contributor

@Alonely0 Alonely0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine, but there are a lot of removed comments (vibecode?) and unnecessary performance hits.

}

fn indicator_char(path: &PathData, style: IndicatorStyle) -> Option<char> {
let sym = classify_file(path);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The classify_files() function is now called unconditionally, but beforehand it was contingent on config.indicator_style != IndicatorStyle::None. I'm concerned this is going to negatively affect performance since it has to stat files. Maybe the best solution is to remove the IndicatorStyle::None branch and change all occurrences of IndicatorStyle to Option<IndicatorStyle>, then do a let-else.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PD: please keep the old comments on the code you refactored to this new function. Did you vibecode this? Don't take it the wrong way; this is just a usual telltale.

None => target_path.clone(),
}
} else {
target_path.clone()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not clone here; it is not necessary. Use references, like the previous code that you have replaced. This was fixed in edfe26c.

),
);
} else {
name.push(escaped_target);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep comments. Previously in L804-805.

false,
);

let mut target_display = escaped_target.clone();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not clone here. You should refactor the immediate assignment inside the if to be the expression of the let definition, like let var = if ... { ... } else { ... };. Alternatively, use references or a Cow if you have to.

false,
);

// Check if the target actually needs coloring
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep this comment if you can.

);

if style.is_some() {
// Only apply coloring if there's actually a style
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Keep this comment if you can.

is_wrap(name.len()),
));
} else {
// For regular files with no coloring, just use plain text
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Once/if you apply the other requested changes, consider keeping this comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants