diff options
author | Lasse Collin <lasse.collin@tukaani.org> | 2007-11-10 01:07:37 +0200 |
---|---|---|
committer | Jim Meyering <meyering@redhat.com> | 2007-11-24 15:06:43 +0100 |
commit | cbc06bb6390c1ad4a227723078ecd7f7689251cc (patch) | |
tree | e15224e4c5e1cdbb6817b2ae74e22587b6882099 /src/cp.c | |
parent | ad8fbe0dd2c77fe41457311f91bfcf49b0bf7616 (diff) | |
download | coreutils-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.c | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -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) |