From 6202e797128c832f4b3afab19161c5a9a335bb87 Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Thu, 23 Nov 2000 15:04:17 +0000 Subject: (mode_changed): New function. (change_file_mode): Use it to determine accurately when -c should make chmod announce there's been a change. --- src/chmod.c | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) 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) -- cgit v1.2.3-70-g09d2