diff options
author | Pádraig Brady <P@draigBrady.com> | 2011-05-27 23:07:08 +0100 |
---|---|---|
committer | Pádraig Brady <P@draigBrady.com> | 2011-05-27 23:21:46 +0100 |
commit | 54a49f22ae158470142f92e00af69fbb3b774699 (patch) | |
tree | f330d996e954f5a02f6a62075b9e94b4dd97a7bc | |
parent | 6b282e7510ca8dcbb44f8402b52ba8c8b1d01b80 (diff) | |
download | coreutils-54a49f22ae158470142f92e00af69fbb3b774699.tar.xz |
chown,chgrp: output the original ownership in -v messages
* src/chown-core.c (describe_change): Output the
original owner if possible.
(user_group_str): Handle the case when neither
owner or group are passed.
* NEWS: Mention the change in behavior.
-rw-r--r-- | NEWS | 3 | ||||
-rw-r--r-- | src/chown-core.c | 36 |
2 files changed, 27 insertions, 12 deletions
@@ -16,7 +16,8 @@ GNU coreutils NEWS -*- outline -*- ** Changes in behavior - chmod -v and -c now output the original mode in the messages. + chmod, chown and chgrp now output the original attributes in messages, + when -v or -c specified. ** New features diff --git a/src/chown-core.c b/src/chown-core.c index e72aa33b1..55f8a2d36 100644 --- a/src/chown-core.c +++ b/src/chown-core.c @@ -107,7 +107,7 @@ uid_to_name (uid_t uid) static char * user_group_str (char const *user, char const *group) { - char *spec; + char *spec = NULL; if (user) { @@ -121,7 +121,7 @@ user_group_str (char const *user, char const *group) spec = xstrdup (user); } } - else + else if (group) { spec = xstrdup (group); } @@ -139,6 +139,7 @@ describe_change (const char *file, enum Change_status changed, char const *user, char const *group) { const char *fmt; + char *old_spec; char *spec; if (changed == CH_NOT_APPLIED) @@ -148,32 +149,45 @@ describe_change (const char *file, enum Change_status changed, return; } + spec = user_group_str (user, group); + old_spec = user_group_str (user ? old_user : NULL, group ? old_group : NULL); + switch (changed) { case CH_SUCCEEDED: - fmt = (user ? _("changed ownership of %s to %s\n") - : group ? _("changed group of %s to %s\n") + fmt = (user ? _("changed ownership of %s from %s to %s\n") + : group ? _("changed group of %s from %s to %s\n") : _("no change to ownership of %s\n")); - spec = user_group_str (user, group); break; case CH_FAILED: - fmt = (user ? _("failed to change ownership of %s to %s\n") - : group ? _("failed to change group of %s to %s\n") - : _("failed to change ownership of %s\n")); - spec = user_group_str (user, group); + if (old_spec) + { + fmt = (user ? _("failed to change ownership of %s from %s to %s\n") + : group ? _("failed to change group of %s from %s to %s\n") + : _("failed to change ownership of %s\n")); + } + else + { + fmt = (user ? _("failed to change ownership of %s to %s\n") + : group ? _("failed to change group of %s to %s\n") + : _("failed to change ownership of %s\n")); + free (old_spec); + old_spec = spec; + spec = NULL; + } break; case CH_NO_CHANGE_REQUESTED: fmt = (user ? _("ownership of %s retained as %s\n") : group ? _("group of %s retained as %s\n") : _("ownership of %s retained\n")); - spec = user_group_str (user ? old_user : NULL, group ? old_group : NULL); break; default: abort (); } - printf (fmt, quote (file), spec); + printf (fmt, quote (file), old_spec, spec); + free (old_spec); free (spec); } |