rm(1): remove whiteouts when forcibly removing directories
Some checks are pending
Cross-build Kernel / amd64 ubuntu-22.04 (clang-15) (push) Waiting to run
Cross-build Kernel / aarch64 ubuntu-22.04 (clang-15) (push) Waiting to run
Cross-build Kernel / amd64 ubuntu-24.04 (clang-18) (push) Waiting to run
Cross-build Kernel / aarch64 ubuntu-24.04 (clang-18) (push) Waiting to run
Cross-build Kernel / amd64 macos-latest (clang-18) (push) Waiting to run
Cross-build Kernel / aarch64 macos-latest (clang-18) (push) Waiting to run

Commit 2ed053cde5 changed UFS' VOP_RMDIR() behavior to no longer
ignore whiteouts when determining whether a directory is empty,
unless explicitly requested by the caller.  However, this also
necessitates a change to rm(1) to avoid breaking the expected
behavior when forcibly removing directory hierarchies via `rm -fr`.
I neglected to make this follow-on change despite discussing it
in the review for the breaking commit (D45987).

Finally address the breakage by making `rm -fr` imply FTS_WHITEOUT
when rm(1) reads directory contents via fts_read(3).  While here,
also fix a logic error which produces a spurious 'No error' warning
message on stdout for each deleted whiteout.

Reported by:	csjp
Reviewed by:	csjp, kib, olce
MFC after:	3 days
Differential Revision:	https://reviews.freebsd.org/D53640
This commit is contained in:
Jason A. Harmening 2025-11-07 22:23:02 -06:00
parent 335fc09ab8
commit 8b92a6ad59

View file

@ -184,7 +184,7 @@ rm_tree(char **argv)
flags = FTS_PHYSICAL;
if (!needstat)
flags |= FTS_NOSTAT;
if (Wflag)
if (Wflag || fflag)
flags |= FTS_WHITEOUT;
if (xflag)
flags |= FTS_XDEV;
@ -273,7 +273,7 @@ rm_tree(char **argv)
case FTS_W:
rval = undelete(p->fts_accpath);
if (rval == 0 && (fflag && errno == ENOENT)) {
if (rval == 0 || (fflag && errno == ENOENT)) {
if (vflag)
(void)printf("%s\n",
p->fts_path);