public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Sam James" <sam@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: lib/portage/dbapi/
Date: Mon, 15 Sep 2025 11:14:55 +0000 (UTC)	[thread overview]
Message-ID: <1757934877.c83466a50efdee2cac81a5ed6a660c11b9ac746e.sam@gentoo> (raw)

commit:     c83466a50efdee2cac81a5ed6a660c11b9ac746e
Author:     Florian Schmaus <flow <AT> gentoo <DOT> org>
AuthorDate: Mon Sep 15 10:44:48 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Mon Sep 15 11:14:37 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=c83466a5

bintree: Improve UseCachedCopyOfRemoteIndex handling, report if TTL

Move the logic where parts of the user-exposed message is constructed
from the except block to right before we raise the
UseCachedCopyOfRemoteIndex exception. This means we can get rid of
some logic in the except block, which tried to determine what the
cause of the UseCachedCopyOfRemoteIndex exception was.

As benefit, we will no report if the use the cached copy if it is
within its TTL.

Signed-off-by: Florian Schmaus <flow <AT> gentoo.org>
Part-of: https://github.com/gentoo/portage/pull/1469
Signed-off-by: Sam James <sam <AT> gentoo.org>

 lib/portage/dbapi/bintree.py | 33 +++++++++++++++++----------------
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/lib/portage/dbapi/bintree.py b/lib/portage/dbapi/bintree.py
index 8e69fe3b89..4f0d780523 100644
--- a/lib/portage/dbapi/bintree.py
+++ b/lib/portage/dbapi/bintree.py
@@ -84,7 +84,9 @@ from urllib.parse import urlparse
 class UseCachedCopyOfRemoteIndex(Exception):
     # If the local copy is recent enough
     # then fetching the remote index can be skipped.
-    pass
+    def __init__(self, desc: str, extra_info: str = ""):
+        self.desc = desc
+        self.extra_info = extra_info
 
 
 class bindbapi(fakedbapi):
@@ -1427,7 +1429,9 @@ class binarytree:
                     f = None
 
                     if local_timestamp and (repo.frozen or not getbinpkg_refresh):
-                        raise UseCachedCopyOfRemoteIndex()
+                        if repo.frozen:
+                            raise UseCachedCopyOfRemoteIndex("frozen")
+                        raise UseCachedCopyOfRemoteIndex("")
 
                     try:
                         ttl = float(pkgindex.header.get("TTL", 0))
@@ -1439,7 +1443,7 @@ class binarytree:
                             and ttl
                             and download_timestamp + ttl > time.time()
                         ):
-                            raise UseCachedCopyOfRemoteIndex()
+                            raise UseCachedCopyOfRemoteIndex("within TTL")
 
                     # Set proxy settings for _urlopen -> urllib_request
                     proxies = {}
@@ -1508,7 +1512,13 @@ class binarytree:
                                 ):
                                     last_modified = err.headers.get("Last-Modified")
                                     remote_timestamp = http_to_timestamp(last_modified)
-                                raise UseCachedCopyOfRemoteIndex()
+                                    local_iso_time = unix_to_iso_time(local_timestamp)
+                                    remote_iso_time = unix_to_iso_time(remote_timestamp)
+                                    extra_info = f" (local: {local_iso_time}, remote: {remote_iso_time})"
+
+                                raise UseCachedCopyOfRemoteIndex(
+                                    "up-to-date", extra_info
+                                )
 
                             if parsed_url.scheme in ("ftp", "http", "https"):
                                 # This protocol is supposedly supported by urlopen,
@@ -1647,20 +1657,11 @@ class binarytree:
                     # We successfully fetched the remote index, break
                     # out of the ("Packages.gz", "Packages") loop.
                     break
-                except UseCachedCopyOfRemoteIndex:
+                except UseCachedCopyOfRemoteIndex as exc:
                     changed = False
                     rmt_idx = pkgindex
                     if getbinpkg_refresh or repo.frozen:
-                        extra_info = ""
-                        if repo.frozen:
-                            desc = "frozen"
-                        else:
-                            desc = "up-to-date"
-                            if remote_timestamp and verbose:
-                                local_iso_time = unix_to_iso_time(local_timestamp)
-                                remote_iso_time = unix_to_iso_time(remote_timestamp)
-                                extra_info = f" (local: {local_iso_time}, remote: {remote_iso_time})"
-
+                        extra_info = exc.extra_info if verbose else ""
                         writemsg_stdout("\n")
                         writemsg_stdout(
                             colorize(
@@ -1668,7 +1669,7 @@ class binarytree:
                                 _(
                                     " [%s] Local copy of remote index is %s and will be used%s."
                                 )
-                                % (binrepo_name, desc, extra_info),
+                                % (binrepo_name, exc.desc, extra_info),
                             )
                             + "\n"
                         )


             reply	other threads:[~2025-09-15 11:14 UTC|newest]

Thread overview: 97+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-09-15 11:14 Sam James [this message]
  -- strict thread matches above, loose matches on Subject: below --
2025-11-01 19:54 [gentoo-commits] proj/portage:master commit in: lib/portage/dbapi/ Zac Medico
2025-11-01  9:49 Sam James
2025-11-01  9:49 Sam James
2025-10-30  3:06 Zac Medico
2025-10-28  5:27 Zac Medico
2025-09-16 15:40 Sam James
2025-09-15 12:21 Sam James
2025-09-15 12:21 Sam James
2025-09-15 11:14 Sam James
2025-09-15 11:14 Sam James
2025-09-15 11:14 Sam James
2025-09-14  9:33 Sam James
2025-09-14  0:15 Sam James
2025-09-14  0:15 Sam James
2025-09-12 21:18 Sam James
2025-09-12 21:18 Sam James
2025-09-11 20:37 Sam James
2025-09-11 18:07 Sam James
2025-09-11 11:27 Sam James
2025-09-11  3:17 Sam James
2025-09-11  0:07 Sam James
2025-06-24  1:09 Sam James
2025-06-17  2:58 Sam James
2025-01-24 21:29 Zac Medico
2025-01-09 23:35 Zac Medico
2024-06-01 19:20 Zac Medico
2024-05-27 18:13 Zac Medico
2024-03-02 22:55 Zac Medico
2024-02-25  8:25 Sam James
2024-01-16  7:52 Sam James
2024-01-16  5:26 Zac Medico
2024-01-16  5:16 Sam James
2024-01-16  5:16 Sam James
2024-01-03  5:57 Zac Medico
2023-12-10  1:28 Zac Medico
2023-10-24 18:37 Zac Medico
2023-10-23 14:28 Zac Medico
2023-10-22 21:30 Zac Medico
2023-10-22 20:58 Zac Medico
2023-10-22 15:53 Zac Medico
2023-10-20  0:34 Zac Medico
2023-10-15 22:02 Zac Medico
2023-10-08 19:48 Zac Medico
2023-10-05  5:45 Zac Medico
2023-10-04  4:29 Zac Medico
2023-09-26 21:09 Sam James
2023-09-23 22:49 Sam James
2023-09-23 22:38 Sam James
2023-09-23 22:31 Sam James
2023-09-20 18:02 Mike Gilbert
2023-09-15  4:28 Sam James
2023-07-29  3:57 Sam James
2023-05-23  0:26 Sam James
2023-05-23  0:26 Sam James
2023-05-23  0:26 Sam James
2022-12-21  1:30 Sam James
2022-12-21  1:28 Sam James
2022-11-08 23:07 Sam James
2022-09-25 19:12 Mike Gilbert
2022-09-09 10:16 Michał Górny
2022-08-18 19:00 Mike Gilbert
2022-04-20 20:24 Zac Medico
2022-04-13 15:34 Sam James
2022-04-13 15:34 Sam James
2021-11-26 21:09 Mike Gilbert
2021-09-21  5:51 Zac Medico
2021-09-21  5:51 Zac Medico
2021-09-21  5:51 Zac Medico
2021-06-05 18:08 Zac Medico
2021-03-07 11:42 Zac Medico
2021-02-23 21:31 Zac Medico
2021-01-18  9:20 Zac Medico
2021-01-17 13:31 Zac Medico
2021-01-17  8:49 Zac Medico
2021-01-17  8:49 Zac Medico
2020-09-08  2:52 Zac Medico
2020-08-09  0:15 Zac Medico
2020-08-04  3:16 Zac Medico
2020-08-03 23:28 Zac Medico
2020-08-03 23:28 Zac Medico
2020-08-03 21:42 Zac Medico
2020-08-03 21:42 Zac Medico
2020-08-03 19:30 Zac Medico
2020-07-22 20:14 Zac Medico
2020-07-22 19:52 Zac Medico
2020-07-22 17:46 Zac Medico
2020-06-07  3:26 Zac Medico
2020-02-20  9:55 Zac Medico
2020-02-03  3:04 Zac Medico
2019-08-24  3:15 Zac Medico
2019-06-20 19:43 Zac Medico
2019-05-11 21:16 Zac Medico
2019-01-20  6:55 Zac Medico
2019-01-11 10:14 Fabian Groffen
2018-09-24  7:30 Zac Medico
2018-09-24  0:46 Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1757934877.c83466a50efdee2cac81a5ed6a660c11b9ac746e.sam@gentoo \
    --to=sam@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox