1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-05-28 05:07:50 +02:00

ls: fix coloring of dangling symlinks in default listing mode

When listing a directory containing dangling symlinks,
and not outputting a long format listing, and orphaned links
are set to no coloring in LS_COLORS, then the symlinks
would get no color rather than reverting to the standard
symlink color.  The issue was introduced in v8.13-19-g84457c4

* src/ls.c (print_color_indicator): Use the standard method
to check if coloring is specified for orphaned symlinks.
The existing method would consider 'or=00' or 'or=0' as significant
in LS_COLORS. Even 'or=' was significant as in that case the
string='or=' and the length=0.  Also apply the same change
for missing symlinks for consistency.
(gobble_file): Remove the simulation of linkok, which is only
tested in print_color_indicator() which now handles this directly
by keying on the LS_COLORS values correctly.
* tests/misc/ls-misc.pl: Add a test case.
* THANKS: Add the reporter.
* NEWS: Mention the fix.
Reported-by: David Matei
This commit is contained in:
Pádraig Brady
2012-09-16 04:10:50 +01:00
parent c5ccf29bbf
commit a04ddb8dd3
4 changed files with 22 additions and 9 deletions
+4
View File
@@ -21,6 +21,10 @@ GNU coreutils NEWS -*- outline -*-
numbers, and up to 8 times slower for some worst-case individual numbers.
[bug introduced in coreutils-7.0, with GNU MP support]
ls now correctly colors dangling symlinks when listing their containing
directories, with orphaned symlink coloring disabled in LS_COLORS.
[bug introduced in coreutils-8.14]
rm -i -d now prompts the user then removes an empty directory, rather
than ignoring the -d option and failing with an 'Is a directory' error.
[bug introduced in coreutils-8.19, with the addition of --dir (-d)]
+1
View File
@@ -153,6 +153,7 @@ David Godfrey dave@delta.demon.co.uk
David Luyer david_luyer@pacific.net.au
David Madore david.madore@ens.fr
David Malone dwmalone@cnri.dit.ie
David Matei matei@cs.toronto.edu
Davide Canova kc.canova@gmail.com
Dawson Engler engler@stanford.edu
Dean Gaudet dean-savannah@arctic.org
+2 -9
View File
@@ -3064,12 +3064,6 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
free (linkname);
}
/* When not distinguishing types of symlinks, pretend we know that
it is stat'able, so that it will be colored as a regular symlink,
and not as an orphan. */
if (S_ISLNK (f->stat.st_mode) && !check_symlink_color)
f->linkok = true;
if (S_ISLNK (f->stat.st_mode))
f->filetype = symbolic_link;
else if (S_ISDIR (f->stat.st_mode))
@@ -4293,7 +4287,7 @@ print_color_indicator (const struct fileinfo *f, bool symlink_target)
/* Is this a nonexistent file? If so, linkok == -1. */
if (linkok == -1 && color_indicator[C_MISSING].string != NULL)
if (linkok == -1 && is_colored (C_MISSING))
type = C_MISSING;
else if (!f->stat_ok)
{
@@ -4368,8 +4362,7 @@ print_color_indicator (const struct fileinfo *f, bool symlink_target)
/* Adjust the color for orphaned symlinks. */
if (type == C_LINK && !linkok)
{
if (color_symlink_as_referent
|| color_indicator[C_ORPHAN].string)
if (color_symlink_as_referent || is_colored (C_ORPHAN))
type = C_ORPHAN;
}
+15
View File
@@ -263,6 +263,21 @@ my @Tests =
{POST => sub {unlink 's' or die "s: $!\n";
restore_ls_colors; }},
],
# The patch associated with sl-dangle[678] introduced a regression
# that was fixed after coreutils-8.19. This edge case triggers when
# listing a dir containing dangling symlinks, but with orphans uncolored.
# I.E. the same as the previous test, but listing the directory
# rather than the symlink directly.
['sl-dangle9', '--color=always d',
{OUT => "$e\e[1;36ms$e\n"},
{PRE => sub {mkdir 'd',0755 or die "d: $!\n";
symlink 'dangle', 'd/s' or die "d/s: $!\n";
push_ls_colors('ln=1;36:or=:')
}},
{POST => sub {unlink 'd/s' or die "d/s: $!\n";
rmdir 'd' or die "d: $!\n";
restore_ls_colors; }},
],
# Test for a bug that was introduced in coreutils-4.5.4; fixed in 4.5.5.
# To demonstrate it, the file in question (with executable bit set)