From 7bd79e444a65d5b07f382997a1ad4d2b96f68f28 Mon Sep 17 00:00:00 2001 From: AdmiringWorm Date: Mon, 27 May 2024 10:50:38 +0200 Subject: [PATCH] (#3433) Add overload for FindPackages method It was found later when including Chocolatey Licensed Extension that it would fail to load due to the change to the base source cache context. As such this commit updates the public API in this case to add the old method as a deprecated overload. --- .../infrastructure.app/nuget/NugetList.cs | 24 ++++++++++++++++++- .../services/NugetService.cs | 6 ++--- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/chocolatey/infrastructure.app/nuget/NugetList.cs b/src/chocolatey/infrastructure.app/nuget/NugetList.cs index 0111f65015..6048a023fa 100644 --- a/src/chocolatey/infrastructure.app/nuget/NugetList.cs +++ b/src/chocolatey/infrastructure.app/nuget/NugetList.cs @@ -248,7 +248,7 @@ private async static Task> SearchPackagesAsyn } else { - var exactPackage = FindPackage(searchTermLower, configuration, nugetLogger, cacheContext, packageRepositoryResources, version); + var exactPackage = FindPackage(searchTermLower, configuration, nugetLogger, (SourceCacheContext)cacheContext, packageRepositoryResources, version); if (exactPackage == null) { @@ -342,6 +342,28 @@ public static ISet FindAllPackageVersions(string package return metadataList; } + /// + /// Searches for packages that are available based on name and other options + /// + /// Name of package to search for + /// Chocolatey configuration used to help supply the search parameters + /// The nuget logger + /// The resources that should be queried + /// Version to search for + /// Settings for caching of results from sources + /// One result or nothing + [Obsolete("Use the overload that uses the base source cache context instead.")] + public static IPackageSearchMetadata FindPackage( + string packageName, + ChocolateyConfiguration config, + ILogger nugetLogger, + ChocolateySourceCacheContext cacheContext, + IEnumerable resources, + NuGetVersion version) + { + return FindPackage(packageName, config, nugetLogger, (SourceCacheContext)cacheContext, resources, version); + } + /// /// Searches for packages that are available based on name and other options /// diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index e91910412c..f742d93dc2 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -628,7 +628,7 @@ public virtual ConcurrentDictionary Install(ChocolateyCon latestPackageVersion = version; } - var availablePackage = NugetList.FindPackage(packageName, config, _nugetLogger, sourceCacheContext, remoteEndpoints, latestPackageVersion); + var availablePackage = NugetList.FindPackage(packageName, config, _nugetLogger, (SourceCacheContext)sourceCacheContext, remoteEndpoints, latestPackageVersion); if (availablePackage == null) { @@ -1149,7 +1149,7 @@ public virtual ConcurrentDictionary Upgrade(ChocolateyCon // this is a prerelease - opt in for newer prereleases. config.Prerelease = true; } - var availablePackage = NugetList.FindPackage(packageName, config, _nugetLogger, sourceCacheContext, remoteEndpoints, version); + var availablePackage = NugetList.FindPackage(packageName, config, _nugetLogger, (SourceCacheContext)sourceCacheContext, remoteEndpoints, version); config.Prerelease = originalPrerelease; @@ -1334,7 +1334,7 @@ public virtual ConcurrentDictionary Upgrade(ChocolateyCon { if (version != null) { - var requestedPackageDependency = NugetList.FindPackage(parentPackage.Id, config, _nugetLogger, sourceCacheContext, remoteEndpoints, version); + var requestedPackageDependency = NugetList.FindPackage(parentPackage.Id, config, _nugetLogger, (SourceCacheContext)sourceCacheContext, remoteEndpoints, version); if (requestedPackageDependency != null) {