[gentoo-commits] proj/portage:master commit in: /, lib/portage/dbapi/, lib/portage/tests/dbapi/, lib/_emerge/, ...

2023-11-06 Thread Sam James
commit: 6ae45739e208b7a9d59e0b6056be72a5791aae04
Author: Sam James  gentoo  org>
AuthorDate: Mon Nov  6 17:07:10 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Mon Nov  6 17:25:04 2023 +
URL:https://gitweb.gentoo.org/proj/portage.git/commit/?id=6ae45739

bintree: don't call trust helper with --pretend

Trust helpers are likely to need privileges and it's a bit too far for pretend
there, I think. People can run it manually if they want it done for them anyway.

We could check writable instead but I'd like to get a fix in for the regression
first.

Bug: https://bugs.gentoo.org/915842
Signed-off-by: Sam James  gentoo.org>

 NEWS |  3 +++
 lib/_emerge/actions.py   |  3 +++
 lib/portage/dbapi/bintree.py | 14 +++---
 lib/portage/tests/dbapi/test_bintree.py  |  6 --
 lib/portage/tests/emerge/test_actions.py |  4 +++-
 5 files changed, 24 insertions(+), 6 deletions(-)

diff --git a/NEWS b/NEWS
index 89d9335275..654b3175f0 100644
--- a/NEWS
+++ b/NEWS
@@ -17,6 +17,9 @@ Bug fixes:
 
 * Avoid crash with blockers in depgraph for binpkg-respect-use notice (bug 
#916336).
 
+* Don't call trust helper (e.g. getuto) with --getbinpkg --pretend as we may
+  lack privileges to do anything (bug #915842).
+
 portage-3.0.54 (2023-10-25)
 --
 

diff --git a/lib/_emerge/actions.py b/lib/_emerge/actions.py
index 323fde3767..07d477a046 100644
--- a/lib/_emerge/actions.py
+++ b/lib/_emerge/actions.py
@@ -174,6 +174,7 @@ def action_build(
 kwargs["add_repos"] = (quickpkg_vardb,)
 
 try:
+kwargs["pretend"] = "--pretend" in emerge_config.opts
 emerge_config.target_config.trees["bintree"].populate(
 getbinpkgs="--getbinpkg" in emerge_config.opts, **kwargs
 )
@@ -3472,6 +3473,8 @@ def run_action(emerge_config):
 emerge_config.running_config.trees["vartree"].dbapi,
 )
 
+kwargs["pretend"] = "--pretend" in emerge_config.opts
+
 try:
 mytrees["bintree"].populate(
 getbinpkgs="--getbinpkg" in emerge_config.opts,

diff --git a/lib/portage/dbapi/bintree.py b/lib/portage/dbapi/bintree.py
index 0ecfdc25d0..6446fde95a 100644
--- a/lib/portage/dbapi/bintree.py
+++ b/lib/portage/dbapi/bintree.py
@@ -831,6 +831,7 @@ class binarytree:
 add_repos=(),
 force_reindex=False,
 invalid_errors=True,
+pretend=False,
 ):
 """
 Populates the binarytree with package metadata.
@@ -844,6 +845,10 @@ class binarytree:
 @type add_repos: sequence
 """
 
+# TODO: Should we return here if we're --pretend? On the one hand,
+# people might not want --pretend to affect state. On the other hand,
+# it makes --pretend pretty useless with --getbinpkg as your index will
+# be stale.
 if self._populating:
 return
 
@@ -898,7 +903,9 @@ class binarytree:
 noiselevel=-1,
 )
 else:
-self._populate_remote(getbinpkg_refresh=getbinpkg_refresh)
+self._populate_remote(
+getbinpkg_refresh=getbinpkg_refresh, pretend=pretend
+)
 
 finally:
 self._populating = False
@@ -1290,7 +1297,7 @@ class binarytree:
 return
 ret.check_returncode()
 
-def _populate_remote(self, getbinpkg_refresh=True):
+def _populate_remote(self, getbinpkg_refresh=True, pretend=False):
 self._remote_has_index = False
 self._remotepkgs = {}
 
@@ -1299,7 +1306,8 @@ class binarytree:
 # when binpackages are involved, not only when we refuse unsigned
 # ones. (If the keys have expired we end up refusing signed but
 # technically invalid packages...)
-self._run_trust_helper()
+if not pretend:
+self._run_trust_helper()
 gpkg_only = True
 else:
 gpkg_only = False

diff --git a/lib/portage/tests/dbapi/test_bintree.py 
b/lib/portage/tests/dbapi/test_bintree.py
index 5a6ee5b142..0aa411ad97 100644
--- a/lib/portage/tests/dbapi/test_bintree.py
+++ b/lib/portage/tests/dbapi/test_bintree.py
@@ -120,7 +120,9 @@ class BinarytreeTestCase(TestCase):
 settings.__getitem__.return_value = "/some/path"
 bt = binarytree(pkgdir=os.getenv("TMPDIR", "/tmp"), settings=settings)
 bt.populate(getbinpkgs=True, getbinpkg_refresh=refresh)
-ppopulate_remote.assert_called_once_with(getbinpkg_refresh=refresh)
+ppopulate_remote.assert_called_once_with(
+getbinpkg_refresh=refresh, pretend=False
+)
 
 @patch("portage.dbapi.bintree.writemsg")
 @patch("portage.dbapi.bintree.BinRepoConfigLoader")
@@ -161,4 +163,4 @@ class BinarytreeTestCase(TestCase):
 

[gentoo-commits] proj/portage:master commit in: lib/portage/dbapi/, lib/portage/tests/dbapi/

2023-10-07 Thread Sam James
commit: c53d046c9629d5c3a7841aee4e92ae38c0691e69
Author: Siddhanth Rathod  gmail  com>
AuthorDate: Thu Oct  5 13:22:52 2023 +
Commit: Sam James  gentoo  org>
CommitDate: Sun Oct  8 03:29:46 2023 +
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  gmail.com>
Closes: https://github.com/gentoo/portage/pull/1123
Signed-off-by: Sam James  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