commit: 801146653fa3bd408d12507057d5c12839def997
Author: Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Sat Jul 5 20:05:14 2025 +0000
Commit: Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Sun Jul 13 04:19:02 2025 +0000
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=80114665
emerge-webrsync: clarify the control flow of do_snapshot()
Presently, the do_snapshot() function composes an array of snapshot
tarballs and an array of mirrors before iterating over the cross product
of both, stopping after fetching a tarball that can be validated.
Render the control flow of its innermost loop just a little more clear
by consistently employing simple command chains joined by control
operators, and by briefly commenting as to the purpose of each.
Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>
bin/emerge-webrsync | 35 ++++++++++++++++++-----------------
1 file changed, 18 insertions(+), 17 deletions(-)
diff --git a/bin/emerge-webrsync b/bin/emerge-webrsync
index 096c25e874..107613fbaf 100755
--- a/bin/emerge-webrsync
+++ b/bin/emerge-webrsync
@@ -488,6 +488,9 @@ do_snapshot() {
for mirror in "${mirrors[@]/%\/}"; do
einfo "Trying to retrieve ${date} snapshot from ${mirror} ..."
for file in "${tarballs[@]}"; do
+ have_files=0
+
+ # Attempt to use any previously downloaded files.
test -s "${DISTDIR}/${file}.md5sum" \
&& test -s "${DISTDIR}/${file}.gpgsig" \
&& test -s "${DISTDIR}/${file}" \
@@ -495,25 +498,23 @@ do_snapshot() {
&& check_file_signature "${DISTDIR}/${file}" \
&& have_files=1
- if (( ! have_files )); then
- fetch_file "${mirror}/snapshots/${file}.md5sum"
\
- && fetch_file
"${mirror}/snapshots/${file}.gpgsig" \
- && fetch_file "${mirror}/snapshots/${file}" \
- && check_file_digest "${DISTDIR}/${file}" \
- && check_file_signature "${DISTDIR}/${file}" \
- && have_files=1
- fi
+ # Otherwise, attempt to fetch the required files.
+ (( ! have_files )) \
+ && fetch_file "${mirror}/snapshots/${file}.md5sum" \
+ && fetch_file "${mirror}/snapshots/${file}.gpgsig" \
+ && fetch_file "${mirror}/snapshots/${file}" \
+ && check_file_digest "${DISTDIR}/${file}" \
+ && check_file_signature "${DISTDIR}/${file}" \
+ && have_files=1
+ # Accept any validated files under consideration,
+ # provided that the age of the snapshot is tolerable.
(( have_files )) \
- && ! is_snapshot_fresh "${DISTDIR}/${file}"
"${ignore_timestamp}" \
- && have_files=0
-
- if (( have_files )); then
- break 2
- else
- # Remove files and use a different mirror
- rm -f --
"${DISTDIR}/${file}"{".md5sum",".gpgsig",}
- fi
+ && is_snapshot_fresh "${DISTDIR}/${file}"
"${ignore_timestamp}" \
+ && break 2
+
+ # Remove any files before trying a different mirror.
+ rm -f -- "${DISTDIR}/${file}"{".md5sum",".gpgsig",}
done
done