commit:     14a21e6e4a6c5ef9ad9f84bae6b65fff5c00fdda
Author:     Sam James <sam <AT> gentoo <DOT> org>
AuthorDate: Fri Dec 26 18:23:04 2025 +0000
Commit:     Sam James <sam <AT> gentoo <DOT> org>
CommitDate: Fri Dec 26 18:57:02 2025 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=14a21e6e

Always wrap binpkg verification failures in eerror

Use the same logic as from 08a2bc3800ea2e997716903244ec041339b45b06. This
also fixes that in some cases, we weren't emitting gpg output at all,
just 'GPG verify failed'.

Bug: https://bugs.gentoo.org/927632
Bug: https://bugs.gentoo.org/936322
Bug: https://bugs.gentoo.org/941770
Signed-off-by: Sam James <sam <AT> gentoo.org>

 lib/_emerge/Scheduler.py | 41 +++++++++++++++++++++++++++++------------
 lib/portage/gpkg.py      | 38 +++++++++++++++++++++++++-------------
 2 files changed, 54 insertions(+), 25 deletions(-)

diff --git a/lib/_emerge/Scheduler.py b/lib/_emerge/Scheduler.py
index fa45b50c0f..b5c283bb09 100644
--- a/lib/_emerge/Scheduler.py
+++ b/lib/_emerge/Scheduler.py
@@ -2,6 +2,7 @@
 # Distributed under the terms of the GNU General Public License v2
 
 from collections import deque
+import io
 import gc
 import gzip
 import logging
@@ -1001,19 +1002,35 @@ class Scheduler(PollScheduler):
                     if fetched and bintree.get_local_repo_location(x.cpv):
                         os.rename(fetched, fetcher.pkg_allocated_path)
                     elif fetched:
-                        if not bintree.inject(
-                            x.cpv,
-                            current_pkg_path=fetched,
-                            allocated_pkg_path=fetcher.pkg_allocated_path,
-                        ):
-                            eerror(
-                                "Binary package is not usable",
-                                phase="pretend",
-                                key=x.cpv,
+                        injected_pkg = None
+                        stdout_orig = sys.stdout
+                        stderr_orig = sys.stderr
+                        out = io.StringIO()
+                        try:
+                            sys.stdout = out
+                            sys.stderr = out
+
+                            injected_pkg = bintree.inject(
+                                x.cpv,
+                                current_pkg_path=fetched,
+                                allocated_pkg_path=fetcher.pkg_allocated_path,
                             )
-                            failures += 1
-                            self._record_pkg_failure(x, settings, 1)
-                            continue
+                        finally:
+                            sys.stdout = stdout_orig
+                            sys.stderr = stderr_orig
+
+                        output_value = out.getvalue()
+                        if output_value:
+                            if injected_pkg is None:
+                                msg = ["Binary package is not usable:"]
+                                msg.extend(
+                                    "\t" + line for line in 
output_value.splitlines()
+                                )
+                                self._elog("eerror", msg)
+
+                        failures += 1
+                        self._record_pkg_failure(x, settings, 1)
+                        continue
 
                     infloc = os.path.join(build_dir_path, "build-info")
                     ensure_dirs(infloc)

diff --git a/lib/portage/gpkg.py b/lib/portage/gpkg.py
index c100c9f666..861476b703 100644
--- a/lib/portage/gpkg.py
+++ b/lib/portage/gpkg.py
@@ -555,11 +555,16 @@ class checksum_helper:
                 trust_signature = True
 
         if (not good_signature) or (not trust_signature):
-            writemsg(
-                colorize(
-                    "BAD", f"!!!\n{self.gpg_result.decode('UTF-8', 
errors='replace')}"
-                )
+            msg = ["Binary package is not usable:"]
+            msg.extend(
+                "\t" + line
+                for line in self.gpg_result.decode(
+                    "UTF-8", errors="replace"
+                ).splitlines()
             )
+            out = portage.output.EOutput()
+            [out.eerror(line) for line in msg]
+
             raise InvalidSignature("GPG verify failed")
 
     def update(self, data):
@@ -599,18 +604,25 @@ class checksum_helper:
                 if self.gpg_operation == checksum_helper.VERIFY:
                     self._check_gpg_status(self.gpg_result)
             else:
-                writemsg(
-                    colorize(
-                        "BAD",
-                        f"!!!\n{self.gpg_result.decode('UTF-8', 
errors='replace')}",
-                    )
+                msg = ["Binary package is not usable:"]
+                msg.extend(
+                    "\t" + line
+                    for line in self.gpg_result.decode(
+                        "UTF-8", errors="replace"
+                    ).splitlines()
                 )
+                out = portage.output.EOutput()
+                [out.eerror(line) for line in msg]
+
                 if self.gpg_operation == checksum_helper.SIGNING:
-                    writemsg(
-                        colorize(
-                            "BAD", self.gpg_output.decode("UTF-8", 
errors="replace")
-                        )
+                    msg = ["Binary package is not usable (signing failed):"]
+                    msg.extend(
+                        "\t" + line
+                        for line in self.gpg_output.decode(
+                            "UTF-8", errors="replace"
+                        ).splitlines()
                     )
+                    [out.eerror(line) for line in msg]
                     raise GPGException("GPG signing failed")
                 elif self.gpg_operation == checksum_helper.VERIFY:
                     raise InvalidSignature("GPG verify failed")

Reply via email to