Skip to content

Commit

Permalink
(chocolatey#3165) Update count method to support nuget service
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
AdmiringWorm committed May 24, 2023
1 parent 89c8c9c commit 159ee69
Showing 1 changed file with 8 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ public ChocolateyPackageService(

public virtual int Count(ChocolateyConfiguration config)
{
if (config.SourceType.IsEqualTo(SourceTypes.Normal))
{
return _nugetService.Count(config);
}

return PerformSourceRunnerFunction<ICountSourceRunner, int>(
config,
runner => runner.Count(config),
Expand All @@ -153,7 +158,7 @@ private void PerformSourceRunnerAction<TSourceRunner>(ChocolateyConfiguration co
private void PerformSourceRunnerAction<TSourceRunner>(ChocolateyConfiguration config, Action<TSourceRunner> action, IEnumerable<TSourceRunner> alternativeSourceRunners, bool throwOnException = false)
where TSourceRunner : class, IAlternativeSourceRunner
{
var runner = GetSourceRunner<TSourceRunner>(config.SourceType, alternativeSourceRunners);
var runner = GetSourceRunner(config.SourceType, alternativeSourceRunners);
if (runner != null && action != null)
{
if (runner is IBootstrappableSourceRunner bootstrapper)
Expand Down Expand Up @@ -186,7 +191,7 @@ private TResult PerformSourceRunnerFunction<TSourceRunner, TResult>(ChocolateyCo
private TResult PerformSourceRunnerFunction<TSourceRunner, TResult>(ChocolateyConfiguration config, Func<TSourceRunner, TResult> function, IEnumerable<TSourceRunner> alternativeSourceRunners, bool throwOnException = false)
where TSourceRunner : class, IAlternativeSourceRunner
{
var runner = GetSourceRunner<TSourceRunner>(config.SourceType, alternativeSourceRunners);
var runner = GetSourceRunner(config.SourceType, alternativeSourceRunners);
if (runner != null && function != null)
{
if (runner is IBootstrappableSourceRunner bootstrapper)
Expand All @@ -209,7 +214,7 @@ private TResult PerformSourceRunnerFunction<TSourceRunner, TResult>(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)
Expand Down Expand Up @@ -1795,15 +1800,6 @@ private void LogEnvironmentChanges(ChocolateyConfiguration config, IEnumerable<G
}
}

private TSourceRunner GetSourceRunner<TSourceRunner>(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<TSourceRunner>();
return GetSourceRunner(sourceType, sourceRunners);
}

private TSourceRunner GetSourceRunner<TSourceRunner>(string sourceType, IEnumerable<TSourceRunner> alternativeSourceRunners)
where TSourceRunner : class, IAlternativeSourceRunner
{
Expand Down

0 comments on commit 159ee69

Please sign in to comment.