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 1A445158074 for ; Fri, 04 Jul 2025 02:19:08 +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 056AF34209E for ; Fri, 04 Jul 2025 02:19:08 +0000 (UTC) Received: from bobolink.gentoo.org (localhost [127.0.0.1]) by bobolink.gentoo.org (Postfix) with ESMTP id 4844211055C; Fri, 04 Jul 2025 02:19:03 +0000 (UTC) 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) (No client certificate requested) by bobolink.gentoo.org (Postfix) with ESMTPS id 3FBA911055C for ; Fri, 04 Jul 2025 02:19:03 +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) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id C17CF341070 for ; Fri, 04 Jul 2025 02:19:02 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 474282CEA for ; Fri, 04 Jul 2025 02:19:01 +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: <1751595421.450ca5aac89525d612b00824380e61dca33177a0.sam@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/misc-functions.sh X-VCS-Directories: bin/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: 450ca5aac89525d612b00824380e61dca33177a0 X-VCS-Branch: master Date: Fri, 04 Jul 2025 02:19:01 +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: efa454cd-24ea-4deb-b713-2b713e546d43 X-Archives-Hash: c0c7f514f642b9e7f2eee3770524b040 commit: 450ca5aac89525d612b00824380e61dca33177a0 Author: Kerin Millar plushkava net> AuthorDate: Tue Jul 1 19:04:26 2025 +0000 Commit: Sam James gentoo org> CommitDate: Fri Jul 4 02:17:01 2025 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=450ca5aa misc-functions.sh: avoid repeatedly testing readlink -f in canonicalize() Presently, there are two implementations of canonicalize(), one of which serves to cover situations where the readlink(1) utility is either unavailable or does not support the -f option. Upon first being called, a test is performed to determine which should be used, with the result being cached by the 'READLINK_F_WORKS' variable. The intent is to avoid repeating this test on subsequent occasions that the function is called. However, owing to the way in which the function is used, the variable confers no benefit. Consider the following demonstration, which shows that the variable will be declared after the point at which bash has forked to create a subshell. $ target=$(canonicalize /bin; declare -p READLINK_F_WORKS >&2) declare -- READLINK_F_WORKS="true" $ declare -p READLINK_F_WORKS -bash: declare: READLINK_F_WORKS: not found Address this issue by having the "misc-functions.sh" unit gauge the availability and capability of readlink(1) at the the time that is sourced, declaring the appropriate form of the function in advance of its invocation. This should particularly benefit the "05prefix" QA test. Fixes: ca46b021359ffa13a808f99dd635a6958b369be5 Signed-off-by: Kerin Millar plushkava.net> Signed-off-by: Sam James gentoo.org> bin/misc-functions.sh | 55 ++++++++++++++++++++++----------------------------- 1 file changed, 24 insertions(+), 31 deletions(-) diff --git a/bin/misc-functions.sh b/bin/misc-functions.sh index d414e11f8f..abddef9f18 100755 --- a/bin/misc-functions.sh +++ b/bin/misc-functions.sh @@ -47,39 +47,32 @@ install_symlink_html_docs() { fi } -# replacement for "readlink -f" or "realpath" -READLINK_F_WORKS="" -canonicalize() { - if [[ -z ${READLINK_F_WORKS} ]] ; then - if [[ $(readlink -f -- /../ 2>/dev/null) == "/" ]] ; then - READLINK_F_WORKS=true - else - READLINK_F_WORKS=false - fi - fi - if ${READLINK_F_WORKS} ; then +if [[ $(readlink -f /../ 2>/dev/null) == / ]]; then + canonicalize() { readlink -f -- "$@" - return - fi - - local f=$1 b n=10 wd=$(pwd) - while (( n-- > 0 )); do - while [[ ${f: -1} = / && ${#f} -gt 1 ]]; do - f=${f%/} + } +else + # replacement for "readlink -f" or "realpath" + canonicalize() { + local f=$1 b n=10 wd=$(pwd) + while (( n-- > 0 )); do + while [[ ${f: -1} = / && ${#f} -gt 1 ]]; do + f=${f%/} + done + b=${f##*/} + cd "${f%"${b}"}" 2>/dev/null || break + if [[ ! -L ${b} ]]; then + f=$(pwd -P) + echo "${f%/}/${b}" + cd "${wd}" + return 0 + fi + f=$(readlink "${b}") done - b=${f##*/} - cd "${f%"${b}"}" 2>/dev/null || break - if [[ ! -L ${b} ]]; then - f=$(pwd -P) - echo "${f%/}/${b}" - cd "${wd}" - return 0 - fi - f=$(readlink "${b}") - done - cd "${wd}" - return 1 -} + cd "${wd}" + return 1 + } +fi install_qa_check() { local d f i qa_var x paths qa_checks=() checks_run=()