commit:     74fe3bd47cce6eb811b83901476044ed90f7814d
Author:     Kerin Millar <kfm <AT> plushkava <DOT> net>
AuthorDate: Mon Jun 16 03:43:28 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Tue Jun 17 03:00:38 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=74fe3bd4

emerge-webrsync: simplify tarball name generation in do_snapshot()

Presently, the do_snapshot() function employs a somewhat convoluted
method of detecting the available decompressors - any of xzcat, bzcat
and zcat - and composing the names of the prospective tarballs. Simplify
the code by pre-generating the tarball names and storing them in the
newly introduced 'tarballs' array variable.

Signed-off-by: Kerin Millar <kfm <AT> plushkava.net>
Signed-off-by: Sam James <sam <AT> gentoo.org>

 bin/emerge-webrsync | 26 ++++++++++++++------------
 1 file changed, 14 insertions(+), 12 deletions(-)

diff --git a/bin/emerge-webrsync b/bin/emerge-webrsync
index 25ed348c96..3d83265970 100755
--- a/bin/emerge-webrsync
+++ b/bin/emerge-webrsync
@@ -435,25 +435,27 @@ sync_local() {
 
 do_snapshot() {
        local ignore_timestamp=$1 date=$2
-       local snapshot_timestamp compression{,s} utc_seconds have_files 
signature digest mirror file name
+       local snapshot_timestamp utc_seconds have_files signature digest mirror 
file
+       local -A suffix_by
+       local -a tarballs
 
-       type -P xzcat > /dev/null && compressions="${compressions} 
${repo_name}:xz portage:xz"
-       type -P bzcat > /dev/null && compressions="${compressions} 
${repo_name}:bz2 portage:bz2"
-       type -P zcat > /dev/null && compressions="${compressions} 
${repo_name}:gz portage:gz"
-       if [[ -z ${compressions} ]] ; then
-               die "unable to locate any decompressors (xzcat or bzcat or 
zcat)"
+       suffix_by=([xzcat]=xz [bzcat]=bz2 [zcat]=gz)
+
+       for file in xzcat bzcat zcat; do
+               if type -P "${file}"; then
+                       tarballs+=( 
{"$repo_name","portage"}-"${date}.tar.${suffix_by[$file]}" )
+               fi
+       done >/dev/null
+
+       if (( ! ${#tarballs[@]} )); then
+               die "unable to locate any decompressors (xzcat, bzcat or zcat)"
        fi
 
        for mirror in ${GENTOO_MIRRORS} ; do
                mirror=${mirror%/}
                [[ ${PORTAGE_QUIET} -eq 1 ]] || einfo "Trying to retrieve 
${date} snapshot from ${mirror} ..."
 
-               for compression in ${compressions} ; do
-                       name=${compression%%:*}
-
-                       compression=${compression#*:}
-
-                       file="${name}-${date}.tar.${compression}"
+               for file in "${tarballs[@]}"; do
                        digest="${file}.md5sum"
                        signature="${file}.gpgsig"
 

Reply via email to