]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
chmod: don't ignore a dangling symlink
authorJim Meyering <jim@meyering.net>
Fri, 7 Sep 2007 08:37:08 +0000 (10:37 +0200)
committerJim Meyering <jim@meyering.net>
Fri, 7 Sep 2007 08:45:22 +0000 (10:45 +0200)
* NEWS: Mention the bug fix.
* src/chmod.c (process_file): Handle the case of FTS_SLNONE,
i.e., give a diagnostic saying we cannot operate on such a file.
* tests/chmod/thru-dangling: Compare new stderr output with expected.

ChangeLog
NEWS
src/chmod.c
tests/chmod/thru-dangling

index c09128bb5da4d59d7376a868c5927b6dac0c1dcd..a8c606bf9ba011072a27bb94662050715a79d409 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-09-07  Jim Meyering  <jim@meyering.net>
+
+       chmod: don't ignore a dangling symlink
+       * NEWS: Mention the bug fix.
+       * src/chmod.c (process_file): Handle the case of FTS_SLNONE,
+       i.e., give a diagnostic saying we cannot operate on such a file.
+       * tests/chmod/thru-dangling: Compare new stderr output with expected.
+
 2007-09-07  Bob Proulx  <bob@proulx.com>
 
        Add a test: demonstrate that chmod ignores a dangling symlink
diff --git a/NEWS b/NEWS
index 6a0f18d9aa62c5e9cfd84445019b89bd448ebbcc..93a632c5a84a3bba3a6cc4208da2e33048d76406 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -70,6 +70,10 @@ GNU coreutils NEWS                                    -*- outline -*-
 
 ** Bug fixes
 
+  chmod no longer ignores a dangling symlink.  Now, chmod fails
+  with a diagnostic saying that it cannot operate on such a file.
+  [bug introduced in coreutils-5.1.0]
+
   cp attempts to read a regular file, even if stat says it is empty.
   Before, "cp /proc/cpuinfo c" would create an empty file when the kernel
   reports stat.st_size == 0, while "cat /proc/cpuinfo > c" would "work",
index a6705542005da334311c86bd69fc2385457acec9..a22e5c127fc5078ca3c8561c037c05f9daa6906c 100644 (file)
@@ -1,5 +1,5 @@
 /* chmod -- change permission modes of files
-   Copyright (C) 89, 90, 91, 1995-2006 Free Software Foundation, Inc.
+   Copyright (C) 89, 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
@@ -220,6 +220,11 @@ process_file (FTS *fts, FTSENT *ent)
       ok = false;
       break;
 
+    case FTS_SLNONE:
+      error (0, 0, _("cannot operate on dangling symlink %s"),
+            quote (file_full_name));
+      ok = false;
+
     default:
       break;
     }
index d972a8abf4e8949c5299ef203216776e08a20b37..7a82db83da45ff550f046bc060894fe30116a9d9 100755 (executable)
@@ -40,6 +40,10 @@ fi
 fail=0
 
 # This operation cannot succeed since the symbolic link dangles.
-chmod 644 dangle && fail=1
+chmod 644 dangle 2> out && fail=1
+
+echo "chmod: cannot operate on dangling symlink \`dangle'" > exp
+cmp out exp || fail=1
+test $fail = 1 && diff out exp 2> /dev/null
 
 (exit $fail); exit $fail