commit: c53d046c9629d5c3a7841aee4e92ae38c0691e69 Author: Siddhanth Rathod <xsiddhanthrathod <AT> gmail <DOT> com> AuthorDate: Thu Oct 5 13:22:52 2023 +0000 Commit: Sam James <sam <AT> gentoo <DOT> org> CommitDate: Sun Oct 8 03:29:46 2023 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=c53d046c
dbapi: bintree: introduce invalid_errors Introduce 'invalid_errors' var to enable suppression of invalid binary error, for use by gentoolkit. [sam: See gentoolkit side at https://github.com/gentoo/gentoolkit/pull/35]. Bug: https://bugs.gentoo.org/900224 Signed-off-by: Siddhanth Rathod <xsiddhanthrathod <AT> gmail.com> Closes: https://github.com/gentoo/portage/pull/1123 Signed-off-by: Sam James <sam <AT> gentoo.org> lib/portage/dbapi/bintree.py | 60 +++++++++++++++++++-------------- lib/portage/tests/dbapi/test_bintree.py | 6 ++-- 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/lib/portage/dbapi/bintree.py b/lib/portage/dbapi/bintree.py index 580ce2f290..7a4166c120 100644 --- a/lib/portage/dbapi/bintree.py +++ b/lib/portage/dbapi/bintree.py @@ -809,6 +809,7 @@ class binarytree: getbinpkg_refresh=False, add_repos=(), force_reindex=False, + invalid_errors=True, ): """ Populates the binarytree with package metadata. @@ -839,7 +840,8 @@ class binarytree: try: update_pkgindex = self._populate_local( reindex="pkgdir-index-trusted" not in self.settings.features - or force_reindex + or force_reindex, + invalid_errors=invalid_errors, ) if update_pkgindex and self.dbapi.writable: @@ -882,7 +884,7 @@ class binarytree: self.populated = True - def _populate_local(self, reindex=True): + def _populate_local(self, reindex=True, invalid_errors=True): """ Populates the binarytree with local package metadata. @@ -1019,11 +1021,15 @@ class binarytree: self.dbapi.cpv_inject(mycpv) continue if not os.access(full_path, os.R_OK): - writemsg( - _("!!! Permission denied to read " "binary package: '%s'\n") - % full_path, - noiselevel=-1, - ) + if invalid_errors: + writemsg( + _( + "!!! Permission denied to read " + "binary package: '%s'\n" + ) + % full_path, + noiselevel=-1, + ) self.invalids.append(myfile[:-5]) self.invalid_paths[myfile] = [full_path] continue @@ -1062,10 +1068,11 @@ class binarytree: binpkg_format=binpkg_format, ) except (PortagePackageException, SignatureException) as e: - writemsg( - f"!!! Invalid binary package: '{full_path}', {e}\n", - noiselevel=-1, - ) + if invalid_errors: + writemsg( + f"!!! Invalid binary package: '{full_path}', {e}\n", + noiselevel=-1, + ) self.invalid_paths[mypkg] = [full_path] continue mycat = pkg_metadata.get("CATEGORY", "") @@ -1073,10 +1080,11 @@ class binarytree: slot = pkg_metadata.get("SLOT", "") if not mycat or not mypf or not slot: # old-style or corrupt package - writemsg( - _("\n!!! Invalid binary package: '%s'\n") % full_path, - noiselevel=-1, - ) + if invalid_errors: + writemsg( + _("\n!!! Invalid binary package: '%s'\n") % full_path, + noiselevel=-1, + ) missing_keys = [] if not mycat: missing_keys.append("CATEGORY") @@ -1087,18 +1095,20 @@ class binarytree: msg = [] if missing_keys: missing_keys.sort() + if invalid_errors: + msg.append( + _("Missing metadata key(s): %s.") + % ", ".join(missing_keys) + ) + if invalid_errors: msg.append( - _("Missing metadata key(s): %s.") - % ", ".join(missing_keys) - ) - msg.append( - _( - " This binary package is not " - "recoverable and should be deleted." + _( + " This binary package is not " + "recoverable and should be deleted." + ) ) - ) - for line in textwrap.wrap("".join(msg), 72): - writemsg(f"!!! {line}\n", noiselevel=-1) + for line in textwrap.wrap("".join(msg), 72): + writemsg(f"!!! {line}\n", noiselevel=-1) self.invalids.append(mypkg) self.invalid_paths[mypkg] = [full_path] continue diff --git a/lib/portage/tests/dbapi/test_bintree.py b/lib/portage/tests/dbapi/test_bintree.py index 60785b4e59..5a6ee5b142 100644 --- a/lib/portage/tests/dbapi/test_bintree.py +++ b/lib/portage/tests/dbapi/test_bintree.py @@ -87,7 +87,7 @@ class BinarytreeTestCase(TestCase): bt = binarytree(pkgdir=os.getenv("TMPDIR", "/tmp"), settings=MagicMock()) ppopulate_local.return_value = {} bt.populate() - ppopulate_local.assert_called_once_with(reindex=True) + ppopulate_local.assert_called_once_with(reindex=True, invalid_errors=True) self.assertFalse(bt._populating) self.assertTrue(bt.populated) @@ -95,7 +95,9 @@ class BinarytreeTestCase(TestCase): def test_populate_calls_twice_populate_local_if_updates(self, ppopulate_local): bt = binarytree(pkgdir=os.getenv("TMPDIR", "/tmp"), settings=MagicMock()) bt.populate() - self.assertIn(call(reindex=True), ppopulate_local.mock_calls) + self.assertIn( + call(reindex=True, invalid_errors=True), ppopulate_local.mock_calls + ) self.assertIn(call(), ppopulate_local.mock_calls) self.assertEqual(ppopulate_local.call_count, 2)
