zsh-workers
 help / color / mirror / code / Atom feed
From: Matthew Martin <phy1729@gmail.com>
To: zsh-workers@zsh.org
Subject: [PATCH] rm: Accept -R as equivalent to -r
Date: Wed, 20 Mar 2019 23:13:29 -0500	[thread overview]
Message-ID: <20190321041326.GA58005@CptOrmolo.darkstar> (raw)

While updating the completers for builtins, I ran across that rm doesn't
support -R while it does support -r. POSIX defines -R and -r as
equivalent. I think it's easier to just support -R in the builtin rm
than fix the completer.

- Matthew Martin

---
 Doc/Zsh/mod_files.yo | 14 +++++++-------
 Src/Modules/files.c  |  7 ++++---
 2 files changed, 11 insertions(+), 10 deletions(-)

diff --git a/Doc/Zsh/mod_files.yo b/Doc/Zsh/mod_files.yo
index 3cf7b61e3..9f9634c86 100644
--- a/Doc/Zsh/mod_files.yo
+++ b/Doc/Zsh/mod_files.yo
@@ -144,15 +144,15 @@ fall back on copying and removing files; if this behaviour is desired,
 use tt(cp) and tt(rm) manually.  This may change in a future version.
 )
 findex(rm)
-item(tt(rm) [ tt(-dfirs) ] var(filename) ...)(
+item(tt(rm) [ tt(-dfiRrs) ] var(filename) ...)(
 Removes files and directories specified.
 
-Normally, tt(rm) will not remove directories (except with the tt(-r)
-option).  The tt(-d) option causes tt(rm) to try removing directories
+Normally, tt(rm) will not remove directories (except with the tt(-R) or tt(-r)
+options).  The tt(-d) option causes tt(rm) to try removing directories
 with tt(unlink) (see manref(unlink)(2)), the same method used for files.
 Typically only the super-user can actually succeed in unlinking
 directories in this way.
-tt(-d) takes precedence over tt(-r).
+tt(-d) takes precedence over tt(-R) and tt(-r).
 
 By default, the user will be queried before removing any file
 that the user cannot write to, but writable files will be silently
@@ -162,9 +162,9 @@ any files.  The tt(-f) option causes files to be
 silently deleted, without querying, and suppresses all error indications.
 tt(-f) takes precedence.
 
-The tt(-r) option causes tt(rm) to recursively descend into directories,
-deleting all files in the directory before removing the directory with
-the tt(rmdir) system call (see manref(rmdir)(2)).
+The tt(-R) and tt(-r) options cause tt(rm) to recursively descend into
+directories, deleting all files in the directory before removing the directory
+with the tt(rmdir) system call (see manref(rmdir)(2)).
 
 The tt(-s) option is a zsh extension to tt(rm) functionality.  It enables
 paranoid behaviour, intended to avoid common security problems involving
diff --git a/Src/Modules/files.c b/Src/Modules/files.c
index 85764d55e..6d20e38a8 100644
--- a/Src/Modules/files.c
+++ b/Src/Modules/files.c
@@ -613,7 +613,8 @@ bin_rm(char *nam, char **args, Options ops, UNUSED(int func))
     rmm.opt_interact = OPT_ISSET(ops,'i') && !OPT_ISSET(ops,'f');
     rmm.opt_unlinkdir = OPT_ISSET(ops,'d');
     err = recursivecmd(nam, OPT_ISSET(ops,'f'), 
-		       OPT_ISSET(ops,'r') && !OPT_ISSET(ops,'d'),
+		       !OPT_ISSET(ops,'d') && (OPT_ISSET(ops,'R') ||
+		                               OPT_ISSET(ops,'r')),
 		       OPT_ISSET(ops,'s'),
 	args, recurse_donothing, rm_dirpost, rm_leaf, &rmm);
     return OPT_ISSET(ops,'f') ? 0 : err;
@@ -798,7 +799,7 @@ static struct builtin bintab[] = {
     BUILTIN("ln",    0, bin_ln,    1, -1, BIN_LN,    LN_OPTS, NULL),
     BUILTIN("mkdir", 0, bin_mkdir, 1, -1, 0,         "pm:",   NULL),
     BUILTIN("mv",    0, bin_ln,    2, -1, BIN_MV,    "fi",    NULL),
-    BUILTIN("rm",    0, bin_rm,    1, -1, 0,         "dfirs", NULL),
+    BUILTIN("rm",    0, bin_rm,    1, -1, 0,         "dfiRrs", NULL),
     BUILTIN("rmdir", 0, bin_rmdir, 1, -1, 0,         NULL,    NULL),
     BUILTIN("sync",  0, bin_sync,  0,  0, 0,         NULL,    NULL),
     /* The "safe" zsh-only names */
@@ -808,7 +809,7 @@ static struct builtin bintab[] = {
     BUILTIN("zf_ln",    0, bin_ln,    1, -1, BIN_LN,    LN_OPTS, NULL),
     BUILTIN("zf_mkdir", 0, bin_mkdir, 1, -1, 0,         "pm:",   NULL),
     BUILTIN("zf_mv",    0, bin_ln,    2, -1, BIN_MV,    "fi",    NULL),
-    BUILTIN("zf_rm",    0, bin_rm,    1, -1, 0,         "dfirs", NULL),
+    BUILTIN("zf_rm",    0, bin_rm,    1, -1, 0,         "dfiRrs", NULL),
     BUILTIN("zf_rmdir", 0, bin_rmdir, 1, -1, 0,         NULL,    NULL),
     BUILTIN("zf_sync",  0, bin_sync,  0,  0, 0,         NULL,    NULL),
 
-- 
2.21.0


                 reply	other threads:[~2019-03-21  4:14 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=20190321041326.GA58005@CptOrmolo.darkstar \
    --to=phy1729@gmail.com \
    --cc=zsh-workers@zsh.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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 NNTP newsgroup(s).