summaryrefslogtreecommitdiff
path: root/src/cp.c
diff options
context:
space:
mode:
authorLasse Collin <lasse.collin@tukaani.org>2007-11-10 01:07:37 +0200
committerJim Meyering <meyering@redhat.com>2007-11-24 15:06:43 +0100
commitcbc06bb6390c1ad4a227723078ecd7f7689251cc (patch)
treee15224e4c5e1cdbb6817b2ae74e22587b6882099 /src/cp.c
parentad8fbe0dd2c77fe41457311f91bfcf49b0bf7616 (diff)
downloadcoreutils-cbc06bb6390c1ad4a227723078ecd7f7689251cc.tar.xz
"cp -p" tries to preserve GID even if preserving the UID fails.
* NEWS: Mention this new feature. * src/copy.c (set_owner): Try to preserve just the GID, when initial fchown/lchown fails. * src/cp.c (re_protect): Likewise.
Diffstat (limited to 'src/cp.c')
-rw-r--r--src/cp.c19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/cp.c b/src/cp.c
index 5859f8c1d..599498dd7 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -316,13 +316,18 @@ re_protect (char const *const_dst_name, size_t src_offset,
if (x->preserve_ownership)
{
- if (lchown (dst_name, p->st.st_uid, p->st.st_gid) != 0
- && ! chown_failure_ok (x))
- {
- error (0, errno, _("failed to preserve ownership for %s"),
- quote (dst_name));
- return false;
- }
+ if (lchown (dst_name, p->st.st_uid, p->st.st_gid) != 0)
+ {
+ if (! chown_failure_ok (x))
+ {
+ error (0, errno, _("failed to preserve ownership for %s"),
+ quote (dst_name));
+ return false;
+ }
+ /* Failing to preserve ownership is OK. Still, try to preserve
+ the group, but ignore the possible error. */
+ (void) lchown (dst_name, -1, p->st.st_gid);
+ }
}
if (x->preserve_mode)