"SYMLINK", "ORPHAN", "MISSING", "FIFO", "PIPE", "SOCK", "BLK", "BLOCK",
"CHR", "CHAR", "DOOR", "EXEC", "LEFT", "LEFTCODE", "RIGHT", "RIGHTCODE",
"END", "ENDCODE", "SUID", "SETUID", "SGID", "SETGID", "STICKY",
- "OTHER_WRITABLE", "OWR", "STICKY_OTHER_WRITABLE", "OWT", "CAPABILITY", NULL
+ "OTHER_WRITABLE", "OWR", "STICKY_OTHER_WRITABLE", "OWT", "CAPABILITY",
+ "HARDLINK", NULL
};
static const char *const ls_codes[] =
{
"no", "no", "fi", "rs", "di", "ln", "ln", "ln", "or", "mi", "pi", "pi",
"so", "bd", "bd", "cd", "cd", "do", "ex", "lc", "lc", "rc", "rc", "ec", "ec",
- "su", "su", "sg", "sg", "st", "ow", "ow", "tw", "tw", "ca", NULL
+ "su", "su", "sg", "sg", "st", "ow", "ow", "tw", "tw", "ca", "hl", NULL
};
#define array_len(Array) (sizeof (Array) / sizeof *(Array))
verify (array_len (slack_codes) == array_len (ls_codes));
ino_t inode, bool command_line_arg,
char const *dirname);
static bool print_color_indicator (const char *name, mode_t mode, int linkok,
- bool stat_ok, enum filetype type);
+ bool stat_ok, enum filetype type,
+ nlink_t nlink);
static void put_indicator (const struct bin_str *ind);
static void add_ignore_pattern (const char *pattern);
static void attach (char *dest, const char *dirname, const char *name);
static void print_name_with_quoting (const char *p, mode_t mode,
int linkok, bool stat_ok,
enum filetype type,
- struct obstack *stack);
+ struct obstack *stack, nlink_t nlink);
static void prep_non_filename_text (void);
static void print_type_indicator (bool stat_ok, mode_t mode,
enum filetype type);
C_LEFT, C_RIGHT, C_END, C_RESET, C_NORM, C_FILE, C_DIR, C_LINK,
C_FIFO, C_SOCK,
C_BLK, C_CHR, C_MISSING, C_ORPHAN, C_EXEC, C_DOOR, C_SETUID, C_SETGID,
- C_STICKY, C_OTHER_WRITABLE, C_STICKY_OTHER_WRITABLE, C_CAP
+ C_STICKY, C_OTHER_WRITABLE, C_STICKY_OTHER_WRITABLE, C_CAP, C_HARDLINK
};
static const char *const indicator_name[]=
{
"lc", "rc", "ec", "rs", "no", "fi", "di", "ln", "pi", "so",
"bd", "cd", "mi", "or", "ex", "do", "su", "sg", "st",
- "ow", "tw", "ca", NULL
+ "ow", "tw", "ca", "hl", NULL
};
struct color_ext_type
{ LEN_STR_PAIR ("37;44") }, /* st: sticky: black on blue */
{ LEN_STR_PAIR ("34;42") }, /* ow: other-writable: blue on green */
{ LEN_STR_PAIR ("30;42") }, /* tw: ow w/ sticky: black on green */
- { LEN_STR_PAIR ("30;41") }, /* capability: black on red */
+ { LEN_STR_PAIR ("30;41") }, /* ca: black on red */
+ { LEN_STR_PAIR ("44;37") }, /* hl: white on blue */
};
/* FIXME: comment */
DIRED_FPUTS (buf, stdout, p - buf);
print_name_with_quoting (f->name, FILE_OR_LINK_MODE (f), f->linkok,
- f->stat_ok, f->filetype, &dired_obstack);
+ f->stat_ok, f->filetype, &dired_obstack,
+ f->stat.st_nlink);
if (f->filetype == symbolic_link)
{
{
DIRED_FPUTS_LITERAL (" -> ", stdout);
print_name_with_quoting (f->linkname, f->linkmode, f->linkok - 1,
- f->stat_ok, f->filetype, NULL);
+ f->stat_ok, f->filetype, NULL,
+ f->stat.st_nlink);
if (indicator_style != none)
print_type_indicator (true, f->linkmode, unknown);
}
static void
print_name_with_quoting (const char *p, mode_t mode, int linkok,
bool stat_ok, enum filetype type,
- struct obstack *stack)
+ struct obstack *stack, nlink_t nlink)
{
bool used_color_this_time
= (print_with_color
- && print_color_indicator (p, mode, linkok, stat_ok, type));
+ && print_color_indicator (p, mode, linkok, stat_ok, type, nlink));
if (stack)
PUSH_CURRENT_DIRED_POS (stack);
printf ("%*s ", format == with_commas ? 0 : scontext_width, f->scontext);
print_name_with_quoting (f->name, FILE_OR_LINK_MODE (f), f->linkok,
- f->stat_ok, f->filetype, NULL);
+ f->stat_ok, f->filetype, NULL, f->stat.st_nlink);
if (indicator_style != none)
print_type_indicator (f->stat_ok, f->stat.st_mode, f->filetype);
/* Returns whether any color sequence was printed. */
static bool
print_color_indicator (const char *name, mode_t mode, int linkok,
- bool stat_ok, enum filetype filetype)
+ bool stat_ok, enum filetype filetype,
+ nlink_t nlink)
{
int type;
struct color_ext_type *ext; /* Color extension */
type = C_CAP;
else if ((mode & S_IXUGO) != 0)
type = C_EXEC;
+ else if (1 < nlink)
+ type = C_HARDLINK;
}
else if (S_ISDIR (mode))
{
--- /dev/null
+#!/bin/sh
+# Ensure "ls --color" properly colorizes hard linked files.
+
+# Copyright (C) 2008 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+if test "$VERBOSE" = yes; then
+ set -x
+ ls --version
+fi
+
+. $srcdir/test-lib.sh
+working_umask_or_skip_
+
+touch file file1 || framework_failure
+ln file1 file2 || skip_test_ "can't create hard link"
+code='44;37'
+fail=0
+
+# regular file - not hard linked
+LS_COLORS="hl=$code" ls -U1 --color=always file > out || fail=1
+printf "file\n" > out_ok || fail=1
+compare out out_ok || fail=1
+
+# hard links
+LS_COLORS="hl=$code" ls -U1 --color=always file1 file2 > out || fail=1
+printf "\033[0m\033[44;37mfile1\033[0m
+\033[44;37mfile2\033[0m
+\033[m" > out_ok || fail=1
+compare out out_ok || fail=1
+
+Exit $fail