From d6baae525fd3a0ace512f6ffd56b907d8802810c Mon Sep 17 00:00:00 2001 From: Harmen Stoppels Date: Mon, 22 Apr 2024 19:03:44 +0200 Subject: 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 --- lib/spack/spack/repo.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'lib') diff --git a/lib/spack/spack/repo.py b/lib/spack/spack/repo.py index b5f7640baf..9b6f104fe5 100644 --- a/lib/spack/spack/repo.py +++ b/lib/spack/spack/repo.py @@ -726,14 +726,14 @@ class RepoPath: """Get the first repo in precedence order.""" 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 def _all_package_names(self, include_virtuals): """Return all unique package names in all repositories.""" - all_pkgs = set() - 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()) + return sorted(self._all_package_names_set(include_virtuals), key=lambda n: n.lower()) def all_package_names(self, include_virtuals=False): return self._all_package_names(include_virtuals) @@ -794,7 +794,11 @@ class RepoPath: @autospec 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: raise UnknownPackageError(vpkg_spec.fullname) return providers -- cgit v1.2.3-70-g09d2