Skip to content

Commit 790bdef

Browse files
committed
dependencies: fix graph_reverse_depends crash on Atom.intersects
Atom.intersects() type-checks its argument since portage removed str subtyping from Atom, so it needs a real Atom object, not a Dependencies (a Query subclass) or a plain string. graph_reverse_depends() called dep.intersects(self) where self is a Dependencies object. Pass self.atom instead, but that then exposed a second bug: gentoolkit.atom.Atom.__init__ sets self.atom to the raw atom string it was constructed from (used by __repr__/__str__). Query.__init__ copied that string into self.atom via __dict__.update(), and its fallback except branch set self.atom = self.cpv (also a plain string), so Query.atom was never actually usable as an Atom. Fix both: restore self.atom to the real Atom object in the success path, and construct one from self.cpv in the fallback path. Bug: https://bugs.gentoo.org/981521 Signed-off-by: Matt Turner <mattst88@gentoo.org>
1 parent bbc768d commit 790bdef

2 files changed

Lines changed: 12 additions & 2 deletions

File tree

pym/gentoolkit/dependencies.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ def graph_reverse_depends(
236236

237237
found_match = False
238238
for dep in pkgdep.get_all_depends():
239-
if dep.intersects(self):
239+
if dep.intersects(self.atom):
240240
pkgdep.depatom = dep
241241
pkgdep.depth = depth
242242
yield pkgdep

pym/gentoolkit/query.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,10 @@ def __init__(self, query, is_regex=False):
6060
try:
6161
atom = Atom(self.query)
6262
self.__dict__.update(atom.__dict__)
63+
# gentoolkit.atom.Atom.__init__ sets self.atom to the raw
64+
# atom string (for __repr__/__str__), clobbering what should
65+
# be a reference to the Atom object itself; restore it.
66+
self.atom = atom
6367
# portage.dep.Atom uses __slots__, so cpv, _cp, and _version
6468
# are absent from atom.__dict__; initialize them explicitly so
6569
# CPV's lazy property accessors don't raise AttributeError.
@@ -75,7 +79,13 @@ def __init__(self, query, is_regex=False):
7579
except errors.GentoolkitInvalidAtom:
7680
CPV.__init__(self, self.query)
7781
self.operator = ""
78-
self.atom = self.cpv
82+
# self.cpv may contain glob/regex wildcards (e.g. from a
83+
# regex query), which aren't valid atom syntax; fall back to
84+
# the plain string in that case.
85+
try:
86+
self.atom = Atom(f"={self.cpv}")
87+
except errors.GentoolkitInvalidAtom:
88+
self.atom = self.cpv
7989

8090
def __repr__(self):
8191
rx = ""

0 commit comments

Comments
 (0)