public inbox for cygwin-cvs@sourceware.org
help / color / mirror / Atom feed
From: Ken Brown <kbrown@sourceware.org>
To: cygwin-cvs@sourceware.org
Subject: [newlib-cygwin] Cygwin: chown: make sure ctime gets updated when necessary
Date: Tue, 26 Jan 2021 14:37:27 +0000 (GMT)	[thread overview]
Message-ID: <20210126143727.2E40E385DC1A@sourceware.org> (raw)

https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;h=b32f6dd40a2764aed1baec35da0a7512f3fbceb3

commit b32f6dd40a2764aed1baec35da0a7512f3fbceb3
Author: Ken Brown <kbrown@cornell.edu>
Date:   Mon Jan 25 21:05:37 2021 -0500

    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.

Diff:
---
 winsup/cygwin/fhandler_disk_file.cc | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc
index 07f9c513a..5e58688b7 100644
--- a/winsup/cygwin/fhandler_disk_file.cc
+++ b/winsup/cygwin/fhandler_disk_file.cc
@@ -887,15 +887,18 @@ fhandler_disk_file::fchown (uid_t uid, gid_t gid)
 				    aclp, MAX_ACL_ENTRIES)) < 0)
     goto out;
 
-  if (uid == ILLEGAL_UID)
-    uid = old_uid;
-  if (gid == ILLEGAL_GID)
-    gid = old_gid;
-  if (uid == old_uid && gid == old_gid)
+  /* According to POSIX, chown can be a no-op if uid is (uid_t)-1 and
+     gid is (gid_t)-1.  Otherwise, even if uid and gid are unchanged,
+     we must ensure that ctime is updated. */
+  if (uid == ILLEGAL_UID && gid == ILLEGAL_GID)
     {
       ret = 0;
       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
      another user/group.  The permission bits returned above are pretty much


                 reply	other threads:[~2021-01-26 14:37 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210126143727.2E40E385DC1A@sourceware.org \
    --to=kbrown@sourceware.org \
    --cc=cygwin-cvs@sourceware.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).