summaryrefslogtreecommitdiff
path: root/src/cp.c
diff options
context:
space:
mode:
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)