commit: 7fd6d076b20ebdf617b74e4b25917f5d01e5b16d
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Fri Jun 27 04:42:44 2025 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sat Jun 28 02:30:15 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=7fd6d076
phase-functions.sh: use find(1) to potentially delete PORTAGE_BUILDDIR
Presently, the __dyn_clean() function concludes with an invocation of
rmdir(1) that attempts to delete the directory specified by the
'PORTAGE_BUILDDIR' variable, immediately followed by an invocation of
the true builtin. Clearly, the author of this code acknowledged that the
directory might still be populated, but chose to silence the ensuing
error and jettison the exit status of rmdir(1).
Address this issue by instead invoking find(1) with the primaries
necessary for it to identify an empty directory, and by having it
execute rmdir(1) in that event. Further, pass the "--" operand to
rmdir(1) to signify end-of-options.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/phase-functions.sh | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)
diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh
index de86b00cc4..c3a051bb7b 100644
--- a/bin/phase-functions.sh
+++ b/bin/phase-functions.sh
@@ -331,9 +331,8 @@ __dyn_clean() {
# result in it wiping the users distfiles directory (bad).
rm -rf "${PORTAGE_BUILDDIR}/distdir"
- rmdir "${PORTAGE_BUILDDIR}" 2>/dev/null
-
- true
+ printf '%s\0' "${PORTAGE_BUILDDIR}" \
+ | find0 -maxdepth 0 -type d -empty -exec rmdir -- {} \;
}
__abort_handler() {