diff --git a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs index 6accfe2334..a85d9e62e0 100644 --- a/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs +++ b/src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs @@ -339,6 +339,7 @@ Exit codes that normally result from running this command. Normal: - 0: operation was successful, no issues detected - -1 or 1: an error has occurred + - 2: nothing to do, no packages outdated Package Exit Codes: - 1641: success, reboot initiated diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index 132135e417..2717931659 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -617,8 +617,8 @@ public virtual ConcurrentDictionary install_run(Chocolate } finally { - var installFailures = report_action_summary(packageInstalls, "installed"); - if (installFailures != 0 && Environment.ExitCode == 0) + var actionSummaryResults = report_action_summary(packageInstalls, "installed"); + if (actionSummaryResults.Item2 != 0 && Environment.ExitCode == 0) { Environment.ExitCode = 1; } @@ -812,7 +812,7 @@ public void upgrade_noop(ChocolateyConfiguration config) var noopUpgrades = perform_source_runner_function(config, r => r.upgrade_noop(config, action)); if (config.RegularOutput) { - var noopFailures = report_action_summary(noopUpgrades, "can upgrade"); + var actionSummaryResult = report_action_summary(noopUpgrades, "can upgrade"); } randomly_notify_about_pro_business(config); @@ -865,12 +865,17 @@ public virtual ConcurrentDictionary upgrade_run(Chocolate } finally { - var upgradeFailures = report_action_summary(packageUpgrades, "upgraded"); - if (upgradeFailures != 0 && Environment.ExitCode == 0) + var actionSummaryResult = report_action_summary(packageUpgrades, "upgraded"); + if (actionSummaryResult.Item2 != 0 && Environment.ExitCode == 0) { Environment.ExitCode = 1; } + if ((actionSummaryResult.Item1 + actionSummaryResult.Item2 == 0) && Environment.ExitCode == 0) + { + Environment.ExitCode = 2; + } + randomly_notify_about_pro_business(config); } @@ -941,13 +946,13 @@ public virtual ConcurrentDictionary uninstall_run(Chocola } finally { - var uninstallFailures = report_action_summary(packageUninstalls, "uninstalled"); - if (uninstallFailures != 0 && Environment.ExitCode == 0) + var actionSummaryResult = report_action_summary(packageUninstalls, "uninstalled"); + if (actionSummaryResult.Item2 != 0 && Environment.ExitCode == 0) { Environment.ExitCode = 1; } - if (uninstallFailures != 0) + if (actionSummaryResult.Item2 != 0) { this.Log().Warn(@" If a package uninstall is failing and/or you've already uninstalled the @@ -973,7 +978,8 @@ this option only as a last resort. return packageUninstalls; } - private int report_action_summary(ConcurrentDictionary packageResults, string actionName) + //TODO once project upgraded to .Net 4.8, switch return type to (int successes, int failures, int warnings, int rebootPackages) + private Tuple report_action_summary(ConcurrentDictionary packageResults, string actionName) { var successes = packageResults.or_empty_list_if_null().Where(p => p.Value.Success && !p.Value.Inconclusive); var failures = packageResults.Count(p => !p.Value.Success); @@ -1041,7 +1047,7 @@ The recent package changes indicate a reboot is necessary. } } - return failures; + return new Tuple(successes.Count(), failures, warnings, rebootPackages); } public virtual void handle_package_uninstall(PackageResult packageResult, ChocolateyConfiguration config)