From a7ec8caffe1a48590f5e3da9400080ab8a6ec303 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Sat, 22 Sep 2007 10:02:09 +0200 Subject: 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. --- tests/rm/fail-eacces | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'tests/rm') diff --git a/tests/rm/fail-eacces b/tests/rm/fail-eacces index b15c2f544..d49764c53 100755 --- a/tests/rm/fail-eacces +++ b/tests/rm/fail-eacces @@ -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 -- cgit v1.2.3-54-g00ecf