Skip to content

Commit b8e6379

Browse files
committed
rm: don't suppress error messages if -f is used
Unlike every other rm(1) and contrary to the POSIX standard, libcmd's rm suppresses all error messages (such as 'permission denied') upon failure to unlink(2) or rmdir(2) if the -f/--force option is used. This commit makes rm print its error messages (except for 'not found') regardless of -f (state->force). This commit also changes the error message 'directory not removed' to 'directory not empty' which is more like GNU and BSD rm.
1 parent 7886cdc commit b8e6379

File tree

2 files changed

+13
-24
lines changed

2 files changed

+13
-24
lines changed

NEWS

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ This documents significant changes in the 1.0 branch of ksh 93u+m.
22
For full details, see the git log at: https://github.com/ksh93/ksh/tree/1.0
33
Uppercase BUG_* IDs are shell bug IDs as used by the Modernish shell library.
44

5+
2025-09-30:
6+
7+
- The rm path-bound built-in command from libcmd no longer suppresses error
8+
messages when the -f/--force option is used.
9+
510
2025-06-14:
611

712
- Fixed a bug occurring on systems with posix_spawn(3), spawnve(2), and

src/lib/libcmd/rm.c

Lines changed: 8 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* *
33
* This software is part of the ast package *
44
* Copyright (c) 1992-2013 AT&T Intellectual Property *
5-
* Copyright (c) 2020-2024 Contributors to ksh 93u+m *
5+
* Copyright (c) 2020-2025 Contributors to ksh 93u+m *
66
* and is licensed under the *
77
* Eclipse Public License, Version 2.0 *
88
* *
@@ -24,7 +24,7 @@
2424
*/
2525

2626
static const char usage[] =
27-
"[-?\n@(#)$Id: rm (ksh 93u+m) 2022-08-30 $\n]"
27+
"[-?\n@(#)$Id: rm (ksh 93u+m) 2025-09-30 $\n]"
2828
"[--catalog?" ERROR_CATALOG "]"
2929
"[+NAME?rm - remove files]"
3030
"[+DESCRIPTION?\brm\b removes the named \afile\a arguments. By default it"
@@ -123,10 +123,8 @@ rm(State_t* state, FTSENT* ent)
123123
}
124124
error_info.errors++;
125125
}
126-
else if (!state->force)
127-
error(2, "%s: cannot %s directory", ent->fts_path, (ent->fts_info & FTS_NR) ? "read" : "search");
128126
else
129-
error_info.errors++;
127+
error(2, "%s: cannot %s directory", ent->fts_path, (ent->fts_info & FTS_NR) ? "read" : "search");
130128
fts_set(NULL, ent, FTS_SKIP);
131129
nonempty(ent);
132130
break;
@@ -136,10 +134,7 @@ rm(State_t* state, FTSENT* ent)
136134
if (path[0] == '.' && (!path[1] || path[1] == '.' && !path[2]) && (ent->fts_level > 0 || path[1]))
137135
{
138136
fts_set(NULL, ent, FTS_SKIP);
139-
if (!state->force)
140-
error(2, "%s: cannot remove", ent->fts_path);
141-
else
142-
error_info.errors++;
137+
error(2, "%s: cannot remove", ent->fts_path);
143138
break;
144139
}
145140
if (!state->recursive)
@@ -224,25 +219,17 @@ rm(State_t* state, FTSENT* ent)
224219
/* FALLTHROUGH */
225220
default:
226221
nonempty(ent);
227-
if (!state->force)
228-
error(ERROR_SYSTEM|2, "%s: directory not removed", ent->fts_path);
229-
else
230-
error_info.errors++;
222+
error(ERROR_SYSTEM|2, "%s: directory not removed", ent->fts_path);
231223
break;
232224
}
233225
}
234-
else if (!state->force)
235-
error(2, "%s: cannot remove", ent->fts_path);
236226
else
237-
error_info.errors++;
227+
error(2, "%s: cannot remove", ent->fts_path);
238228
}
239229
else
240230
{
241231
nonempty(ent);
242-
if (!state->force)
243-
error(2, "%s: directory not removed", ent->fts_path);
244-
else
245-
error_info.errors++;
232+
error(2, "%s: directory not empty", ent->fts_path);
246233
}
247234
break;
248235
default:
@@ -308,10 +295,7 @@ rm(State_t* state, FTSENT* ent)
308295
case ENOENT:
309296
break;
310297
default:
311-
if (!state->force || state->interactive)
312-
error(ERROR_SYSTEM|2, "%s: not removed", ent->fts_path);
313-
else
314-
error_info.errors++;
298+
error(ERROR_SYSTEM|2, "%s: not removed", ent->fts_path);
315299
break;
316300
}
317301
}

0 commit comments

Comments
 (0)