From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 69C46158074 for ; Sat, 28 Jun 2025 02:30:45 +0000 (UTC) Received: from lists.gentoo.org (bobolink.gentoo.org [140.211.166.189]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) (Authenticated sender: relay-lists.gentoo.org@gentoo.org) by smtp.gentoo.org (Postfix) with ESMTPSA id 543A1340EA7 for ; Sat, 28 Jun 2025 02:30:45 +0000 (UTC) Received: from bobolink.gentoo.org (localhost [127.0.0.1]) by bobolink.gentoo.org (Postfix) with ESMTP id 9B15111055E; Sat, 28 Jun 2025 02:30:36 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) by bobolink.gentoo.org (Postfix) with ESMTPS id 8D0E911055D for ; Sat, 28 Jun 2025 02:30:36 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 46C8F340EAC for ; Sat, 28 Jun 2025 02:30:36 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id B2DFE2AA2 for ; Sat, 28 Jun 2025 02:30:34 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1751077815.2d5809fd23c620f7889441202eeb5950959eb3e8.sam@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/phase-functions.sh X-VCS-Directories: bin/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: 2d5809fd23c620f7889441202eeb5950959eb3e8 X-VCS-Branch: master Date: Sat, 28 Jun 2025 02:30:34 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: cbaaba72-b851-465b-9c16-98e9e5f503f0 X-Archives-Hash: 0b2c10b7df095d51d6135542003636d7 commit: 2d5809fd23c620f7889441202eeb5950959eb3e8 Author: Kerin Millar plushkava net> AuthorDate: Wed Jun 25 04:50:26 2025 +0000 Commit: Sam James gentoo org> CommitDate: Sat Jun 28 02:30:15 2025 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=2d5809fd phase-functions.sh: improve empty directory culling in __dyn_clean() Presently, the __dyn_clean() function contains a pipeline that is intended to recursively delete empty directories, with the exception of those whose pathnames are equal to - or subsumed by - the path specified by the 'WORKDIR' variable. This pipeline suffers from various defects, which are described and addressed herewith. The value of the 'PORTAGE_BUILDDIR' variable could be treated by the find(1) utility as an option or primary. Address this issue by using the find0() function, which takes advantage of the -files0-from option that is supported as of findutils-4.9.0. Pathnames containing are handled neither correctly nor safely. Address this issue by specifying the -print0 primary to find(1), thereby producing a stream of null-terminated pathnames. The value of the 'WORKDIR' variable is injected into the argument following the -regex primary, resulting in it being treated as a sub-pattern of a regular expression in the GNU Emacs dialect. Address this issue by eschewing the primary and, instead, using bash to safely exclude any pathnames that are equal to - or subsumed by - 'WORKDIR'. The sort(1) utility is used to reverse the list of pathnames, with the intent of ensuring that directory removal is performed in a depth-first fashion. Not only is this fairly expensive but it also requires for the input stream to be a list of -terminated pathnames. Address this issue by forgoing the use of sort(1) and, instead, specifying the -depth primary to find(1). The rmdir(1) utility is invoked in such a way that STDERR is muted. It appears to be a sloppy attempt at covering up the fact that rmdir(1) won't be able to remove any non-empty directories. Address this issue by refraining from muting STDERR and, instead, specifying the -empty primary to find(1). The rmdir(1) utility is invoked in such a way that its operands could be mistaken for options. Address this issue by specifying the "--" operand, so as to signify end-of-options. See-also: d887c7fd33b5f136ff62d423d7a11980fb9faca1 See-also: a0210b3c49ea346b1e999f92a7ed89802e8d6849 Signed-off-by: Kerin Millar plushkava.net> Signed-off-by: Sam James gentoo.org> bin/phase-functions.sh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/bin/phase-functions.sh b/bin/phase-functions.sh index abe7162560..de86b00cc4 100644 --- a/bin/phase-functions.sh +++ b/bin/phase-functions.sh @@ -321,7 +321,10 @@ __dyn_clean() { fi if [[ -f "${PORTAGE_BUILDDIR}/.unpacked" ]]; then - find "${PORTAGE_BUILDDIR}" -type d ! -regex "^${WORKDIR}" | sort -r | tr "\n" "\0" | ${XARGS} -0 rmdir &>/dev/null + printf '%s\0' "${PORTAGE_BUILDDIR}" \ + | find0 -depth -type d -empty -print0 \ + | while read -rd ''; do [[ ${REPLY} != "${WORKDIR}"?(/*) ]] && printf '%s\0' "${REPLY}"; done \ + | ${XARGS} -0 rmdir -- fi # Do not bind this to doebuild defined DISTDIR; don't trust doebuild, and if mistakes are made it'll