aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2025-10-06 13:31:48 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2025-10-06 13:37:21 -0700
commitbae32db8fead1134e4ce5804f61ec094cf2cad0b (patch)
tree23c629a861ffa22d1816f1936948420bf04784a3 /src
parentcksum: allow -a {blake2b,sha2,sha3} --check to work on base64 (diff)
downloadcoreutils-bae32db8fead1134e4ce5804f61ec094cf2cad0b.tar.gz
coreutils-bae32db8fead1134e4ce5804f61ec094cf2cad0b.zip
rm: make ‘rm -d DIR’ more like ‘rmdir DIR’
* src/remove.c (rm_fts): When not recursive, arrange for ‘rm -d DIR’ to behave more like ‘rmdir DIR’. This works better for Ceph snapshot directories. Problem reported by Yannick Le Pennec (bug#78245).
Diffstat (limited to 'src')
-rw-r--r--src/remove.c18
1 files changed, 8 insertions, 10 deletions
diff --git a/src/remove.c b/src/remove.c
index 079b00fc1..f50276efd 100644
--- a/src/remove.c
+++ b/src/remove.c
@@ -446,18 +446,16 @@ rm_fts (FTS *fts, FTSENT *ent, struct rm_options const *x)
switch (ent->fts_info)
{
case FTS_D: /* preorder directory */
- if (! x->recursive
- && !(x->remove_empty_directories
- && get_dir_status (fts, ent, &dir_status) != 0))
+ if (!x->recursive)
{
- /* This is the first (pre-order) encounter with a directory
- that we cannot delete.
- Not recursive, and it's not an empty directory (if we're removing
- them) so arrange to skip contents. */
- int err = x->remove_empty_directories ? ENOTEMPTY : EISDIR;
- error (0, err, _("cannot remove %s"), quoteaf (ent->fts_path));
+ /* Not recursive, so skip contents, and fail now unless
+ removing empty directories. */
+ fts_set (fts, ent, FTS_SKIP);
+ if (x->remove_empty_directories)
+ return RM_OK;
+ error (0, EISDIR, _("cannot remove %s"), quoteaf (ent->fts_path));
mark_ancestor_dirs (ent);
- fts_skip_tree (fts, ent);
+ ignore_value (fts_read (fts));
return RM_ERROR;
}