summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Dudka <kdudka@redhat.com>2009-06-10 19:44:43 +0200
committerJim Meyering <meyering@redhat.com>2009-06-11 09:53:50 +0200
commit0df338f6719ec2bcf1e1dea2d8b12dc66daf8a1e (patch)
tree4c77cf9c92a258da00f48e002142e9e4946d7bc1
parent502be19e0fdb52dbc76fe95d5a4966ef0b06f3dc (diff)
downloadcoreutils-0df338f6719ec2bcf1e1dea2d8b12dc66daf8a1e.tar.xz
ls --color: do not colorize files with multiple hard links by default
* src/ls.c: Rename hl->mh, do not colorize files with multiple hard links by default. * src/dircolors.c: Rename HARDLINK -> MULTIHARDLINK, hl -> mh. * src/dircolors.hin: Do not colorize files with multiple hard links by default. * tests/Makefile.am: Rename the test case accordingly. * tests/ls/multihardlink: Additionally test ls' default behavior and factor out some duplication. * NEWS: Mention the change in behavior.
-rw-r--r--NEWS9
-rw-r--r--src/dircolors.c4
-rw-r--r--src/dircolors.hin2
-rw-r--r--src/ls.c10
-rw-r--r--tests/Makefile.am2
-rwxr-xr-xtests/ls/hardlink60
-rwxr-xr-xtests/ls/multihardlink74
7 files changed, 92 insertions, 69 deletions
diff --git a/NEWS b/NEWS
index 29b09a08f..0455d592d 100644
--- a/NEWS
+++ b/NEWS
@@ -7,6 +7,15 @@ GNU coreutils NEWS -*- outline -*-
truncate -s failed to skip all whitespace in the option argument in
some locales.
+** Changes in behavior
+
+ ls --color: files with multiple hard links are no longer colored differently
+ by default. That can be enabled by changing the LS_COLORS environment
+ variable. You can control that using the MULTIHARDLINK dircolors input
+ variable which corresponds to the 'mh' LS_COLORS item. Note these variables
+ were renamed from 'HARDLINK' and 'hl' which were available since
+ coreutils-7.1 when this feature was introduced.
+
** New features
chroot now accepts the options --userspec and --groups.
diff --git a/src/dircolors.c b/src/dircolors.c
index f01d5575f..39c8e64b7 100644
--- a/src/dircolors.c
+++ b/src/dircolors.c
@@ -64,14 +64,14 @@ static const char *const slack_codes[] =
"CHR", "CHAR", "DOOR", "EXEC", "LEFT", "LEFTCODE", "RIGHT", "RIGHTCODE",
"END", "ENDCODE", "SUID", "SETUID", "SGID", "SETGID", "STICKY",
"OTHER_WRITABLE", "OWR", "STICKY_OTHER_WRITABLE", "OWT", "CAPABILITY",
- "HARDLINK", "CLRTOEOL", NULL
+ "MULTIHARDLINK", "CLRTOEOL", 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", "hl", "cl", NULL
+ "su", "su", "sg", "sg", "st", "ow", "ow", "tw", "tw", "ca", "mh", "cl", NULL
};
verify (ARRAY_CARDINALITY (slack_codes) == ARRAY_CARDINALITY (ls_codes));
diff --git a/src/dircolors.hin b/src/dircolors.hin
index 5621259a2..30fd87856 100644
--- a/src/dircolors.hin
+++ b/src/dircolors.hin
@@ -70,7 +70,7 @@ RESET 0 # reset to "normal" color
DIR 01;34 # directory
LINK 01;36 # symbolic link. (If you set this to 'target' instead of a
# numerical value, the color is as for the file pointed to.)
-HARDLINK 44;37 # regular file with more than one link
+MULTIHARDLINK 00 # regular file with more than one link
FIFO 40;33 # pipe
SOCK 01;35 # socket
DOOR 01;35 # door
diff --git a/src/ls.c b/src/ls.c
index 838431c96..48bc47e90 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -529,7 +529,7 @@ enum indicator_no
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_HARDLINK,
+ C_STICKY, C_OTHER_WRITABLE, C_STICKY_OTHER_WRITABLE, C_CAP, C_MULTIHARDLINK,
C_CLR_TO_EOL
};
@@ -537,7 +537,7 @@ 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", "hl", "cl", NULL
+ "ow", "tw", "ca", "mh", "cl", NULL
};
struct color_ext_type
@@ -571,7 +571,7 @@ static struct bin_str color_indicator[] =
{ 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") }, /* ca: black on red */
- { LEN_STR_PAIR ("44;37") }, /* hl: white on blue */
+ { 0, NULL }, /* mh: disabled by default */
{ LEN_STR_PAIR ("\033[K") }, /* cl: clear to end of line */
};
@@ -4106,8 +4106,8 @@ print_color_indicator (const char *name, mode_t mode, int linkok,
type = C_CAP;
else if ((mode & S_IXUGO) != 0)
type = C_EXEC;
- else if (is_colored (C_HARDLINK) && (1 < nlink))
- type = C_HARDLINK;
+ else if (is_colored (C_MULTIHARDLINK) && (1 < nlink))
+ type = C_MULTIHARDLINK;
}
else if (S_ISDIR (mode))
{
diff --git a/tests/Makefile.am b/tests/Makefile.am
index a0ed986ea..2405ce44f 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -343,10 +343,10 @@ TESTS = \
ls/dired \
ls/file-type \
ls/follow-slink \
- ls/hardlink \
ls/infloop \
ls/inode \
ls/m-option \
+ ls/multihardlink \
ls/no-arg \
ls/no-cap \
ls/proc-selinux-segfault \
diff --git a/tests/ls/hardlink b/tests/ls/hardlink
deleted file mode 100755
index b12091466..000000000
--- a/tests/ls/hardlink
+++ /dev/null
@@ -1,60 +0,0 @@
-#!/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_hl='44;37'
-code_png='01;35'
-fail=0
-
-# regular file - not hard linked
-LS_COLORS="hl=$code_hl" 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_hl" 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
-
-# hard links and png
-mv file2 file2.png || framework_failure
-LS_COLORS="hl=$code_hl:*.png=$code_png" ls -U1 --color=always file1 file2.png > out || fail=1
-printf "\033[0m\033[44;37mfile1\033[0m
-\033[44;37mfile2.png\033[0m
-\033[m" > out_ok || fail=1
-compare out out_ok || fail=1
-
-# hard links and png (hard links highlighting disabled)
-LS_COLORS="hl=:*.png=$code_png" ls -U1 --color=always file1 file2.png > out || fail=1
-printf "file1
-\033[0m\033[01;35mfile2.png\033[0m
-\033[m" > out_ok || fail=1
-compare out out_ok || fail=1
-
-Exit $fail
diff --git a/tests/ls/multihardlink b/tests/ls/multihardlink
new file mode 100755
index 000000000..d237a71a9
--- /dev/null
+++ b/tests/ls/multihardlink
@@ -0,0 +1,74 @@
+#!/bin/sh
+# Ensure "ls --color" properly colorizes hard linked files.
+
+# Copyright (C) 2008-2009 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_mh='44;37'
+code_png='01;35'
+c0=$(printf '\033[0m')
+c_end=$(printf '\033[m')
+c_mh=$(printf '\033[%sm' $code_mh)
+c_png=$(printf '\033[%sm' $code_png)
+fail=0
+
+# regular file - not hard linked
+LS_COLORS="mh=$code_mh" ls -U1 --color=always file > out || fail=1
+printf "file\n" > out_ok || framework_failure
+compare out out_ok || fail=1
+
+# hard links
+LS_COLORS="mh=$code_mh" ls -U1 --color=always file1 file2 > out || fail=1
+printf "$c0${c_mh}file1$c0
+${c_mh}file2$c0
+$c_end" > out_ok || framework_failure
+compare out out_ok || fail=1
+
+# hard links and png (hard link coloring takes precedence)
+mv file2 file2.png || framework_failure
+LS_COLORS="mh=$code_mh:*.png=$code_png" ls -U1 --color=always file1 file2.png \
+ > out || fail=1
+printf "$c0${c_mh}file1$c0
+${c_mh}file2.png$c0
+$c_end" > out_ok || framework_failure
+compare out out_ok || fail=1
+
+# hard links and png (hard link coloring disabled => png coloring enabled)
+LS_COLORS="mh=00:*.png=$code_png" ls -U1 --color=always file1 file2.png > out \
+ || fail=1
+printf "file1
+$c0${c_png}file2.png$c0
+$c_end" > out_ok || framework_failure
+compare out out_ok || fail=1
+
+# hard links and png (hard link coloring not enabled explicitly => png coloring)
+LS_COLORS="*.png=$code_png" ls -U1 --color=always file1 file2.png > out \
+ || fail=1
+printf "file1
+$c0${c_png}file2.png$c0
+$c_end" > out_ok || framework_failure
+compare out out_ok || fail=1
+
+Exit $fail