Skip to content

Commit

Permalink
rm: rm -f should not fail
Browse files Browse the repository at this point in the history
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
  • Loading branch information
jlduran committed Jul 16, 2024
1 parent 87ee63b commit 8d963aa
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions bin/rm/rm.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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;
}

Check warning on line 376 in bin/rm/rm.c

View workflow job for this annotation

GitHub Actions / Style Checker

Missing Signed-off-by: line

Check warning on line 376 in bin/rm/rm.c

View workflow job for this annotation

GitHub Actions / Style Checker

Missing Signed-off-by: line
Expand Down

0 comments on commit 8d963aa

Please sign in to comment.