[coreutils/f16] output the correct ownership in chown -v (upstream bug #10636)
Kamil Dudka
kdudka at fedoraproject.org
Sun Jan 29 13:45:56 UTC 2012
commit a18bb6f59f3fb832340374393c6c01efed34f2f7
Author: Kamil Dudka <kdudka at redhat.com>
Date: Sun Jan 29 14:34:54 2012 +0100
output the correct ownership in chown -v (upstream bug #10636)
coreutils-8.12-chown.patch | 164 ++++++++++++++++++++++++++++++++++++++++++++
coreutils.spec | 9 ++-
2 files changed, 171 insertions(+), 2 deletions(-)
---
diff --git a/coreutils-8.12-chown.patch b/coreutils-8.12-chown.patch
new file mode 100644
index 0000000..679c949
--- /dev/null
+++ b/coreutils-8.12-chown.patch
@@ -0,0 +1,164 @@
+From 92625246f6c9614be5780a04eb227d6519becef5 Mon Sep 17 00:00:00 2001
+From: =?UTF-8?q?P=C3=A1draig=20Brady?= <P at draigBrady.com>
+Date: Thu, 26 May 2011 11:15:11 +0100
+Subject: [PATCH] chown,chgrp: output the correct ownership in -v messages
+
+* src/chown_core.c (describe_change): Accept the ownership of
+the original file and output that when not changing.
+This is significant when --from is specified as then
+the original and specified ownership may be different.
+(user_group_str): A new helper function refactored from
+describe_change().
+(change_file_owner): Pass the original user and group
+strings to describe_change().
+* test/chown/basic: Add a test case.
+
+Signed-off-by: Kamil Dudka <kdudka at redhat.com>
+---
+ src/chown-core.c | 59 ++++++++++++++++++++++++++++++++++------------------
+ tests/chown/basic | 11 +++++++++
+ 2 files changed, 49 insertions(+), 21 deletions(-)
+
+diff --git a/src/chown-core.c b/src/chown-core.c
+index 82f7341..e72aa33 100644
+--- a/src/chown-core.c
++++ b/src/chown-core.c
+@@ -102,17 +102,44 @@ uid_to_name (uid_t uid)
+ : umaxtostr (uid, buf));
+ }
+
++/* Allocate a string representing USER and GROUP. */
++
++static char *
++user_group_str (char const *user, char const *group)
++{
++ char *spec;
++
++ if (user)
++ {
++ if (group)
++ {
++ spec = xmalloc (strlen (user) + 1 + strlen (group) + 1);
++ stpcpy (stpcpy (stpcpy (spec, user), ":"), group);
++ }
++ else
++ {
++ spec = xstrdup (user);
++ }
++ }
++ else
++ {
++ spec = xstrdup (group);
++ }
++
++ return spec;
++}
++
+ /* Tell the user how/if the user and group of FILE have been changed.
+ If USER is NULL, give the group-oriented messages.
+ CHANGED describes what (if anything) has happened. */
+
+ static void
+ describe_change (const char *file, enum Change_status changed,
++ char const *old_user, char const *old_group,
+ char const *user, char const *group)
+ {
+ const char *fmt;
+- char const *spec;
+- char *spec_allocated = NULL;
++ char *spec;
+
+ if (changed == CH_NOT_APPLIED)
+ {
+@@ -121,40 +148,25 @@ describe_change (const char *file, enum Change_status changed,
+ return;
+ }
+
+- if (user)
+- {
+- if (group)
+- {
+- spec_allocated = xmalloc (strlen (user) + 1 + strlen (group) + 1);
+- stpcpy (stpcpy (stpcpy (spec_allocated, user), ":"), group);
+- spec = spec_allocated;
+- }
+- else
+- {
+- spec = user;
+- }
+- }
+- else
+- {
+- spec = group;
+- }
+-
+ switch (changed)
+ {
+ case CH_SUCCEEDED:
+ fmt = (user ? _("changed ownership of %s to %s\n")
+ : group ? _("changed group of %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);
+ 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 ();
+@@ -162,7 +174,7 @@ describe_change (const char *file, enum Change_status changed,
+
+ printf (fmt, quote (file), spec);
+
+- free (spec_allocated);
++ free (spec);
+ }
+
+ /* Change the owner and/or group of the FILE to UID and/or GID (safely)
+@@ -459,8 +471,13 @@ change_file_owner (FTS *fts, FTSENT *ent,
+ : !symlink_changed ? CH_NOT_APPLIED
+ : !changed ? CH_NO_CHANGE_REQUESTED
+ : CH_SUCCEEDED);
++ char *old_usr = file_stats ? uid_to_name (file_stats->st_uid) : NULL;
++ char *old_grp = file_stats ? gid_to_name (file_stats->st_gid) : NULL;
+ describe_change (file_full_name, ch_status,
++ old_usr, old_grp,
+ chopt->user_name, chopt->group_name);
++ free (old_usr);
++ free (old_grp);
+ }
+ }
+
+diff --git a/tests/chown/basic b/tests/chown/basic
+index 0614f70..5626029 100755
+--- a/tests/chown/basic
++++ b/tests/chown/basic
+@@ -27,6 +27,17 @@ chown -R --preserve-root 0:1 f
+ # Make sure the owner and group are 0 and 1 respectively.
+ set _ `ls -n f`; shift; test "$3:$4" = 0:1 || fail=1
+
++# Make sure the correct diagnostic is output
++# Note we output a name even though an id was specified.
++chown -v --from=42 43 f > out || fail=1
++printf "ownership of \`f' retained as `id -nu`\n" > exp
++compare out exp || fail=1
++
++# Ensure diagnostics work for non existent files.
++chown -v 0 nf > out && fail=1
++printf "failed to change ownership of \`nf' to 0\n" > exp
++compare out exp || fail=1
++
+ chown --from=0:1 2:010 f || fail=1
+
+ # And now they should be 2 and 10 respectively.
+--
+1.7.1
+
diff --git a/coreutils.spec b/coreutils.spec
index 7354097..161a11c 100644
--- a/coreutils.spec
+++ b/coreutils.spec
@@ -1,7 +1,7 @@
Summary: A set of basic GNU tools commonly used in shell scripts
Name: coreutils
Version: 8.12
-Release: 4%{?dist}
+Release: 5%{?dist}
License: GPLv3+
Group: System Environment/Base
Url: http://www.gnu.org/software/coreutils/
@@ -18,6 +18,7 @@ Source202: coreutils-su-l.pamd
Source203: coreutils-runuser-l.pamd
# From upstream
+patch1: coreutils-8.12-chown.patch
# Our patches
#general patch to workaround koji build system issues
@@ -115,6 +116,7 @@ Libraries for coreutils package.
%setup -q
# From upstream
+%patch1 -p1 -b .chown
# Our patches
%patch100 -p1 -b .configure
@@ -145,7 +147,7 @@ Libraries for coreutils package.
%patch950 -p1 -b .selinux
%patch951 -p1 -b .selinuxman
-chmod a+x tests/misc/sort-mb-tests tests/df/direct || :
+chmod a+x tests/misc/sort-mb-tests tests/df/direct test/chown/basic || :
#fix typos/mistakes in localized documentation(#439410, #440056)
find ./po/ -name "*.p*" | xargs \
@@ -332,6 +334,9 @@ fi
%{_libdir}/coreutils
%changelog
+* Sun Jan 29 2012 Kamil Dudka <kdudka at redhat.com> - 8.12-5
+- output the correct ownership in chown -v (upstream bug #10636)
+
* Mon Oct 24 2011 Ondrej Vasik <ovasik at redhat.com> - 8.12-4
- require at least pam >= 1.1.3-7 (#748215)
More information about the scm-commits
mailing list