diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2022-08-16 13:52:42 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2022-08-16 13:52:42 +0000 |
commit | 46880bf01ccc0bbd1fb39187e3505b42de971db7 (patch) | |
tree | 9c22ca1a3c16c286ddf1f8aee931a3abb0232d36 | |
parent | 1c86202c0ebb7c34b457a7e50672e286ed0c14b7 (diff) |
-v option should only act based upon syscall success. test case is
"rm -rfv nonexistent". problem spotted by Alfred Morgan
ok millert
-rw-r--r-- | bin/rm/rm.c | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/bin/rm/rm.c b/bin/rm/rm.c index 450446a48a9..944d55d42f9 100644 --- a/bin/rm/rm.c +++ b/bin/rm/rm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: rm.c,v 1.43 2021/10/24 21:24:21 deraadt Exp $ */ +/* $OpenBSD: rm.c,v 1.44 2022/08/16 13:52:41 deraadt Exp $ */ /* $NetBSD: rm.c,v 1.19 1995/09/07 06:48:50 jtc Exp $ */ /*- @@ -203,12 +203,13 @@ rm_tree(char **argv) switch (p->fts_info) { case FTS_DP: case FTS_DNR: - if (!rmdir(p->fts_accpath) || - (fflag && errno == ENOENT)) { + if (!rmdir(p->fts_accpath)) { if (vflag) fprintf(stdout, "%s\n", p->fts_path); continue; } + if (fflag && errno == ENOENT) + continue; break; case FTS_F: @@ -218,12 +219,13 @@ rm_tree(char **argv) FTS_NSOK ? NULL : p->fts_statp); /* FALLTHROUGH */ default: - if (!unlink(p->fts_accpath) || - (fflag && errno == ENOENT)) { + if (!unlink(p->fts_accpath)) { if (vflag) fprintf(stdout, "%s\n", p->fts_path); continue; } + if (fflag && errno == ENOENT) + continue; } warn("%s", p->fts_path); eval = 1; @@ -271,7 +273,7 @@ rm_file(char **argv) if (rval && (!fflag || errno != ENOENT)) { warn("%s", f); eval = 1; - } else if (vflag) + } else if (rval == 0 && vflag) (void)fprintf(stdout, "%s\n", f); } } |