From be8411ced1cac411d5e50a6bc059244d583099e0 Mon Sep 17 00:00:00 2001 From: Kamil Dudka Date: Wed, 10 Jun 2009 16:47:53 +0200 Subject: [PATCH] ls --color: hard link highlighting is now disabled by default * src/ls.c: Rename hl->mh, disable hard link highlighting by default. * src/dircolors.c: Rename HARDLINK -> MULTIHARDLINK, hl -> mh. * src/dircolors.hin: Disable hard link highlighting by default. * tests/Makefile.am: Rename the test case accordingly. * NEWS: Mention the change in behavior. --- NEWS | 7 +++++ src/dircolors.c | 4 +- src/dircolors.hin | 2 +- src/ls.c | 10 ++++---- tests/Makefile.am | 2 +- tests/ls/hardlink | 60 ------------------------------------------------ tests/ls/multihardlink | 60 ++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 76 insertions(+), 69 deletions(-) delete mode 100755 tests/ls/hardlink create mode 100755 tests/ls/multihardlink diff --git a/NEWS b/NEWS index 29b09a0..d6d88c8 100644 --- a/NEWS +++ b/NEWS @@ -7,6 +7,13 @@ GNU coreutils NEWS -*- outline -*- truncate -s failed to skip all whitespace in the option argument in some locales. +** Changes in behavior + + ls --color: hard link highlighting is now disabled by default, it can be + enabled by changing the LS_COLORS environment variable. You can do it + explicitly in your profile. Note the init string was renamed from HARDLINK + to MULTIHARDLINK and the appropriate color code from 'hl' to 'mh'. + ** New features chroot now accepts the options --userspec and --groups. diff --git a/src/dircolors.c b/src/dircolors.c index f01d557..39c8e64 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 5621259..30fd878 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 838431c..48bc47e 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 a0ed986..2405ce4 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 b120914..0000000 --- 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 . - -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 0000000..0d626d6 --- /dev/null +++ b/tests/ls/multihardlink @@ -0,0 +1,60 @@ +#!/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 . + +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' +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 || fail=1 +compare out out_ok || fail=1 + +# hard links +LS_COLORS="mh=$code_mh" 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="mh=$code_mh:*.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 higmhighting disabled) +LS_COLORS="mh=:*.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 -- 1.6.1.2