diff options
author | Jim Meyering <jim@meyering.net> | 2007-07-15 22:13:16 +0200 |
---|---|---|
committer | Jim Meyering <jim@meyering.net> | 2007-07-15 22:13:44 +0200 |
commit | 0a744370bb9a58b023d518bf4f32a5cb36929138 (patch) | |
tree | 94501f57b387e79c1f25abe439334d0b7a528ac5 /tests/ls | |
parent | 065109af86c08ca6b2e2ce1d160b63a38df78188 (diff) | |
download | coreutils-0a744370bb9a58b023d518bf4f32a5cb36929138.tar.xz |
ls --color: Don't stat symlinks when neither ORPHAN nor MISSING attribute has a color.
* src/ls.c (main): Don't set check_symlink_color when C_EXEC is
colored, unless ln=target (aka color_symlink_as_referent) is set.
(gobble_file): Set f->linkok = true also when !check_symlink_color.
http://thread.gmane.org/gmane.comp.gnu.coreutils.bugs/10608/focus=10927
Reported by Jeremy Maitin-Shepard.
* tests/strace: New file, contents extracted from...
* tests/mv/atomic: ...here. Source strace.
* tests/ls/stat-free-symlinks: New file. Test for the above.
Use strace to ensure that in this corner case, ls does not call stat.
* tests/ls/Makefile.am (TESTS): Add stat-free-symlinks.
* tests/Makefile.am (EXTRA_DIST): Add strace.
Diffstat (limited to 'tests/ls')
-rw-r--r-- | tests/ls/Makefile.am | 1 | ||||
-rwxr-xr-x | tests/ls/stat-free-symlinks | 72 |
2 files changed, 73 insertions, 0 deletions
diff --git a/tests/ls/Makefile.am b/tests/ls/Makefile.am index ecd018edb..45ca9fe5e 100644 --- a/tests/ls/Makefile.am +++ b/tests/ls/Makefile.am @@ -18,6 +18,7 @@ # 02110-1301, USA. TESTS = \ + stat-free-symlinks \ nameless-uid \ color-dtype-dir \ stat-failed \ diff --git a/tests/ls/stat-free-symlinks b/tests/ls/stat-free-symlinks new file mode 100755 index 000000000..78d91c90b --- /dev/null +++ b/tests/ls/stat-free-symlinks @@ -0,0 +1,72 @@ +#!/bin/sh +# ensure that ls does not stat a symlink in an unusual case + +# Copyright (C) 2007 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, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA +# 02110-1301, USA. + +if test "$VERBOSE" = yes; then + set -x + ls --version +fi + +. $srcdir/../envvar-check +. $srcdir/../strace + +pwd=`pwd` +t0=`echo "$0"|sed 's,.*/,,'`.tmp; tmp=$t0/$$ +trap 'status=$?; cd "$pwd" && chmod -R u+rwx $t0 && rm -rf $t0 && exit $status' 0 +trap '(exit $?); exit $?' 1 2 13 15 + +framework_failure=0 +mkdir -p $tmp || framework_failure=1 +cd $tmp || framework_failure=1 + +touch x || framework_failure=1 +chmod a+x x || framework_failure=1 +ln -s x link-to-x || framework_failure=1 + +if test $framework_failure = 1; then + echo "$0: failure in testing framework" 1>&2 + (exit 1); exit 1 +fi + +fail=0 + +# ls from coreutils 6.9 would unnecessarily stat a symlink in an unusual case: +# When not coloring orphan and missing entries, and without ln=target, +# ensure that ls -F (or -d, or -l: i.e., when not dereferencing) +# does not stat a symlink to directory, and does still color that +# symlink and an executable file properly. + +LS_COLORS='or=0:mi=0:ex=01;32:ln=01;35' \ + strace -qe stat ls -F --color=always x link-to-x > out 2> err || fail=1 + +# With coreutils 6.9 and earlier, this file would contain a +# line showing ls had called stat on "x". +test -s err && fail=1 + +# Check that output is colorized, as requested, too. +{ + printf '\e[0m\e[01;35mlink-to-x\e[0m@\n' + printf '\e[01;32mx\e[0m*\n' + printf '\e[m' +} > exp || fail=1 + +cmp out exp || fail=1 +test $fail = 1 && diff out exp 2> /dev/null + +(exit $fail); exit $fail |