1
0
mirror of git://git.sv.gnu.org/coreutils.git synced 2026-04-21 11:16:16 +02:00

rm: give a sensible diagnostic when failing to remove a symlink

On some systems (those with openat et al), when rm would fail to
remove a symlink, it would fail with the misleading diagnostic,
"Too many levels of symbolic links".
* NEWS: Mention the bug fix.
* src/remove.c (is_nondir_lstat): New function.
(remove_entry): Use it to catch failed-to-remove symlink (and any
other non-dir) here so that we don't fall through and try to treat
it as directory, which -- with a symlink -- would provoke the bogus
ELOOP failure.
* tests/rm/fail-eacces: Add a test for the above.
* src/c99-to-c89.diff: Adjust offsets.
This commit is contained in:
Jim Meyering
2007-09-22 10:02:09 +02:00
parent 920b4416c1
commit a7ec8caffe
5 changed files with 60 additions and 5 deletions

View File

@@ -1,5 +1,8 @@
#!/bin/sh
# Ensure that rm -rf unremovable-non-dir gives a diagnostic.
# Test both a regular file and a symlink -- it makes a difference to rm.
# With the symlink, rm from coreutils-6.9 would fail with a misleading
# ELOOP diagnostic.
# Copyright (C) 2006-2007 Free Software Foundation, Inc.
@@ -25,7 +28,19 @@ fi
. $srcdir/../test-lib.sh
skip_if_root_
mkdir d && touch d/f && chmod a-w d || framework_failure
ok=0
mkdir d &&
touch d/f &&
ln -s f d/slink &&
chmod a-w d &&
ok=1
test $ok = 1 || framework_failure
mkdir e &&
ln -s f e/slink &&
chmod a-w e &&
ok=1
test $ok = 1 || framework_failure
fail=0
@@ -33,7 +48,13 @@ rm -rf d/f 2> out && fail=1
cat <<\EOF > exp
rm: cannot remove `d/f': Permission denied
EOF
compare out exp || fail=1
# This used to fail with ELOOP.
rm -rf e 2> out && fail=1
cat <<\EOF > exp
rm: cannot remove `e/slink': Permission denied
EOF
compare out exp || fail=1
(exit $fail); exit $fail