* 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.
+2007-11-24 Jim Meyering <meyering@redhat.com>
+
+ "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.
+
2007-11-23 Jim Meyering <meyering@redhat.com>
* src/runcon.c (main): Remove unused parameter, "envp".
Add SELinux support (FIXME: add details here)
+ cp -p tries to preserve the GID of a file even if preserving the UID
+ is not possible.
+
uniq accepts a new option: --zero-terminated (-z). As with the sort
option of the same name, this makes uniq consume and produce
NUL-terminated lines rather than newline-terminated lines.
safety prefer lchown if the system supports it since no
symbolic links should be involved. DEST_DESC must
refer to the same file as DEST_NAME if defined.
- Return 1 if the syscall succeeds, 0 if it fails but it's OK
+ Upon failure to set both UID and GID, try to set only the GID.
+ Return 1 if the initial syscall succeeds, 0 if it fails but it's OK
not to preserve ownership, -1 otherwise. */
static int
{
if (fchown (dest_desc, uid, gid) == 0)
return 1;
+ if (errno == EPERM || errno == EINVAL)
+ {
+ /* We've failed to set *both*. Now, try to set just the group
+ ID, but ignore any failure here, and don't change errno. */
+ int saved_errno = errno;
+ (void) fchown (dest_desc, -1, gid);
+ errno = saved_errno;
+ }
}
else
{
if (lchown (dst_name, uid, gid) == 0)
return 1;
+ if (errno == EPERM || errno == EINVAL)
+ {
+ /* We've failed to set *both*. Now, try to set just the group
+ ID, but ignore any failure here, and don't change errno. */
+ int saved_errno = errno;
+ (void) lchown (dst_name, -1, gid);
+ errno = saved_errno;
+ }
}
if (! chown_failure_ok (x))
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)