commit: 57ed35228b06e035e9ecfeda5b2c96a02f69151e Author: Florian Schmaus <flow <AT> gentoo <DOT> org> AuthorDate: Fri Sep 12 12:36:51 2025 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Fri Sep 12 21:17:57 2025 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=57ed3522
bintree: Emit warning if binhost did not respect If-Modified-Since It appears some binhost (mirrors) do not respect If-Modified-Since [1]. Warn the user about those. 1: https://bugs.gentoo.org/962557#c11 Bug: https://bugs.gentoo.org/962557 Signed-off-by: Florian Schmaus <flow <AT> gentoo.org> Part-of: https://github.com/gentoo/portage/pull/1461 Closes: https://github.com/gentoo/portage/pull/1461 Signed-off-by: Sam James <sam <AT> gentoo.org> lib/portage/dbapi/bintree.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/lib/portage/dbapi/bintree.py b/lib/portage/dbapi/bintree.py index 4009f76e6f..46f5e7f8b9 100644 --- a/lib/portage/dbapi/bintree.py +++ b/lib/portage/dbapi/bintree.py @@ -1465,10 +1465,40 @@ class binarytree: if_modified_since=local_timestamp, proxies=proxies, ) - if hasattr(f, "headers") and f.headers.get( - "timestamp", "" + if hasattr(f, "headers"): + if f.headers.get("timestamp", ""): + remote_timestamp = f.headers.get("timestamp") + elif f.headers.get("Last-Modified", ""): + last_modified = err.headers.get("Last-Modified") + remote_timestamp = http_to_timestamp( + last_modified + ) + if ( + remote_timestamp + and local_timestamp + and int(remote_timestamp) < int(local_timestamp) ): - remote_timestamp = f.headers.get("timestamp") + msg = ( + f"[{binrepo_name}] WARNING: Service {host} did not respect If-Modified-Since." + f" Consider asking the service operator to enable support for" + f" If-Modified-Since or using another service" + ) + extra_info = "" + if 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})" + writemsg( + colorize( + "WARN", + f"{msg}{extra_info}.\n", + ), + noiselevel=-1, + ) except OSError as err: if ( hasattr(err, "code") and err.code == 304
