public inbox for cygwin-patches@cygwin.com
 help / color / mirror / Atom feed
* PATCH] Cygwin: utils: chattr: Allow to clear all attributes with '='.
@ 2021-05-20 21:04 Christian Franke
  2021-05-21  7:58 ` Corinna Vinschen
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Franke @ 2021-05-20 21:04 UTC (permalink / raw)
  To: cygwin-patches

[-- Attachment #1: Type: text/plain, Size: 81 bytes --]

'chattr = FILE' is shorter that 'chattr -rhsat... FILE' :-)

Regards,
Christian


[-- Attachment #2: 0001-Cygwin-utils-chattr-Allow-to-clear-all-attributes-wi.patch --]
[-- Type: text/plain, Size: 1810 bytes --]

From 41c1a9648d46835354167a7e024e7191014e1370 Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Thu, 20 May 2021 22:52:28 +0200
Subject: [PATCH] Cygwin: utils: chattr: Allow to clear all attributes with
 '='.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
---
 winsup/utils/chattr.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/winsup/utils/chattr.c b/winsup/utils/chattr.c
index 6942e11b0..b7beff276 100644
--- a/winsup/utils/chattr.c
+++ b/winsup/utils/chattr.c
@@ -23,6 +23,7 @@ details. */
 
 int Ropt, Vopt, fopt;
 uint64_t add, del, set;
+int set_used;
 
 struct option longopts[] = {
   { "recursive", no_argument, NULL, 'R' },
@@ -83,6 +84,7 @@ get_flags (const char *opt)
       break;
     case '=':
       mode = &set;
+      set_used = 1;
       break;
     default:
       return 1;
@@ -104,10 +106,10 @@ int
 sanity_check ()
 {
   int ret = -1;
-  if (!set && !add && !del)
+  if (!set_used && !add && !del)
     fprintf (stderr, "%s: Must use at least one of =, + or -\n",
 	     program_invocation_short_name);
-  else if (set && (add | del))
+  else if (set_used && (add | del))
     fprintf (stderr, "%s: = is incompatible with + and -\n",
 	     program_invocation_short_name);
   else if ((add & del) != 0)
@@ -138,7 +140,7 @@ chattr (const char *path)
 	       program_invocation_short_name, strerror (errno), path);
       return 1;
     }
-  if (set)
+  if (set_used)
     newflags = set;
   else
     {
@@ -313,7 +315,7 @@ next:
       opt = strchr ("+-=", argv[optind][0]);
       if (!opt)
 	break;
-      if (argv[optind][1] == '\0' || get_flags (argv[optind]))
+      if ((*opt != '=' && argv[optind][1] == '\0') || get_flags (argv[optind]))
 	usage (stderr);
       ++optind;
     }
-- 
2.31.1


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

* Re: PATCH] Cygwin: utils: chattr: Allow to clear all attributes with '='.
  2021-05-20 21:04 PATCH] Cygwin: utils: chattr: Allow to clear all attributes with '=' Christian Franke
@ 2021-05-21  7:58 ` Corinna Vinschen
  2021-05-21 10:07   ` Christian Franke
  0 siblings, 1 reply; 4+ messages in thread
From: Corinna Vinschen @ 2021-05-21  7:58 UTC (permalink / raw)
  To: cygwin-patches

On May 20 23:04, Christian Franke wrote:
> 'chattr = FILE' is shorter that 'chattr -rhsat... FILE' :-)

That's ok, but it might be worth to add this to the docs, too :)


Thanks,
Corinna

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

* Re: PATCH] Cygwin: utils: chattr: Allow to clear all attributes with '='.
  2021-05-21  7:58 ` Corinna Vinschen
@ 2021-05-21 10:07   ` Christian Franke
  2021-05-21 10:57     ` Corinna Vinschen
  0 siblings, 1 reply; 4+ messages in thread
From: Christian Franke @ 2021-05-21 10:07 UTC (permalink / raw)
  To: cygwin-patches

[-- Attachment #1: Type: text/plain, Size: 221 bytes --]

Corinna Vinschen wrote:
> On May 20 23:04, Christian Franke wrote:
>> 'chattr = FILE' is shorter that 'chattr -rhsat... FILE' :-)
> That's ok, but it might be worth to add this to the docs, too :)

Next try attached...



[-- Attachment #2: 0001-Cygwin-utils-chattr-Allow-to-clear-all-attributes-wi.patch --]
[-- Type: text/plain, Size: 3152 bytes --]

From 6ba0ab483f9417631a1592210141aefaff50ebc1 Mon Sep 17 00:00:00 2001
From: Christian Franke <christian.franke@t-online.de>
Date: Fri, 21 May 2021 11:44:32 +0200
Subject: [PATCH] Cygwin: utils: chattr: Allow to clear all attributes with
 '='.

Signed-off-by: Christian Franke <christian.franke@t-online.de>
---
 winsup/doc/utils.xml  |  5 +++--
 winsup/utils/chattr.c | 13 ++++++++-----
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/winsup/doc/utils.xml b/winsup/doc/utils.xml
index 69611b954..0671a7b4d 100644
--- a/winsup/doc/utils.xml
+++ b/winsup/doc/utils.xml
@@ -53,9 +53,10 @@ chattr [-RVfHv] [+-=mode]... [file]...
 
     <para>The format of 'mode' is {+-=}[acCehnrsSt]</para>
 
-    <para>The  operator '+' causes the selected attributes to be added to the
+    <para>The operator '+' causes the selected attributes to be added to the
       existing attributes of the files; '-' causes them to be removed; and
-      '=' causes them to be the only attributes that the files have.</para>
+      '=' causes them to be the only attributes that the files have.
+      A single '=' causes all attributes to be removed.</para>
 
     <para>Supported attributes:</para>
 
diff --git a/winsup/utils/chattr.c b/winsup/utils/chattr.c
index 6942e11b0..e3ab1fba8 100644
--- a/winsup/utils/chattr.c
+++ b/winsup/utils/chattr.c
@@ -23,6 +23,7 @@ details. */
 
 int Ropt, Vopt, fopt;
 uint64_t add, del, set;
+int set_used;
 
 struct option longopts[] = {
   { "recursive", no_argument, NULL, 'R' },
@@ -83,6 +84,7 @@ get_flags (const char *opt)
       break;
     case '=':
       mode = &set;
+      set_used = 1;
       break;
     default:
       return 1;
@@ -104,10 +106,10 @@ int
 sanity_check ()
 {
   int ret = -1;
-  if (!set && !add && !del)
+  if (!set_used && !add && !del)
     fprintf (stderr, "%s: Must use at least one of =, + or -\n",
 	     program_invocation_short_name);
-  else if (set && (add | del))
+  else if (set_used && (add | del))
     fprintf (stderr, "%s: = is incompatible with + and -\n",
 	     program_invocation_short_name);
   else if ((add & del) != 0)
@@ -138,7 +140,7 @@ chattr (const char *path)
 	       program_invocation_short_name, strerror (errno), path);
       return 1;
     }
-  if (set)
+  if (set_used)
     newflags = set;
   else
     {
@@ -245,9 +247,10 @@ usage (FILE *stream)
       "\n"
       "The format of 'mode' is {+-=}[acCehnrsSt]\n"
       "\n"
-      "The  operator '+' causes the selected attributes to be added to the\n"
+      "The operator '+' causes the selected attributes to be added to the\n"
       "existing attributes of the files; '-' causes them to be removed; and\n"
       "'=' causes them to be the only attributes that the files have.\n"
+      "A single '=' causes all attributes to be removed.\n"
       "\n"
       "Supported attributes:\n"
       "\n"
@@ -313,7 +316,7 @@ next:
       opt = strchr ("+-=", argv[optind][0]);
       if (!opt)
 	break;
-      if (argv[optind][1] == '\0' || get_flags (argv[optind]))
+      if ((*opt != '=' && argv[optind][1] == '\0') || get_flags (argv[optind]))
 	usage (stderr);
       ++optind;
     }
-- 
2.31.1


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

* Re: PATCH] Cygwin: utils: chattr: Allow to clear all attributes with '='.
  2021-05-21 10:07   ` Christian Franke
@ 2021-05-21 10:57     ` Corinna Vinschen
  0 siblings, 0 replies; 4+ messages in thread
From: Corinna Vinschen @ 2021-05-21 10:57 UTC (permalink / raw)
  To: cygwin-patches

On May 21 12:07, Christian Franke wrote:
> Corinna Vinschen wrote:
> > On May 20 23:04, Christian Franke wrote:
> > > 'chattr = FILE' is shorter that 'chattr -rhsat... FILE' :-)
> > That's ok, but it might be worth to add this to the docs, too :)
> 
> Next try attached...
> 
> 

> From 6ba0ab483f9417631a1592210141aefaff50ebc1 Mon Sep 17 00:00:00 2001
> From: Christian Franke <christian.franke@t-online.de>
> Date: Fri, 21 May 2021 11:44:32 +0200
> Subject: [PATCH] Cygwin: utils: chattr: Allow to clear all attributes with
>  '='.
> 
> Signed-off-by: Christian Franke <christian.franke@t-online.de>
> ---
>  winsup/doc/utils.xml  |  5 +++--
>  winsup/utils/chattr.c | 13 ++++++++-----
>  2 files changed, 11 insertions(+), 7 deletions(-)

Pushed.


Thanks,
Corinna


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

end of thread, other threads:[~2021-05-21 10:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-20 21:04 PATCH] Cygwin: utils: chattr: Allow to clear all attributes with '=' Christian Franke
2021-05-21  7:58 ` Corinna Vinschen
2021-05-21 10:07   ` Christian Franke
2021-05-21 10:57     ` 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).