From 159ee690a098414efeb6f01d9124fc534c51ca4b Mon Sep 17 00:00:00 2001 From: AdmiringWorm Date: Wed, 24 May 2023 11:56:41 +0200 Subject: [PATCH] (#3165) Update count method to support nuget service This commit updates the Count method that is used to get the amount of packages available on normal and alternative sources to include support for the nuget service. During a previous refactor we had removed the support of acquiring packages on normal sources by a mistake, which causes an issue with Chocolatey GUI to fail due to no available source runner can be found when dealing with counting packages. This was fixed by including an explicit call to the nuget service when norrmal sources are being used. --- .../services/ChocolateyPackageService.cs | 20 ++++++++----------- 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 7567d503b2..21912f20ac 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -137,6 +137,11 @@ public ChocolateyPackageService( public virtual int Count(ChocolateyConfiguration config) { + if (config.SourceType.IsEqualTo(SourceTypes.Normal)) + { + return _nugetService.Count(config); + } + return PerformSourceRunnerFunction( config, runner => runner.Count(config), @@ -153,7 +158,7 @@ private void PerformSourceRunnerAction(ChocolateyConfiguration co private void PerformSourceRunnerAction(ChocolateyConfiguration config, Action action, IEnumerable alternativeSourceRunners, bool throwOnException = false) where TSourceRunner : class, IAlternativeSourceRunner { - var runner = GetSourceRunner(config.SourceType, alternativeSourceRunners); + var runner = GetSourceRunner(config.SourceType, alternativeSourceRunners); if (runner != null && action != null) { if (runner is IBootstrappableSourceRunner bootstrapper) @@ -186,7 +191,7 @@ private TResult PerformSourceRunnerFunction(ChocolateyCo private TResult PerformSourceRunnerFunction(ChocolateyConfiguration config, Func function, IEnumerable alternativeSourceRunners, bool throwOnException = false) where TSourceRunner : class, IAlternativeSourceRunner { - var runner = GetSourceRunner(config.SourceType, alternativeSourceRunners); + var runner = GetSourceRunner(config.SourceType, alternativeSourceRunners); if (runner != null && function != null) { if (runner is IBootstrappableSourceRunner bootstrapper) @@ -209,7 +214,7 @@ private TResult PerformSourceRunnerFunction(ChocolateyCo this.Log().Warn("No runner was found that implements source type '{0}' or, it does not support requested functionality.".FormatWith(config.SourceType)); } - return default(TResult); + return default; } public void ListDryRun(ChocolateyConfiguration config) @@ -1795,15 +1800,6 @@ private void LogEnvironmentChanges(ChocolateyConfiguration config, IEnumerable(string sourceType) - where TSourceRunner : class, IAlternativeSourceRunner - { - // We add the trailing s to the check in case of windows feature which can be specified both with and without - // the s. - var sourceRunners = _containerResolver.ResolveAll(); - return GetSourceRunner(sourceType, sourceRunners); - } - private TSourceRunner GetSourceRunner(string sourceType, IEnumerable alternativeSourceRunners) where TSourceRunner : class, IAlternativeSourceRunner {