From e89c998a9ecbe0a1b29d7e6c97531d5069877087 Mon Sep 17 00:00:00 2001 From: Bernhard Voelker Date: Wed, 25 May 2011 22:11:08 +0100 Subject: [PATCH] chmod: output the original mode in verbose mode MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * src/chmod.c (describe_change): Pass in the original mode, and output this in the messages. * tests/chmod/c-option: Adjust as per the new message. * THANKS.in: Remove the now auto-generated name. * NEWS: Mention the change in behavior. Signed-off-by: Pádraig Brady --- NEWS | 4 ++++ THANKS.in | 1 - src/chmod.c | 18 +++++++++++++----- tests/chmod/c-option | 4 ++-- 4 files changed, 19 insertions(+), 8 deletions(-) diff --git a/NEWS b/NEWS index 502a5c6..c4238f4 100644 --- a/NEWS +++ b/NEWS @@ -10,6 +10,10 @@ GNU coreutils NEWS -*- outline -*- split --number l/... no longer creates extraneous files in certain cases. [bug introduced in coreutils-8.8] +** Changes in behavior + + chmod -v and -c now output the original mode in the messages. + ** New features split accepts a new --filter=CMD option. With it, split filters output diff --git a/THANKS.in b/THANKS.in index 9120ba3..ec97e9c 100644 --- a/THANKS.in +++ b/THANKS.in @@ -80,7 +80,6 @@ Bernd Melchers melchers@cis.fu-berlin.de Bernhard Baehr bernhard.baehr@gmx.de Bernhard Gabler bernhard@uni-koblenz.de Bernhard Rosenkraenzer bero@redhat.de -Bernhard Voelker bernhard.voelker@siemens-enterprise.com Bert Deknuydt Bert.Deknuydt@esat.kuleuven.ac.be Bert Wesarg bert.wesarg@googlemail.com Bill Brelsford wb@k2di.net diff --git a/src/chmod.c b/src/chmod.c index 98db5fa..6fec84a 100644 --- a/src/chmod.c +++ b/src/chmod.c @@ -137,10 +137,11 @@ mode_changed (char const *file, mode_t old_mode, mode_t new_mode) CHANGED describes what (if anything) has happened. */ static void -describe_change (const char *file, mode_t mode, +describe_change (const char *file, mode_t old_mode, mode_t mode, enum Change_status changed) { char perms[12]; /* "-rwxrwxrwx" ls-style modes. */ + char old_perms[12]; const char *fmt; if (changed == CH_NOT_APPLIED) @@ -152,21 +153,28 @@ describe_change (const char *file, mode_t mode, strmode (mode, perms); perms[10] = '\0'; /* Remove trailing space. */ + + strmode (old_mode, old_perms); + old_perms[10] = '\0'; /* Remove trailing space. */ + switch (changed) { case CH_SUCCEEDED: - fmt = _("mode of %s changed to %04lo (%s)\n"); + fmt = _("mode of %s changed from %04lo (%s) to %04lo (%s)\n"); break; case CH_FAILED: - fmt = _("failed to change mode of %s to %04lo (%s)\n"); + fmt = _("failed to change mode of %s from %04lo (%s) to %04lo (%s)\n"); break; case CH_NO_CHANGE_REQUESTED: fmt = _("mode of %s retained as %04lo (%s)\n"); - break; + printf (fmt, quote (file), + (unsigned long int) (mode & CHMOD_MODE_BITS), &perms[1]); + return; default: abort (); } printf (fmt, quote (file), + (unsigned long int) (old_mode & CHMOD_MODE_BITS), &old_perms[1], (unsigned long int) (mode & CHMOD_MODE_BITS), &perms[1]); } @@ -284,7 +292,7 @@ process_file (FTS *fts, FTSENT *ent) : !chmod_succeeded ? CH_NOT_APPLIED : !changed ? CH_NO_CHANGE_REQUESTED : CH_SUCCEEDED); - describe_change (file_full_name, new_mode, ch_status); + describe_change (file_full_name, old_mode, new_mode, ch_status); } } diff --git a/tests/chmod/c-option b/tests/chmod/c-option index 14d89b6..d80038c 100755 --- a/tests/chmod/c-option +++ b/tests/chmod/c-option @@ -33,8 +33,8 @@ chmod -c g=rwx $file > empty || fail=1 test -s empty && fail=1 case "`cat out`" in - "mode of \`f' changed to 0774 "?rwxrwxr--?) ;; - *) fail=1 ;; + "mode of \`f' changed from 0744 "?rwxr--r--?" to 0774 "?rwxrwxr--?) ;; + *) cat out; fail=1 ;; esac Exit $fail -- 2.7.4