From ebf697b623435d46dd48998408e1c7cf3eba1623 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A1draig=20Brady?= Date: Sun, 16 Sep 2012 04:10:50 +0100 Subject: [PATCH] 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 --- NEWS | 4 ++++ THANKS.in | 1 + src/ls.c | 11 ++--------- tests/misc/ls-misc.pl | 15 +++++++++++++++ 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/NEWS b/NEWS index 2e69391..ab205f5 100644 --- a/NEWS +++ b/NEWS @@ -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)] diff --git a/THANKS.in b/THANKS.in index 2c3f83c..b0061b3 100644 --- a/THANKS.in +++ b/THANKS.in @@ -153,6 +153,7 @@ David Godfrey address@hidden David Luyer address@hidden David Madore address@hidden David Malone address@hidden +David Matei address@hidden Davide Canova address@hidden Dawson Engler address@hidden Dean Gaudet address@hidden diff --git a/src/ls.c b/src/ls.c index 9494ae9..106d234 100644 --- a/src/ls.c +++ b/src/ls.c @@ -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; } diff --git a/tests/misc/ls-misc.pl b/tests/misc/ls-misc.pl index 71647f9..04d8016 100755 --- a/tests/misc/ls-misc.pl +++ b/tests/misc/ls-misc.pl @@ -263,6 +263,21 @@ my @Tests = {POST => sub {unlink 's' or die "s: $!\n"; restore_ls_colors; }}, ], + # The code related to the above fixes introduced a regression, + # that was fixed after coreutils-8.19. This is the case 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) -- 1.7.6.4