commit: ad6431fe1eaf1982fd5550a5b75ece77d94e191c
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Fri Jun 20 20:00:09 2025 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Jun 22 10:56:59 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=ad6431fe
emerge-webrsync: employ a single method of parsing md5sum digests
Presently, the check_file_digest() function employs two disparate
methods of parsing md5sum digest files.
If the md5sum(1) utility is found to exist, the complete contents of the
file are read and assigned to the 'digest_content' variable, which is
subsequently expanded in a way that strips everything from the first
whitespace character onwards. This method is acceptable, albeit
potentially expensive in the case that the file is larger than expected.
If, on the other hand, the md5(1) utility is found to exist, the cut(1)
utility is used to print the first field of every line in the file. In
doing so, the assumption is made that the file contains only one line.
Address the matter by employing just one method of reading the MD5
checksum from the digest file, which is to use the read builtin to
obtain the first field of the first line. Further, if it cannot then
immediately return false.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/emerge-webrsync | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/bin/emerge-webrsync b/bin/emerge-webrsync
index 743dee2fbe..6ee9bd7810 100755
--- a/bin/emerge-webrsync
+++ b/bin/emerge-webrsync
@@ -235,12 +235,13 @@ check_file_digest() {
einfo "Checking digest ..."
+ read -r digest_content _ < "${digest}" || return
+
if hash md5sum 2>/dev/null; then
md5sum_output=$(md5sum -- "${file}")
- digest_content=$(< "${digest}")
- [[ "${md5sum_output%%[[:space:]]*}" =
"${digest_content%%[[:space:]]*}" ]]
+ [[ "${md5sum_output%%[[:space:]]*}" == "${digest_content}" ]]
elif hash md5 2>/dev/null; then
- [[ "$(md5 -q -- "${file}")" == "$(cut -d ' ' -f 1 --
"${digest}")" ]]
+ [[ $(md5 -q -- "${file}") == "${digest_content}" ]]
else
die "cannot check digest: no suitable md5/md5sum binaries found"
fi