4
0
mirror of git://sourceware.org/git/newlib-cygwin.git synced 2025-02-08 18:19:08 +08:00

Cygwin: chown: make sure ctime gets updated when necessary

Following POSIX, ensure that ctime is updated if chown succeeds,
unless the new owner is specified as (uid_t)-1 and the new group is
specified as (gid_t)-1.  Previously, ctime was unchanged whenever the
owner and group were both unchanged.

Aside from POSIX compliance, this fix makes gnulib report that chown
works on Cygwin.  This improves the efficiency of packages like GNU
tar that use gnulib's chown module.  Previously such packages would
use a gnulib replacement for chown on Cygwin.
This commit is contained in:
Ken Brown 2021-01-25 21:05:37 -05:00
parent 7425218eee
commit 7edc74562d

View File

@ -887,15 +887,18 @@ fhandler_disk_file::fchown (uid_t uid, gid_t gid)
aclp, MAX_ACL_ENTRIES)) < 0) aclp, MAX_ACL_ENTRIES)) < 0)
goto out; goto out;
if (uid == ILLEGAL_UID) /* According to POSIX, chown can be a no-op if uid is (uid_t)-1 and
uid = old_uid; gid is (gid_t)-1. Otherwise, even if uid and gid are unchanged,
if (gid == ILLEGAL_GID) we must ensure that ctime is updated. */
gid = old_gid; if (uid == ILLEGAL_UID && gid == ILLEGAL_GID)
if (uid == old_uid && gid == old_gid)
{ {
ret = 0; ret = 0;
goto out; goto out;
} }
if (uid == ILLEGAL_UID)
uid = old_uid;
else if (gid == ILLEGAL_GID)
gid = old_gid;
/* Windows ACLs can contain permissions for one group, while being owned by /* Windows ACLs can contain permissions for one group, while being owned by
another user/group. The permission bits returned above are pretty much another user/group. The permission bits returned above are pretty much