repo.py: drop deleted packages from provider cache (#43779)

The reverse provider lookup may have stale entries for deleted packages, which used to cause errors. It's hard to invalidate those cache entries, so this commit simply drops entries w/o invalidating the cache.

Co-authored-by: Massimiliano Culpo <massimiliano.culpo@gmail.com>
This commit is contained in:
Harmen Stoppels 2024-04-22 19:03:44 +02:00 committed by GitHub
parent e1f2612581
commit d6baae525f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -726,14 +726,14 @@ def first_repo(self):
"""Get the first repo in precedence order.""" """Get the first repo in precedence order."""
return self.repos[0] if self.repos else None return self.repos[0] if self.repos else None
@llnl.util.lang.memoized
def _all_package_names_set(self, include_virtuals):
return {name for repo in self.repos for name in repo.all_package_names(include_virtuals)}
@llnl.util.lang.memoized @llnl.util.lang.memoized
def _all_package_names(self, include_virtuals): def _all_package_names(self, include_virtuals):
"""Return all unique package names in all repositories.""" """Return all unique package names in all repositories."""
all_pkgs = set() return sorted(self._all_package_names_set(include_virtuals), key=lambda n: n.lower())
for repo in self.repos:
for name in repo.all_package_names(include_virtuals):
all_pkgs.add(name)
return sorted(all_pkgs, key=lambda n: n.lower())
def all_package_names(self, include_virtuals=False): def all_package_names(self, include_virtuals=False):
return self._all_package_names(include_virtuals) return self._all_package_names(include_virtuals)
@ -794,7 +794,11 @@ def patch_index(self):
@autospec @autospec
def providers_for(self, vpkg_spec): def providers_for(self, vpkg_spec):
providers = self.provider_index.providers_for(vpkg_spec) providers = [
spec
for spec in self.provider_index.providers_for(vpkg_spec)
if spec.name in self._all_package_names_set(include_virtuals=False)
]
if not providers: if not providers:
raise UnknownPackageError(vpkg_spec.fullname) raise UnknownPackageError(vpkg_spec.fullname)
return providers return providers