Skip to content

Commit 221ae7d

Browse files
committed
(chocolateyGH-1038) Add ability to stop operation on reboot
There is now both a parameter and a feature flag which will allow halting the install/upgrade/uninstall of a package, when a reboot request is returned from one of it's dependencies. When this occurs, an ApplicationException will be thrown, and the package exit code, either 1641 (restart initiated), or 3010 (restart requested) will be returned. This could then be inspected to decide when a reboot should actually be performed, before continuing with the remainder of the installation. The implementation of this ability followed closely to how the stoponfirstfailure parameter and feature flag are implemented.
1 parent a37c6b0 commit 221ae7d

7 files changed

+32
-1
lines changed

src/chocolatey/infrastructure.app/ApplicationParameters.cs

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ public static class Features
170170
public static readonly string IgnoreUnfoundPackagesOnUpgradeOutdated = "ignoreUnfoundPackagesOnUpgradeOutdated";
171171
public static readonly string RemovePackageInformationOnUninstall = "removePackageInformationOnUninstall";
172172
public static readonly string LogWithoutColor = "logWithoutColor";
173+
public static readonly string StopOnFirstPackageRebootRequest = "stopOnFirstPackageRebootRequest";
173174
}
174175

175176
public static class Messages

src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright © 2017 - 2018 Chocolatey Software, Inc
1+
// Copyright © 2017 - 2018 Chocolatey Software, Inc
22
// Copyright © 2011 - 2017 RealDimensions Software, LLC
33
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
@@ -303,6 +303,7 @@ private static void set_feature_flags(ChocolateyConfiguration config, ConfigFile
303303

304304
config.Features.ScriptsCheckLastExitCode = set_feature_flag(ApplicationParameters.Features.ScriptsCheckLastExitCode, configFileSettings, defaultEnabled: false, description: "Scripts Check $LastExitCode (external commands) - Leave this off unless you absolutely need it while you fix your package scripts to use `throw 'error message'` or `Set-PowerShellExitCode #` instead of `exit #`. This behavior started in 0.9.10 and produced hard to find bugs. If the last external process exits successfully but with an exit code of not zero, this could cause hard to detect package failures. Available in 0.10.3+. Will be removed in 0.11.0.");
305305
config.PromptForConfirmation = !set_feature_flag(ApplicationParameters.Features.AllowGlobalConfirmation, configFileSettings, defaultEnabled: false, description: "Prompt for confirmation in scripts or bypass.");
306+
config.Features.StopOnFirstPackageRebootRequest = set_feature_flag(ApplicationParameters.Features.StopOnFirstPackageRebootRequest, configFileSettings, defaultEnabled: false, description: "- stop running install, upgrade, or uninstall on first package reboot request instead of continuing with others. As this will affect upgrade all, it is normally recommended to leave this off. Available in 0.10.12+.");
306307
}
307308

308309
private static bool set_feature_flag(string featureName, ConfigFileSettings configFileSettings, bool defaultEnabled, string description)

src/chocolatey/infrastructure.app/commands/ChocolateyInstallCommand.cs

+5
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,11 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
155155
"Stop On First Package Failure - stop running install, upgrade or uninstall on first package failure instead of continuing with others. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.4+.".format_with(ApplicationParameters.Features.StopOnFirstPackageFailure, configuration.Features.StopOnFirstPackageFailure.to_string()),
156156
option => configuration.Features.StopOnFirstPackageFailure = option != null
157157
)
158+
.Add("stoponfirstrebootrequest|stop-on-first-reboot-request|stop-on-first-package-reboot-request",
159+
"Stop On First Package Reboot Request - stop running install, upgrade, or uninstall on first package reboot request instead of continuing with others. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.12+.".format_with
160+
(ApplicationParameters.Features.StopOnFirstPackageRebootRequest, configuration.Features.StopOnFirstPackageRebootRequest.to_string()),
161+
option => configuration.Features.StopOnFirstPackageRebootRequest = option != null
162+
)
158163
;
159164

160165
//todo: package name can be a url / installertype

src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs

+5
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,11 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
118118
"Stop On First Package Failure - stop running install, upgrade or uninstall on first package failure instead of continuing with others. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.4+.".format_with(ApplicationParameters.Features.StopOnFirstPackageFailure, configuration.Features.StopOnFirstPackageFailure.to_string()),
119119
option => configuration.Features.StopOnFirstPackageFailure = option != null
120120
)
121+
.Add("stoponfirstrebootrequest|stop-on-first-reboot-request|stop-on-first-package-reboot-request",
122+
"Stop On First Package Reboot Request - stop running install, upgrade, or uninstall on first package reboot request instead of continuing with others. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.12+.".format_with
123+
(ApplicationParameters.Features.StopOnFirstPackageRebootRequest, configuration.Features.StopOnFirstPackageRebootRequest.to_string()),
124+
option => configuration.Features.StopOnFirstPackageRebootRequest = option != null
125+
)
121126
;
122127
}
123128

src/chocolatey/infrastructure.app/commands/ChocolateyUpgradeCommand.cs

+5
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,11 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
182182
{
183183
if (option != null) configuration.Features.UseRememberedArgumentsForUpgrades = false;
184184
})
185+
.Add("stoponfirstrebootrequest|stop-on-first-reboot-request|stop-on-first-package-reboot-request",
186+
"Stop On First Package Reboot Request - stop running install, upgrade, or uninstall on first package reboot request instead of continuing with others. Overrides the default feature '{0}' set to '{1}'. Available in 0.10.12+.".format_with
187+
(ApplicationParameters.Features.StopOnFirstPackageRebootRequest, configuration.Features.StopOnFirstPackageRebootRequest.to_string()),
188+
option => configuration.Features.StopOnFirstPackageRebootRequest = option != null
189+
)
185190
;
186191
}
187192

src/chocolatey/infrastructure.app/configuration/ChocolateyConfiguration.cs

+1
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ public sealed class FeaturesConfiguration
390390
public bool UseRememberedArgumentsForUpgrades { get; set; }
391391
public bool IgnoreUnfoundPackagesOnUpgradeOutdated { get; set; }
392392
public bool RemovePackageInformationOnUninstall { get; set; }
393+
public bool StopOnFirstPackageRebootRequest { get; set; }
393394

394395
//todo remove in 0.11.0
395396
public bool ScriptsCheckLastExitCode { get; set; }

src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs

+13
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,19 @@ public void handle_package_result(PackageResult packageResult, ChocolateyConfigu
420420

421421
remove_pending(packageResult, config);
422422

423+
// Test to see if exit code is either:
424+
// 1641 - restart initiated
425+
// 3010 - restart required
426+
var rebootExitCodes = new List<int> { 1641, 3010 };
427+
428+
if(rebootExitCodes.Contains(packageResult.ExitCode))
429+
{
430+
if(config.Features.StopOnFirstPackageRebootRequest)
431+
{
432+
throw new ApplicationException("Stopping further execution as {0} has requested a reboot.".format_with(packageResult.Name));
433+
}
434+
}
435+
423436
if (!packageResult.Success)
424437
{
425438
this.Log().Error(ChocolateyLoggers.Important, "The {0} of {1} was NOT successful.".format_with(commandName.to_string(), packageResult.Name));

0 commit comments

Comments
 (0)