From 8d963aa045a4b1543c507444a06a62f0c8de649b Mon Sep 17 00:00:00 2001 From: Jose Luis Duran Date: Tue, 16 Jul 2024 21:02:51 +0000 Subject: [PATCH] rm: rm -f should not fail Fix an inverted logic bug, so the -f flag is always honored. When trying to forcefully (-f) remove a nonexistent file on an msdosfs mount, an error is thrown: # rm -f /boot/efi/foo* rm: /boot/efi/foo*: Invalid argument --- bin/rm/rm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/bin/rm/rm.c b/bin/rm/rm.c index 16bbf7403fd4e8..a0fe63db118f50 100644 --- a/bin/rm/rm.c +++ b/bin/rm/rm.c @@ -196,7 +196,7 @@ rm_tree(char **argv) while (errno = 0, (p = fts_read(fts)) != NULL) { switch (p->fts_info) { case FTS_DNR: - if (!fflag || p->fts_errno != ENOENT) { + if (!fflag && p->fts_errno != ENOENT) { warnx("%s: %s", p->fts_path, strerror(p->fts_errno)); eval = 1; @@ -211,7 +211,7 @@ rm_tree(char **argv) */ if (!needstat) break; - if (!fflag || p->fts_errno != ENOENT) { + if (!fflag && p->fts_errno != ENOENT) { warnx("%s: %s", p->fts_path, strerror(p->fts_errno)); eval = 1; @@ -338,7 +338,7 @@ rm_file(char **argv) if (Wflag) { sb.st_mode = S_IFWHT|S_IWUSR|S_IRUSR; } else { - if (!fflag || errno != ENOENT) { + if (!fflag && errno != ENOENT) { warn("%s", f); eval = 1; } @@ -370,7 +370,7 @@ rm_file(char **argv) else rval = unlink(f); } - if (rval && (!fflag || errno != ENOENT)) { + if (rval && (!fflag && errno != ENOENT)) { warn("%s", f); eval = 1; }