commit: a921d6ee5670778bcd0606ff29e41932312a50ea
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Tue Jul 1 18:27:27 2025 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Jul 4 02:17:00 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=a921d6ee
emerge-webrsync: avoid repeated PATH searches for md5(1)
Presently, the md5sum_hex() function checks whether the md5(1) utility
is available by using the hash builtin. Given the platforms currently
supported by Gentoo, it is rather unlikely that it will be found, in
which case the md5sum(1) utility shall be used instead.
Under these circumstances, should the function be called again, so
shall the hash builtin incur a PATH search again, for reasons twofold.
Firstly, the cache of utility locations can only contain positive
entries (found paths by utility name), not negative entries (unfound
paths by utility name). Secondly, the function is called only from
subshells, with their operating environments being lost upon exiting.
Address this minor issue by declaring the function in advance.
Consequently, a PATH search shall be performed no more than twice in the
worst case; once to miss md5(1) and another to hit or miss md5sum(1).
Reported-by: Sam James <sam <AT> gentoo.org>
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/emerge-webrsync | 16 +++++++++-------
1 file changed, 9 insertions(+), 7 deletions(-)
diff --git a/bin/emerge-webrsync b/bin/emerge-webrsync
index e908a97cbc..e8a816efbb 100755
--- a/bin/emerge-webrsync
+++ b/bin/emerge-webrsync
@@ -243,16 +243,18 @@ check_file_digest() {
fi
}
-md5sum_hex() {
- local output
-
- if hash md5 2>/dev/null; then
+if hash md5 2>/dev/null; then
+ md5sum_hex() {
md5 -q -- "$1"
- else
+ }
+else
+ md5sum_hex() {
+ local output
+
output=$(md5sum -- "$1") \
&& printf '%s\n' "${output%%[[:blank:]]*}"
- fi
-}
+ }
+fi
check_file_signature_gemato() {
local file=$1