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 4FABB158200 for ; Sun, 14 Sep 2025 09:33:25 +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 36A8E34107F for ; Sun, 14 Sep 2025 09:33:25 +0000 (UTC) Received: from bobolink.gentoo.org (localhost [127.0.0.1]) by bobolink.gentoo.org (Postfix) with ESMTP id D4B63110573; Sun, 14 Sep 2025 09:33:19 +0000 (UTC) Received: from smtp.gentoo.org (woodpecker.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 CB046110571 for ; Sun, 14 Sep 2025 09:33:19 +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 7ECE3340F71 for ; Sun, 14 Sep 2025 09:33:19 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 2161A39A4 for ; Sun, 14 Sep 2025 09:33:18 +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: <1757842391.4b57307865cf4bcde8ef5150303eb48465a43689.sam@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/util/ X-VCS-Repository: proj/portage X-VCS-Files: lib/portage/util/_urlopen.py X-VCS-Directories: lib/portage/util/ X-VCS-Committer: sam X-VCS-Committer-Name: Sam James X-VCS-Revision: 4b57307865cf4bcde8ef5150303eb48465a43689 X-VCS-Branch: master Date: Sun, 14 Sep 2025 09:33:18 +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: 314b97f8-588c-47e0-88f8-2a930140742e X-Archives-Hash: 4a1a705da3947a4c87f720ec08617309 commit: 4b57307865cf4bcde8ef5150303eb48465a43689 Author: Sam James gentoo org> AuthorDate: Sun Sep 14 09:02:46 2025 +0000 Commit: Sam James gentoo org> CommitDate: Sun Sep 14 09:33:11 2025 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=4b573078 _urlopen: fix timestamp comparison by using UTC consistently In bintree.py's _populate_remote, we call http_to_timestamp on the timestamp header we get from the remote binhost. Unfortunately, that uses mktime() which is documented to return *local time*: > This is the inverse function of localtime(). Its argument is the struct_time or > full 9-tuple (since the dst flag is needed; use -1 as the dst flag if it is unknown) > which expresses the time in local time, not UTC. Switch to using mktime_tz and parsedate_tz which operate in UTC instead. I've changed timestamp_to_http as well just to be safe: I think this may fix a potential issue with the value we send for If-Modified-Since, as datetime.fromtimestamp() gives localtime. This was manifesting as a warning with --getbinpkg: > [gentoobinhost] WARNING: Service distfiles.gentoo.org did not respect If-Modified-Since. > Consider asking the service operator to enable support for If-Modified-Since or > using another service (local: 2025-09-12T12:43:46+01:00, remote: 2025-09-12T11:43:46+01:00). ... which would disappear when using TZ=UTC. Bug: https://bugs.gentoo.org/962832 Part-of: https://github.com/gentoo/portage/pull/1467 Closes: https://github.com/gentoo/portage/pull/1467 Signed-off-by: Sam James gentoo.org> lib/portage/util/_urlopen.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/lib/portage/util/_urlopen.py b/lib/portage/util/_urlopen.py index 72801b43ba..68403037ce 100644 --- a/lib/portage/util/_urlopen.py +++ b/lib/portage/util/_urlopen.py @@ -3,8 +3,7 @@ import io from datetime import datetime -from time import mktime -from email.utils import formatdate, parsedate +from email.utils import formatdate, parsedate_tz, mktime_tz from urllib.request import urlopen as _urlopen import urllib.parse as urllib_parse import urllib.request as urllib_request @@ -68,12 +67,12 @@ def urlopen(url, timeout=10, if_modified_since=None, headers={}, proxies=None): def timestamp_to_http(timestamp): dt = datetime.fromtimestamp(float(int(timestamp) + TIMESTAMP_TOLERANCE)) - stamp = mktime(dt.timetuple()) + stamp = mktime_tz(dt.timetuple()) return formatdate(timeval=stamp, localtime=False, usegmt=True) def http_to_timestamp(http_datetime_string): - timestamp = mktime(parsedate(http_datetime_string)) + timestamp = mktime_tz(parsedate_tz(http_datetime_string)) return str(int(timestamp))