diff options
-rwxr-xr-x | tests/rm.test | 10 | ||||
-rw-r--r-- | toys/posix/rm.c | 13 |
2 files changed, 20 insertions, 3 deletions
diff --git a/tests/rm.test b/tests/rm.test index 95710c82..42727442 100755 --- a/tests/rm.test +++ b/tests/rm.test @@ -48,3 +48,13 @@ mkdir -p one && touch one/two && chmod 000 one SKIP_HOST=1 testing "-rf 000 dir" \ "rm -rf one 2>/dev/null && [ ! -e one ] && echo yes" "yes\n" "" "" chmod 777 one 2>/dev/null ; rm -rf one + +mkdir -p d1 +touch d1/f1.txt d1/f2.txt +testing "-rv dir" \ + "rm -rv d1" "rm 'd1/f1.txt'\nrm 'd1/f2.txt'\nrmdir 'd1'\n" "" "" +rm -rf d1 + +touch "'" +testing "-v \\'" "rm -v \\'" "rm '''\n" "" "" # TODO: coreutils escapes quote +rm -f \' diff --git a/toys/posix/rm.c b/toys/posix/rm.c index 608e1ca1..6c64e13f 100644 --- a/toys/posix/rm.c +++ b/toys/posix/rm.c @@ -4,19 +4,20 @@ * * See http://pubs.opengroup.org/onlinepubs/9699919799/utilities/rm.html -USE_RM(NEWTOY(rm, "fiRr[-fi]", TOYFLAG_BIN)) +USE_RM(NEWTOY(rm, "fiRrv[-fi]", TOYFLAG_BIN)) config RM bool "rm" default y help - usage: rm [-fiRr] FILE... + usage: rm [-fiRrv] FILE... Remove each argument from the filesystem. -f Force: remove without confirmation, no error if it doesn't exist -i Interactive: prompt for confirmation -rR Recursive: remove directory contents + -v Verbose */ #define FOR_rm @@ -68,7 +69,13 @@ static int do_rm(struct dirtree *try) } skip: - if (unlinkat(fd, try->name, using)) { + if (!unlinkat(fd, try->name, using)) { + if (flags & FLAG_v) { + char *s = dirtree_path(try, 0); + printf("%s%s '%s'\n", toys.which->name, dir ? "dir" : "", s); + free(s); + } + } else { if (!dir || try->symlink != (char *)2) perror_msg_raw(try->name); nodelete: if (try->parent) try->parent->symlink = (char *)2; |