commit: 11f0782599ef0c56142aa0b615ce8e1753ce94c7
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sun Jun 22 03:33:15 2025 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Jun 22 10:57:00 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=11f07825
emerge-werbsync: refactor check_file_digest() and implement diagnostics
This commit aims to improve the check_file_digest() function through
some minor refactoring. The exact changes are described herewith.
Delegate the responsibility of executing the md5sum(1) and md5(1)
utilities to a new function, named md5sum_hex().
In the event that the digest file cannot be opened or read, print a
diagnostic message with ewarn() before returning false, rather than
remain silent.
In the event that the md5sum_hex() function returns false, print a
diagnostic message and exit by calling die(). As before, emerge-webrsync
shall exit if neither of the required utilities can be found. Unlike
before, emerge-webrsync shall also exit if either utility fails, meaning
that it is able to react to severe modes of failure (such as EIO).
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/emerge-webrsync | 25 ++++++++++++++++++-------
1 file changed, 18 insertions(+), 7 deletions(-)
diff --git a/bin/emerge-webrsync b/bin/emerge-webrsync
index 6ee9bd7810..e75a8d67ca 100755
--- a/bin/emerge-webrsync
+++ b/bin/emerge-webrsync
@@ -235,15 +235,26 @@ check_file_digest() {
einfo "Checking digest ..."
- read -r digest_content _ < "${digest}" || return
+ if ! read -r digest_content _ < "${digest}"; then
+ digest=${digest##*/}
+ ewarn "Disregarding ${digest@Q} because it couldn't be parsed"
+ false
+ elif ! md5sum_output=$(md5sum_hex "${file}"); then
+ file=${file##*/}
+ die "couldn't calculate an MD5 checksum for ${file@Q}"
+ else
+ [[ ${md5sum_output} == "${digest_content}" ]]
+ fi
+}
+
+md5sum_hex() {
+ local output
- if hash md5sum 2>/dev/null; then
- md5sum_output=$(md5sum -- "${file}")
- [[ "${md5sum_output%%[[:space:]]*}" == "${digest_content}" ]]
- elif hash md5 2>/dev/null; then
- [[ $(md5 -q -- "${file}") == "${digest_content}" ]]
+ if hash md5 2>/dev/null; then
+ md5 -q -- "$1"
else
- die "cannot check digest: no suitable md5/md5sum binaries found"
+ output=$(md5sum -- "$1") \
+ && printf '%s\n' "${output%%[[:blank:]]*}"
fi
}