public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* [PATCH] Cygwin: chown: make sure ctime gets updated when necessary
@ 2021-01-25 17:24 Ken Brown
  2021-01-25 18:57 ` Corinna Vinschen
  0 siblings, 1 reply; 4+ messages in thread
From: Ken Brown @ 2021-01-25 17:24 UTC (permalink / raw)
  To: cygwin-patches

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.
---
 winsup/cygwin/fhandler_disk_file.cc | 10 +++++++++-
 1 file changed, 9 insertions(+), 1 deletion(-)

diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc
index 07f9c513a..72d259579 100644
--- a/winsup/cygwin/fhandler_disk_file.cc
+++ b/winsup/cygwin/fhandler_disk_file.cc
@@ -863,6 +863,7 @@ fhandler_disk_file::fchown (uid_t uid, gid_t gid)
   tmp_pathbuf tp;
   aclent_t *aclp;
   int nentries;
+  bool noop = true;
 
   if (!pc.has_acls ())
     {
@@ -887,11 +888,18 @@ fhandler_disk_file::fchown (uid_t uid, gid_t gid)
 				    aclp, MAX_ACL_ENTRIES)) < 0)
     goto out;
 
+  /* 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)
     uid = old_uid;
+  else
+    noop = false;
   if (gid == ILLEGAL_GID)
     gid = old_gid;
-  if (uid == old_uid && gid == old_gid)
+  else
+    noop = false;
+  if (noop)
     {
       ret = 0;
       goto out;
-- 
2.30.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Cygwin: chown: make sure ctime gets updated when necessary
  2021-01-25 17:24 [PATCH] Cygwin: chown: make sure ctime gets updated when necessary Ken Brown
@ 2021-01-25 18:57 ` Corinna Vinschen
  2021-01-25 19:16   ` Ken Brown
  0 siblings, 1 reply; 4+ messages in thread
From: Corinna Vinschen @ 2021-01-25 18:57 UTC (permalink / raw)
  To: cygwin-patches

On Jan 25 12:24, Ken Brown via Cygwin-patches wrote:
> 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.
> ---
>  winsup/cygwin/fhandler_disk_file.cc | 10 +++++++++-
>  1 file changed, 9 insertions(+), 1 deletion(-)
> 
> diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc
> index 07f9c513a..72d259579 100644
> --- a/winsup/cygwin/fhandler_disk_file.cc
> +++ b/winsup/cygwin/fhandler_disk_file.cc
> @@ -863,6 +863,7 @@ fhandler_disk_file::fchown (uid_t uid, gid_t gid)
>    tmp_pathbuf tp;
>    aclent_t *aclp;
>    int nentries;
> +  bool noop = true;
>  
>    if (!pc.has_acls ())
>      {
> @@ -887,11 +888,18 @@ fhandler_disk_file::fchown (uid_t uid, gid_t gid)
>  				    aclp, MAX_ACL_ENTRIES)) < 0)
>      goto out;
>  
> +  /* 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)
>      uid = old_uid;
> +  else
> +    noop = false;
>    if (gid == ILLEGAL_GID)
>      gid = old_gid;
> -  if (uid == old_uid && gid == old_gid)

Basically ok, but why not just

     if (uid == ILLEGAL_UID && gid == ILLEGAL_GID)

instead of the noop var?


Corinna

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Cygwin: chown: make sure ctime gets updated when necessary
  2021-01-25 18:57 ` Corinna Vinschen
@ 2021-01-25 19:16   ` Ken Brown
  2021-01-26 12:16     ` Corinna Vinschen
  0 siblings, 1 reply; 4+ messages in thread
From: Ken Brown @ 2021-01-25 19:16 UTC (permalink / raw)
  To: cygwin-patches

On 1/25/2021 1:57 PM, Corinna Vinschen via Cygwin-patches wrote:
> On Jan 25 12:24, Ken Brown via Cygwin-patches wrote:
>> 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.
>> ---
>>   winsup/cygwin/fhandler_disk_file.cc | 10 +++++++++-
>>   1 file changed, 9 insertions(+), 1 deletion(-)
>>
>> diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc
>> index 07f9c513a..72d259579 100644
>> --- a/winsup/cygwin/fhandler_disk_file.cc
>> +++ b/winsup/cygwin/fhandler_disk_file.cc
>> @@ -863,6 +863,7 @@ fhandler_disk_file::fchown (uid_t uid, gid_t gid)
>>     tmp_pathbuf tp;
>>     aclent_t *aclp;
>>     int nentries;
>> +  bool noop = true;
>>   
>>     if (!pc.has_acls ())
>>       {
>> @@ -887,11 +888,18 @@ fhandler_disk_file::fchown (uid_t uid, gid_t gid)
>>   				    aclp, MAX_ACL_ENTRIES)) < 0)
>>       goto out;
>>   
>> +  /* 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)
>>       uid = old_uid;
>> +  else
>> +    noop = false;
>>     if (gid == ILLEGAL_GID)
>>       gid = old_gid;
>> -  if (uid == old_uid && gid == old_gid)
> 
> Basically ok, but why not just
> 
>       if (uid == ILLEGAL_UID && gid == ILLEGAL_GID)
> 
> instead of the noop var?

I went back and forth on that.  Following your suggestion, the code looks like this:

   if (uid == ILLEGAL_UID && gid == ILLEGAL_GID)
     {
       ret = 0;
       goto out;
     }
   if (uid == ILLEGAL_UID)
     uid = old_uid;
   if (gid == ILLEGAL_GID)
     gid = old_gid;

I was trying to avoid checking uid == ILLEGAL_UID and gid == ILLEGAL_GID twice. 
  But on second thought, it's probably silly to worry about that.  The code is 
cleaner without the noop variable.

Thanks.

Ken

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] Cygwin: chown: make sure ctime gets updated when necessary
  2021-01-25 19:16   ` Ken Brown
@ 2021-01-26 12:16     ` Corinna Vinschen
  0 siblings, 0 replies; 4+ messages in thread
From: Corinna Vinschen @ 2021-01-26 12:16 UTC (permalink / raw)
  To: cygwin-patches

On Jan 25 14:16, Ken Brown via Cygwin-patches wrote:
> On 1/25/2021 1:57 PM, Corinna Vinschen via Cygwin-patches wrote:
> > On Jan 25 12:24, Ken Brown via Cygwin-patches wrote:
> > > 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.
> > > ---
> > >   winsup/cygwin/fhandler_disk_file.cc | 10 +++++++++-
> > >   1 file changed, 9 insertions(+), 1 deletion(-)
> > > 
> > > diff --git a/winsup/cygwin/fhandler_disk_file.cc b/winsup/cygwin/fhandler_disk_file.cc
> > > index 07f9c513a..72d259579 100644
> > > --- a/winsup/cygwin/fhandler_disk_file.cc
> > > +++ b/winsup/cygwin/fhandler_disk_file.cc
> > > @@ -863,6 +863,7 @@ fhandler_disk_file::fchown (uid_t uid, gid_t gid)
> > >     tmp_pathbuf tp;
> > >     aclent_t *aclp;
> > >     int nentries;
> > > +  bool noop = true;
> > >     if (!pc.has_acls ())
> > >       {
> > > @@ -887,11 +888,18 @@ fhandler_disk_file::fchown (uid_t uid, gid_t gid)
> > >   				    aclp, MAX_ACL_ENTRIES)) < 0)
> > >       goto out;
> > > +  /* 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)
> > >       uid = old_uid;
> > > +  else
> > > +    noop = false;
> > >     if (gid == ILLEGAL_GID)
> > >       gid = old_gid;
> > > -  if (uid == old_uid && gid == old_gid)
> > 
> > Basically ok, but why not just
> > 
> >       if (uid == ILLEGAL_UID && gid == ILLEGAL_GID)
> > 
> > instead of the noop var?
> 
> I went back and forth on that.  Following your suggestion, the code looks like this:
> 
>   if (uid == ILLEGAL_UID && gid == ILLEGAL_GID)
>     {
>       ret = 0;
>       goto out;
>     }
>   if (uid == ILLEGAL_UID)
>     uid = old_uid;
>   if (gid == ILLEGAL_GID)
>     gid = old_gid;
> 
> I was trying to avoid checking uid == ILLEGAL_UID and gid == ILLEGAL_GID
> twice.  But on second thought, it's probably silly to worry about that.  The
> code is cleaner without the noop variable.

Both is ok with me, whatever you think more spiffy here.


Thanks,
Corinna

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-01-26 12:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-25 17:24 [PATCH] Cygwin: chown: make sure ctime gets updated when necessary Ken Brown
2021-01-25 18:57 ` Corinna Vinschen
2021-01-25 19:16   ` Ken Brown
2021-01-26 12:16     ` Corinna Vinschen

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).