summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>2000-11-23 15:04:17 +0000
committerJim Meyering <jim@meyering.net>2000-11-23 15:04:17 +0000
commit6202e797128c832f4b3afab19161c5a9a335bb87 (patch)
treefb679f5f67255b8f141ab7161e881a3863410531
parentbd320fe27bb534465ea6d9d8a04c830303ec3c7d (diff)
downloadcoreutils-6202e797128c832f4b3afab19161c5a9a335bb87.tar.xz
(mode_changed): New function.
(change_file_mode): Use it to determine accurately when -c should make chmod announce there's been a change.
-rw-r--r--src/chmod.c29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/chmod.c b/src/chmod.c
index 73e210f2d..dd3c42dcd 100644
--- a/src/chmod.c
+++ b/src/chmod.c
@@ -95,6 +95,31 @@ static struct option const long_options[] =
{0, 0, 0, 0}
};
+static int
+mode_changed (const char *file, mode_t old_mode)
+{
+ struct stat new_stats;
+
+ if (lstat (file, &new_stats))
+ {
+ if (force_silent == 0)
+ error (0, errno, _("getting new attributes of %s"), quote (file));
+ return 0;
+ }
+
+#ifdef S_ISLNK
+ if (S_ISLNK (new_stats.st_mode)
+ && stat (file, &new_stats))
+ {
+ if (force_silent == 0)
+ error (0, errno, _("getting new attributes of %s"), quote (file));
+ return 0;
+ }
+#endif
+
+ return old_mode != new_stats.st_mode;
+}
+
/* Tell the user how/if the MODE of FILE has been changed.
CHANGED describes what (if anything) has happened. */
@@ -166,7 +191,9 @@ change_file_mode (const char *file, const struct mode_change *changes,
fail = chmod (file, newmode);
saved_errno = errno;
- if (verbosity == V_high || (verbosity == V_changes_only && !fail))
+ if (verbosity == V_high
+ || (verbosity == V_changes_only
+ && !fail && mode_changed (file, file_stats.st_mode)))
describe_change (file, newmode, (fail ? CH_FAILED : CH_SUCCEEDED));
if (fail)