Skip to content

Commit

Permalink
(#3433) Add overload for FindPackages method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AdmiringWorm committed May 27, 2024
1 parent 3c93860 commit cf9648e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 4 deletions.
24 changes: 23 additions & 1 deletion src/chocolatey/infrastructure.app/nuget/NugetList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private async static Task<IQueryable<IPackageSearchMetadata>> SearchPackagesAsyn
}
else
{
var exactPackage = FindPackage(searchTermLower, configuration, nugetLogger, cacheContext, packageRepositoryResources, version);
var exactPackage = FindPackage(searchTermLower, configuration, nugetLogger, (SourceCacheContext)cacheContext, packageRepositoryResources, version);

if (exactPackage == null)
{
Expand Down Expand Up @@ -342,6 +342,28 @@ public static ISet<IPackageSearchMetadata> FindAllPackageVersions(string package
return metadataList;
}

/// <summary>
/// Searches for packages that are available based on name and other options
/// </summary>
/// <param name="packageName">Name of package to search for</param>
/// <param name="config">Chocolatey configuration used to help supply the search parameters</param>
/// <param name="nugetLogger">The nuget logger</param>
/// <param name="resources">The resources that should be queried</param>
/// <param name="version">Version to search for</param>
/// <param name="cacheContext">Settings for caching of results from sources</param>
/// <returns>One result or nothing</returns>
[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<NuGetEndpointResources> resources,
NuGetVersion version)
{
return FindPackage(packageName, config, nugetLogger, (SourceCacheContext)cacheContext, resources, version);
}

/// <summary>
/// Searches for packages that are available based on name and other options
/// </summary>
Expand Down
6 changes: 3 additions & 3 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ public virtual ConcurrentDictionary<string, PackageResult> 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)
{
Expand Down Expand Up @@ -1149,7 +1149,7 @@ public virtual ConcurrentDictionary<string, PackageResult> 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;

Expand Down Expand Up @@ -1334,7 +1334,7 @@ public virtual ConcurrentDictionary<string, PackageResult> 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)
{
Expand Down

0 comments on commit cf9648e

Please sign in to comment.