Fix iterator invalidation issues.
This commit is contained in:
parent
4de45c2684
commit
5e5024342f
@ -50,9 +50,10 @@ class ProviderIndex(object):
|
|||||||
matching implementation of MPI.
|
matching implementation of MPI.
|
||||||
"""
|
"""
|
||||||
def __init__(self, specs=None, **kwargs):
|
def __init__(self, specs=None, **kwargs):
|
||||||
# TODO: come up with another name for this. This "restricts" values to
|
# TODO: come up with another name for this. This "restricts"
|
||||||
# the verbatim impu specs (i.e., it doesn't pre-apply package's constraints, and
|
# values to the verbatim impu specs (i.e., it doesn't
|
||||||
# keeps things as broad as possible, so it's really the wrong name)
|
# pre-apply package's constraints, and keeps things as broad
|
||||||
|
# as possible, so it's really the wrong name)
|
||||||
if specs is None: specs = []
|
if specs is None: specs = []
|
||||||
self.restrict = kwargs.setdefault('restrict', False)
|
self.restrict = kwargs.setdefault('restrict', False)
|
||||||
|
|
||||||
@ -229,15 +230,23 @@ def merge(self, other):
|
|||||||
|
|
||||||
def remove_provider(self, pkg_name):
|
def remove_provider(self, pkg_name):
|
||||||
"""Remove a provider from the ProviderIndex."""
|
"""Remove a provider from the ProviderIndex."""
|
||||||
for pkg in self.providers:
|
empty_pkg_dict = []
|
||||||
pkg_dict = self.providers[pkg]
|
for pkg, pkg_dict in self.providers.items():
|
||||||
|
empty_pset = []
|
||||||
for provided, pset in pkg_dict.items():
|
for provided, pset in pkg_dict.items():
|
||||||
for provider in pset:
|
same_name = set(p for p in pset if p.fullname == pkg_name)
|
||||||
if provider.fullname == pkg_name:
|
pset.difference_update(same_name)
|
||||||
pset.remove(provider)
|
|
||||||
if not pset:
|
if not pset:
|
||||||
|
empty_pset.append(provided)
|
||||||
|
|
||||||
|
for provided in empty_pset:
|
||||||
del pkg_dict[provided]
|
del pkg_dict[provided]
|
||||||
|
|
||||||
if not pkg_dict:
|
if not pkg_dict:
|
||||||
|
empty_pkg_dict.append(pkg)
|
||||||
|
|
||||||
|
for pkg in empty_pkg_dict:
|
||||||
del self.providers[pkg]
|
del self.providers[pkg]
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user