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 D1B151581CA for ; Wed, 18 Jun 2025 02:33:36 +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 B7A67341603 for ; Wed, 18 Jun 2025 02:33:36 +0000 (UTC) Received: from bobolink.gentoo.org (localhost [127.0.0.1]) by bobolink.gentoo.org (Postfix) with ESMTP id CF0C71104DC; Wed, 18 Jun 2025 02:33:32 +0000 (UTC) Received: from smtp.gentoo.org (smtp.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 C6ED11104DC for ; Wed, 18 Jun 2025 02:33:32 +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 7ACA83415F0 for ; Wed, 18 Jun 2025 02:33:32 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 2431229ED for ; Wed, 18 Jun 2025 02:33:31 +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: <1750214007.caa8f296a5b3f5bdb8f36321a9334f8ff52d9d30.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: caa8f296a5b3f5bdb8f36321a9334f8ff52d9d30 X-VCS-Branch: master Date: Wed, 18 Jun 2025 02:33:31 +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: 22dab704-2ebf-4b4d-b40f-1a6f135613d6 X-Archives-Hash: befc6e80149d44affd79074127c88625 commit: caa8f296a5b3f5bdb8f36321a9334f8ff52d9d30 Author: Kerin Millar plushkava net> AuthorDate: Wed Jun 18 02:16:40 2025 +0000 Commit: Sam James gentoo org> CommitDate: Wed Jun 18 02:33:27 2025 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=caa8f296 emerge-webrsync: drop the get_unixtime() and get_date_part() functions Drop both the get_unixtime() and get_date_part() functions in favour of utilising the %(fmt)T format that is supported by the printf builtin. BEFORE $ date -u +%s # print time of day in unixtime $ date -u -d "@${unixtime}" +%Y%m%d # convert unixtime to a %Y%m%d date AFTER $ printf '%(%s)T\n' $ printf '%(%Y%m%d)T\n' "${unixtime}" Note that, as of bash 4.3, no arguments need be specified after the format string in order to obtain the current time of day. Older versions required an argument of -1 for that purpose. Signed-off-by: Kerin Millar plushkava.net> Signed-off-by: Sam James gentoo.org> bin/emerge-webrsync | 24 +++++------------------- 1 file changed, 5 insertions(+), 19 deletions(-) diff --git a/bin/emerge-webrsync b/bin/emerge-webrsync index a8e70e0af1..719965e302 100755 --- a/bin/emerge-webrsync +++ b/bin/emerge-webrsync @@ -169,20 +169,6 @@ do_tar() { } } -get_unixtime() { - date -u +"%s" -} - -get_date_part() { - local unixtime=$1 part=$2 - - if [[ ${USERLAND} == BSD ]] ; then - date -r "${unixtime}" -u +"${part}" - else - date -d "@${unixtime}" -u +"${part}" - fi -} - get_unixtime_from_string() { local s=$1 @@ -557,7 +543,7 @@ do_snapshot() { do_latest_snapshot() { local timestamp_{difference,problem} snapshot_{date,unixtime} approx_snapshot_time existing_timestamp start_{hour,time} - local min_time_diff attempts=0 + local min_time_diff attempts TZ=UTC einfo "Fetching most recent snapshot ..." @@ -571,8 +557,8 @@ do_latest_snapshot() { min_time_diff=$(( 2 * 60 * 60 )) existing_timestamp=$(get_repository_timestamp) - start_time=$(get_unixtime) - start_hour=$(get_date_part "${start_time}" "%H") + printf -v start_time '%(%s)T' + printf -v start_hour '%(%H)T' "${start_time}" # Daily snapshots are created at 00:45 and are not # available until after 01:00. Don't waste time trying @@ -581,7 +567,7 @@ do_latest_snapshot() { (( start_time -= 86400 )) fi - snapshot_date=$(get_date_part "${start_time}" "%Y%m%d") + printf -v snapshot_date '%(%Y%m%d)T' "${start_time}" snapshot_unixtime=$(get_unixtime_from_string "${snapshot_date}") while (( attempts++ < 40 )); do @@ -591,7 +577,7 @@ do_latest_snapshot() { (( timestamp_difference = existing_timestamp - approx_snapshot_time )) [[ ${timestamp_difference} -lt 0 ]] && (( timestamp_difference = -1 * timestamp_difference )) - snapshot_date=$(get_date_part "${snapshot_unixtime}" "%Y%m%d") + printf -v snapshot_date '%(%Y%m%d)T' "${snapshot_unixtime}" timestamp_problem="" if [[ ${timestamp_difference} -eq 0 ]]; then