From f0b5e513d901871a3994349322785ac1882eb873 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Tue, 2 Jan 2007 07:27:22 +0100 Subject: Now, "ls -FRL" always follows symbolic links on Linux. * NEWS: Mention this bug fix. * src/ls.c (gobble_file): Fix bug reported by Nobuyuki Tsuchimura in http://lists.gnu.org/archive/html/bug-coreutils/2006-12/msg00152.html where "ls -FRL" didn't follow a symbolic link in some cases on Linux. * tests/ls/follow-slink: Add a test for this case. Signed-off-by: Jim Meyering --- ChangeLog | 10 ++++++++++ NEWS | 4 ++++ src/ls.c | 19 ++++++++++--------- tests/ls/follow-slink | 28 ++++++++++++++++++++++------ 4 files changed, 46 insertions(+), 15 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1854f81fa..5e7ed1d02 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +2007-01-02 Paul Eggert + + Now, "ls -FRL" always follows symbolic links on Linux. + * NEWS: Mention this bug fix. + * src/ls.c (gobble_file): Fix bug reported by + Nobuyuki Tsuchimura in + http://lists.gnu.org/archive/html/bug-coreutils/2006-12/msg00152.html + where "ls -FRL" didn't follow a symbolic link in some cases on Linux. + * tests/ls/follow-slink: Add a test for this case. + 2007-01-01 Jim Meyering * tests/rm/fail-eperm: Revert last change. The PATH=... setting diff --git a/NEWS b/NEWS index c934cd981..76f90d304 100644 --- a/NEWS +++ b/NEWS @@ -17,6 +17,9 @@ GNU coreutils NEWS -*- outline -*- dd bs= operands now silently override any later ibs= and obs= operands, as POSIX and tradition require. + "ls -FRL" always follows symbolic links on Linux. Introduced in + coreutils-6.0. + A cross-partition "mv /etc/passwd ~" (by non-root) now prints a reasonable diagnostic. Before, it would print this: "mv: cannot remove `/etc/passwd': Not a directory". @@ -24,6 +27,7 @@ GNU coreutils NEWS -*- outline -*- "rm -rf /etc/passwd" (run by non-root) now prints a diagnostic. Before it would print nothing. + * Noteworthy changes in release 6.7 (2006-12-08) [stable] ** Bug fixes diff --git a/src/ls.c b/src/ls.c index 63d363fd2..feba59141 100644 --- a/src/ls.c +++ b/src/ls.c @@ -1,5 +1,5 @@ /* `dir', `vdir' and `ls' directory listing programs for GNU. - Copyright (C) 85, 88, 90, 91, 1995-2006 Free Software Foundation, Inc. + Copyright (C) 85, 88, 90, 91, 1995-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 @@ -2534,14 +2534,15 @@ gobble_file (char const *name, enum filetype type, ino_t inode, direct.d_type), we have to stat it in order to indicate sticky and/or other-writable attributes. */ || (type == directory && print_with_color) - || (print_inode - && (inode == NOT_AN_INODE_NUMBER - /* When dereferencing symlinks, the inode must come from - stat, but readdir provides the inode of lstat. Command - line dereferences are already taken care of by the above - assertion that the inode number is not yet known. */ - || (dereference == DEREF_ALWAYS - && (type == symbolic_link || type == unknown)))) + /* When dereferencing symlinks, the inode and type must come from + stat, but readdir provides the inode and type of lstat. */ + || ((print_inode || format_needs_type) + && (type == symbolic_link || type == unknown) + && (dereference == DEREF_ALWAYS + || (command_line_arg && dereference != DEREF_NEVER))) + /* Command line dereferences are already taken care of by the above + assertion that the inode number is not yet known. */ + || (print_inode && inode == NOT_AN_INODE_NUMBER) || (format_needs_type && (type == unknown || command_line_arg /* --indicator-style=classify (aka -F) diff --git a/tests/ls/follow-slink b/tests/ls/follow-slink index e79896b96..00e9b1bfb 100755 --- a/tests/ls/follow-slink +++ b/tests/ls/follow-slink @@ -1,7 +1,7 @@ #!/bin/sh # make sure ls -L always follows symlinks -# Copyright (C) 2000, 2002, 2004, 2006 Free Software Foundation, Inc. +# Copyright (C) 2000, 2002, 2004, 2006, 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 @@ -33,9 +33,10 @@ mkdir $tmp || framework_failure=1 cd $tmp || framework_failure=1 # Isolate output files from directory being listed -mkdir dir || framework_failure=1 +mkdir dir dir/sub dir1 || framework_failure=1 cd dir || framework_failure=1 ln -s link link || framework_failure=1 +ln -s ../../dir1 sub/link-to-dir || framework_failure=1 # Make sure the symlink was created. # `ln -s link link' succeeds, but creates no file on @@ -56,15 +57,30 @@ ls -L link 2> /dev/null && fail=1 # list the link, provided no further information about the link needed # to be printed. Since POSIX does not specify one way or the other, we # opt for compatibility (this was broken in 5.3.0 through 5.94). -ls -L > ../out || fail=1 +LC_ALL=C ls -L > ../out-L || fail=1 +LC_ALL=C ls -FLR sub > ../out-FLR-sub || fail=1 cd .. || fail=1 -cat <<\EOF > exp +cat <<\EOF > exp-L link +sub EOF -cmp out exp || fail=1 -test $fail = 1 && diff out exp 2> /dev/null +cat <<\EOF > exp-FLR-sub +sub: +link-to-dir/ + +sub/link-to-dir: +EOF + +cmp out-L exp-L || { + fail=1 + diff out-L exp-L +} +cmp out-FLR-sub exp-FLR-sub || { + fail=1 + diff out-FLR-sub exp-FLR-sub +} (exit $fail); exit $fail -- cgit v1.2.3-54-g00ecf