From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from smtp.gentoo.org (woodpecker.gentoo.org [140.211.166.183]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id C46FE158128 for ; Tue, 17 Jun 2025 03:01:07 +0000 (UTC) Received: from lists.gentoo.org (bobolink.gentoo.org [140.211.166.189]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) (Authenticated sender: relay-lists.gentoo.org@gentoo.org) by smtp.gentoo.org (Postfix) with ESMTPSA id B0C5134269D for ; Tue, 17 Jun 2025 03:01:07 +0000 (UTC) Received: from bobolink.gentoo.org (localhost [127.0.0.1]) by bobolink.gentoo.org (Postfix) with ESMTP id 9D2261104F7; Tue, 17 Jun 2025 03:00:52 +0000 (UTC) Received: from smtp.gentoo.org (dev.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) by bobolink.gentoo.org (Postfix) with ESMTPS id 8C52A1104F7 for ; Tue, 17 Jun 2025 03:00:52 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange x25519) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 41198342683 for ; Tue, 17 Jun 2025 03:00:52 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id DFD5929F0 for ; Tue, 17 Jun 2025 03:00:49 +0000 (UTC) From: "Sam James" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Sam James" Message-ID: <1750129242.2144492f54f1485bb02193e56f46f87e5e47edf3.sam@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: bin/ X-VCS-Repository: proj/portage X-VCS-Files: bin/emerge-webrsync X-VCS-Directories: bin/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: 2144492f54f1485bb02193e56f46f87e5e47edf3 X-VCS-Branch: master Date: Tue, 17 Jun 2025 03:00:49 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-Archives-Salt: 9cabf115-7cca-4fd4-95b0-1553a09e4cb7 X-Archives-Hash: 293a7f526aedec262593750e9d8ba9af commit: 2144492f54f1485bb02193e56f46f87e5e47edf3 Author: Kerin Millar plushkava net> AuthorDate: Tue Jun 17 01:43:38 2025 +0000 Commit: Sam James gentoo org> CommitDate: Tue Jun 17 03:00:42 2025 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=2144492f emerge-webrsync: stash options in an associative array Jettison the 'do_debug', 'keep', 'no_pgp_verify' and 'revert_date' variables. Instead, have the argument parser of the main() function modify an associative array named 'opt'. Signed-off-by: Kerin Millar plushkava.net> Signed-off-by: Sam James gentoo.org> bin/emerge-webrsync | 81 +++++++++++++++++++++++++++++++---------------------- 1 file changed, 48 insertions(+), 33 deletions(-) diff --git a/bin/emerge-webrsync b/bin/emerge-webrsync index 32656a09d6..a58b196e31 100755 --- a/bin/emerge-webrsync +++ b/bin/emerge-webrsync @@ -25,18 +25,18 @@ # main() { - local revert_date arg v + local arg v for arg in "$@" ; do v=${arg#*=} case ${arg} in -h|--help) usage ;; - -k|--keep) keep=true ;; - -q|--quiet) PORTAGE_QUIET=1 ;; - -v|--verbose) unset PORTAGE_QUIET ;; - -x|--debug) do_debug=1 ;; - --revert=*) revert_date=${v} ;; - --no-pgp-verify) no_pgp_verify=1 ;; + -k|--keep) opt[keep]=1 ;; + -q|--quiet) opt[quiet]=1 ;; + -v|--verbose) opt[quiet]=0 ;; + -x|--debug) opt[debug]=1 ;; + --revert=*) opt[revert]=${v} ;; + --no-pgp-verify) opt[no-pgp-verify]=1 ;; *) usage "Invalid option '${arg}'" ;; esac done @@ -64,10 +64,10 @@ main() { && cd -- "${tmpdir}" \ || exit - ${keep} || DISTDIR=${tmpdir} + (( opt[keep] )) || DISTDIR=${tmpdir} [[ ! -d "${DISTDIR}" ]] && mkdir -p "${DISTDIR}" - if ${keep} && [[ ! -w ${DISTDIR} ]] ; then + if (( opt[keep] )) && [[ ! -w ${DISTDIR} ]] ; then die "DISTDIR is not writable: ${DISTDIR}" fi @@ -84,11 +84,11 @@ main() { die fi - [[ ${do_debug} -eq 1 ]] && set -x + (( opt[debug] )) && set -x - if [[ -n ${revert_date} ]] ; then + if [[ -v 'opt[revert]' ]]; then emaint revisions --purgerepos="${repo_name}" - do_snapshot 1 "${revert_date}" + do_snapshot 1 "${opt[revert]}" else do_latest_snapshot fi @@ -116,7 +116,7 @@ usage() { } handle_pgp_setup() { - if [[ ${no_pgp_verify} ]]; then + if (( opt[no-pgp-verify] )); then # Disable PGP verification. The webrsync module specifies this # option if the "sync-webrsync-verify-signature" repo attribute # is explicitly defined with a value of "false". @@ -136,10 +136,14 @@ handle_pgp_setup() { case "${WEBRSYNC_VERIFY_SIGNATURE}" in 0) - [[ ${PORTAGE_QUIET} -eq 1 ]] || ewarn "PGP verification method: disabled" + if (( ! opt[quiet] )); then + ewarn "PGP verification method: disabled" + fi ;; 1) - [[ ${PORTAGE_QUIET} -eq 1 ]] || einfo "PGP verification method: gemato" + if (( ! opt[quiet] )); then + einfo "PGP verification method: gemato" + fi ;; 2) ewarn "PGP verification method: legacy gpg path" @@ -220,7 +224,9 @@ fetch_file() { rm -f "${DISTDIR}/${FILE}" fi - [[ ${PORTAGE_QUIET} -eq 1 ]] || einfo "Fetching file ${FILE} ..." + if (( ! opt[quiet] )); then + einfo "Fetching file ${FILE} ..." + fi # Already set DISTDIR= eval "${FETCHCOMMAND} ${opts}" @@ -236,7 +242,9 @@ check_file_digest() { local digest=$1 file=$2 local digest_content md5sum_output - [[ ${PORTAGE_QUIET} -eq 1 ]] || einfo "Checking digest ..." + if (( ! opt[quiet] )); then + einfo "Checking digest ..." + fi if type -P md5sum > /dev/null; then md5sum_output=$(md5sum "${file}") @@ -278,8 +286,8 @@ check_file_signature_gemato() { fi [[ -n ${PORTAGE_GPG_KEY_SERVER} ]] && gemato_args+=( --keyserver "${PORTAGE_GPG_KEY_SERVER}" ) - [[ ${PORTAGE_QUIET} == 1 ]] && gemato_args+=( --quiet ) - [[ ${do_debug} == 1 ]] && gemato_args+=( --debug ) + (( opt[quiet] )) && gemato_args+=( --quiet ) + (( opt[debug] )) && gemato_args+=( --debug ) if ! gemato "${gemato_args[@]}" -- "${signature}" "${file}"; then # Exit early since it's typically inappropriate to try @@ -362,7 +370,7 @@ check_file_signature() { case ${WEBRSYNC_VERIFY_SIGNATURE} in [12]) - if [[ ${PORTAGE_QUIET} -ne 1 ]]; then + if (( ! opt[quiet] )); then einfo "Checking signature ..." fi ;;& @@ -395,7 +403,9 @@ sync_local() { local ownership post_sync local -a chown_opts rsync_opts - [[ ${PORTAGE_QUIET} -eq 1 ]] || einfo "Syncing local repository ..." + if (( ! opt[quiet] )); then + einfo "Syncing local repository ..." + fi ownership="${PORTAGE_USERNAME}:${PORTAGE_GRPNAME}" if contains_word usersync "${FEATURES}"; then @@ -428,7 +438,7 @@ sync_local() { fi # Free disk space - ${keep} || rm -f "${file}" + (( opt[keep] )) || rm -f "${file}" read -rd '' -a rsync_opts <<<"${PORTAGE_RSYNC_OPTS} ${PORTAGE_RSYNC_EXTRA_OPTS} $(nvecho -q)" if chown "${ownership}" . 2>/dev/null; then @@ -442,7 +452,9 @@ sync_local() { die "Aborting because of rsync failure" } - [[ ${PORTAGE_QUIET} == 1 ]] || einfo "Cleaning up ..." + if (( ! opt[quiet] )); then + einfo "Cleaning up ..." + fi fi if contains_word metadata-transfer "${FEATURES}"; then @@ -480,8 +492,9 @@ do_snapshot() { for mirror in ${GENTOO_MIRRORS} ; do mirror=${mirror%/} - [[ ${PORTAGE_QUIET} -eq 1 ]] || einfo "Trying to retrieve ${date} snapshot from ${mirror} ..." - + if (( ! opt[quiet] )); then + einfo "Trying to retrieve ${date} snapshot from ${mirror} ..." + fi for file in "${tarballs[@]}"; do digest="${file}.md5sum" signature="${file}.gpgsig" @@ -507,7 +520,9 @@ do_snapshot() { # from a different mirror # if (( have_files )); then - [[ ${PORTAGE_QUIET} -eq 1 ]] || einfo "Getting snapshot timestamp ..." + if (( ! opt[quiet] )); then + einfo "Getting snapshot timestamp ..." + fi snapshot_timestamp=$(get_snapshot_timestamp "${DISTDIR}/${file}") @@ -540,7 +555,7 @@ do_snapshot() { if (( have_files )); then sync_local "${DISTDIR}/${file}" \ - && { ${keep} || rm -f "${DISTDIR}"/{"$file","$digest","$signature"}; } + && { (( opt[keep] )) || rm -f "${DISTDIR}"/{"$file","$digest","$signature"}; } else ewarn "${date} snapshot was not found" false @@ -551,7 +566,9 @@ do_latest_snapshot() { local timestamp_{difference,problem} snapshot_date{,_seconds} approx_snapshot_time existing_timestamp start_{hour,time} local min_time_diff attempts=0 - [[ ${PORTAGE_QUIET} -eq 1 ]] || einfo "Fetching most recent snapshot ..." + if (( ! opt[quiet] )); then + einfo "Fetching most recent snapshot ..." + fi # The snapshot for a given day is generated at 00:45 UTC on the following # day, so the current day's snapshot (going by UTC time) hasn't been @@ -653,9 +670,9 @@ source "${functions_script}" || { } # Only echo if in normal mode -vvecho() { [[ ${PORTAGE_QUIET} != 1 ]] && echo "$@" ; } +vvecho() { (( opt[quiet] )) || echo "$@"; } # Only echo if in quiet mode -nvecho() { [[ ${PORTAGE_QUIET} == 1 ]] && echo "$@" ; } +nvecho() { (( ! opt[quiet] )) || echo "$@"; } # Unfortunately, gentoo-functions doesn't yet have a die() (bug #878505) die() { @@ -696,7 +713,5 @@ if [[ -n "${PORTAGE_NICENESS}" ]]; then renice "${PORTAGE_NICENESS}" $$ > /dev/null fi -do_debug=0 -keep=false - +declare -A opt main "$@"