Skip to content

Commit 2c273d3

Browse files
committed
Merge branch 'stable'
* stable: (GH-1655) make virtual methods for outdated / package service (GH-1747) Fix: passing timeout switch of 0 is ignored (GH-1746) Update XML comments / formatting (GH-1746) update logging for validation (GH-1038) Stop operation on package reboot request (GH-1038) Stop execution if pending reboot (GH-1746) Add concept of global validation (maint) Corrected white space
2 parents e0b9a61 + 8822afb commit 2c273d3

19 files changed

+883
-145
lines changed

src/chocolatey.console/Program.cs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Copyright © 2017 - 2018 Chocolatey Software, Inc
22
// Copyright © 2011 - 2017 RealDimensions Software, LLC
3-
//
3+
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
6-
//
6+
//
77
// You may obtain a copy of the License at
8-
//
8+
//
99
// http://www.apache.org/licenses/LICENSE-2.0
10-
//
10+
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,
1313
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -158,7 +158,7 @@ private static void Main(string[] args)
158158
"chocolatey".Log().Error(ChocolateyLoggers.Important, () => "{0}".format_with(ex.Message));
159159
}
160160

161-
Environment.ExitCode = 1;
161+
if (Environment.ExitCode == 0) Environment.ExitCode = 1;
162162
}
163163
finally
164164
{
@@ -188,7 +188,7 @@ private static void add_assembly_resolver()
188188
{
189189
var requestedAssembly = new AssemblyName(args.Name);
190190

191-
// There are things that are ILMerged into Chocolatey. Anything with
191+
// There are things that are ILMerged into Chocolatey. Anything with
192192
// the right public key except licensed should use the choco/chocolatey assembly
193193
if (requestedAssembly.get_public_key_token().is_equal_to(ApplicationParameters.OfficialChocolateyPublicKey)
194194
&& !requestedAssembly.Name.is_equal_to(ApplicationParameters.LicensedChocolateyAssemblySimpleName)

src/chocolatey/chocolatey.csproj

+7
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@
102102
</Compile>
103103
<Compile Include="AssemblyExtensions.cs" />
104104
<Compile Include="infrastructure.app\commands\ChocolateyInfoCommand.cs" />
105+
<Compile Include="infrastructure.app\validations\GlobalConfigurationValidation.cs" />
105106
<Compile Include="infrastructure.app\configuration\EnvironmentSettings.cs" />
106107
<Compile Include="infrastructure.app\domain\GenericRegistryKey.cs" />
107108
<Compile Include="infrastructure.app\domain\GenericRegistryValue.cs" />
@@ -120,10 +121,13 @@
120121
<Compile Include="infrastructure.app\domain\RegistryValueExtensions.cs" />
121122
<Compile Include="infrastructure.app\domain\RegistryValueKindType.cs" />
122123
<Compile Include="infrastructure.app\events\HandlePackageResultCompletedMessage.cs" />
124+
<Compile Include="infrastructure.app\services\IPendingRebootService.cs" />
125+
<Compile Include="infrastructure.app\services\PendingRebootService.cs" />
123126
<Compile Include="infrastructure.app\templates\ChocolateyTodoTemplate.cs" />
124127
<Compile Include="infrastructure.app\utility\ArgumentsUtility.cs" />
125128
<Compile Include="infrastructure.app\utility\HashCode.cs" />
126129
<Compile Include="infrastructure.app\utility\PackageUtility.cs" />
130+
<Compile Include="infrastructure.app\validations\SystemStateValidation.cs" />
127131
<Compile Include="infrastructure\filesystem\FileSystem.cs" />
128132
<Compile Include="infrastructure\logging\AggregateLog.cs" />
129133
<Compile Include="infrastructure\logging\LogLevelType.cs" />
@@ -317,6 +321,9 @@
317321
<Compile Include="infrastructure\tokens\TokenReplacer.cs" />
318322
<Compile Include="ILogExtensions.cs" />
319323
<Compile Include="infrastructure\tolerance\FaultTolerance.cs" />
324+
<Compile Include="infrastructure\validations\IValidation.cs" />
325+
<Compile Include="infrastructure\validations\ValidationResult.cs" />
326+
<Compile Include="infrastructure\validations\ValidationStatus.cs" />
320327
<Compile Include="infrastructure\xml\XmlCData.cs" />
321328
<Compile Include="LogExtensions.cs" />
322329
<Compile Include="ObjectExtensions.cs" />

src/chocolatey/infrastructure.app/ApplicationParameters.cs

+15-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Copyright © 2017 - 2018 Chocolatey Software, Inc
22
// Copyright © 2011 - 2017 RealDimensions Software, LLC
3-
//
3+
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
6-
//
6+
//
77
// You may obtain a copy of the License at
8-
//
8+
//
99
// http://www.apache.org/licenses/LICENSE-2.0
10-
//
10+
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,
1313
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -33,7 +33,7 @@ public static class ApplicationParameters
3333
#if DEBUG
3434
public static readonly string InstallLocation = _fileSystem.get_directory_name(_fileSystem.get_current_assembly_path());
3535
public static readonly string LicensedAssemblyLocation = _fileSystem.file_exists(_fileSystem.combine_paths(InstallLocation, "chocolatey.licensed.dll")) ? _fileSystem.combine_paths(InstallLocation, "chocolatey.licensed.dll") : _fileSystem.combine_paths(InstallLocation, "extensions", "chocolatey", "chocolatey.licensed.dll");
36-
36+
3737
#else
3838
public static readonly string InstallLocation = System.Environment.GetEnvironmentVariable(ChocolateyInstallEnvironmentVariableName) ?? _fileSystem.get_directory_name(_fileSystem.get_current_assembly_path());
3939
public static readonly string LicensedAssemblyLocation = _fileSystem.combine_paths(InstallLocation, "extensions", "chocolatey", "chocolatey.licensed.dll");
@@ -112,10 +112,10 @@ public static class Environment
112112
public static readonly string[] ConfigFileExtensions = new string[] {".autoconf",".config",".conf",".cfg",".jsc",".json",".jsonp",".ini",".xml",".yaml"};
113113
public static readonly string ConfigFileTransformExtension = ".install.xdt";
114114
public static readonly string[] ShimDirectorFileExtensions = new string[] {".gui",".ignore"};
115-
115+
116116
public static readonly string HashProviderFileTooBig = "UnableToDetectChanges_FileTooBig";
117117
public static readonly string HashProviderFileLocked = "UnableToDetectChanges_FileLocked";
118-
118+
119119
/// <summary>
120120
/// This is a readonly bool set to true. It is only shifted for specs.
121121
/// </summary>
@@ -127,6 +127,12 @@ public static class Environment
127127
/// </summary>
128128
public static readonly bool AllowPrompts = true;
129129

130+
public static class ExitCodes
131+
{
132+
public static readonly int ErrorFailNoActionReboot = 350;
133+
public static readonly int ErrorInstallSuspend = 1604;
134+
}
135+
130136
public static class Tools
131137
{
132138
//public static readonly string WebPiCmdExe = _fileSystem.combine_paths(InstallLocation, "nuget.exe");
@@ -145,7 +151,7 @@ public static class ConfigSettings
145151
public static readonly string ProxyBypassOnLocal = "proxyBypassOnLocal";
146152
public static readonly string WebRequestTimeoutSeconds = "webRequestTimeoutSeconds";
147153
}
148-
154+
149155
public static class Features
150156
{
151157
public static readonly string ChecksumFiles = "checksumFiles";
@@ -171,6 +177,7 @@ public static class Features
171177
public static readonly string SkipPackageUpgradesWhenNotInstalled = "skipPackageUpgradesWhenNotInstalled";
172178
public static readonly string RemovePackageInformationOnUninstall = "removePackageInformationOnUninstall";
173179
public static readonly string LogWithoutColor = "logWithoutColor";
180+
public static readonly string ExitOnRebootDetected = "exitOnRebootDetected";
174181
}
175182

176183
public static class Messages

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

+18-16
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
// Copyright © 2017 - 2018 Chocolatey Software, Inc
22
// Copyright © 2011 - 2017 RealDimensions Software, LLC
3-
//
3+
//
44
// Licensed under the Apache License, Version 2.0 (the "License");
55
// you may not use this file except in compliance with the License.
6-
//
6+
//
77
// You may obtain a copy of the License at
8-
//
8+
//
99
// http://www.apache.org/licenses/LICENSE-2.0
10-
//
10+
//
1111
// Unless required by applicable law or agreed to in writing, software
1212
// distributed under the License is distributed on an "AS IS" BASIS,
1313
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -210,7 +210,7 @@ private static void set_config_items(ChocolateyConfiguration config, ConfigFileS
210210
config.CacheLocation = Environment.ExpandEnvironmentVariables(set_config_item(ApplicationParameters.ConfigSettings.CacheLocation, configFileSettings, string.IsNullOrWhiteSpace(configFileSettings.CacheLocation) ? string.Empty : configFileSettings.CacheLocation, "Cache location if not TEMP folder. Replaces `$env:TEMP` value."));
211211
if (string.IsNullOrWhiteSpace(config.CacheLocation)) {
212212
config.CacheLocation = fileSystem.get_temp_path(); // System.Environment.GetEnvironmentVariable("TEMP");
213-
// TEMP gets set in EnvironmentSettings, so it may already have
213+
// TEMP gets set in EnvironmentSettings, so it may already have
214214
// chocolatey in the path when it installs the next package from
215215
// the API.
216216
if(!String.Equals(fileSystem.get_directory_info_for(config.CacheLocation).Name, "chocolatey", StringComparison.OrdinalIgnoreCase)) {
@@ -220,7 +220,7 @@ private static void set_config_items(ChocolateyConfiguration config, ConfigFileS
220220

221221
// if it is still empty, use temp in the Chocolatey install directory.
222222
if (string.IsNullOrWhiteSpace(config.CacheLocation)) config.CacheLocation = fileSystem.combine_paths(ApplicationParameters.InstallLocation, "temp");
223-
223+
224224
var commandExecutionTimeoutSeconds = 0;
225225
var commandExecutionTimeout = set_config_item(ApplicationParameters.ConfigSettings.CommandExecutionTimeoutSeconds, configFileSettings, string.IsNullOrWhiteSpace(configFileSettings.CommandExecutionTimeoutSeconds.to_string()) ? ApplicationParameters.DefaultWaitForExitInSeconds.to_string() : configFileSettings.CommandExecutionTimeoutSeconds.to_string(), "Default timeout for command execution. '0' for infinite (starting in 0.10.4).");
226226
int.TryParse(commandExecutionTimeout, out commandExecutionTimeoutSeconds);
@@ -304,6 +304,7 @@ private static void set_feature_flags(ChocolateyConfiguration config, ConfigFile
304304

305305
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.");
306306
config.PromptForConfirmation = !set_feature_flag(ApplicationParameters.Features.AllowGlobalConfirmation, configFileSettings, defaultEnabled: false, description: "Prompt for confirmation in scripts or bypass.");
307+
config.Features.ExitOnRebootDetected = set_feature_flag(ApplicationParameters.Features.ExitOnRebootDetected, configFileSettings, defaultEnabled: false, description: "Exit On Reboot Detected - Stop running install, upgrade, or uninstall when a reboot request is detected. Requires '{0}' feature to be turned on. Will exit with either {1} or {2}. When it exits with {1}, it means pending reboot discovered prior to running operation. When it exits with {2}, it means some work completed prior to reboot request being detected. As this will affect upgrade all, it is normally recommended to leave this off. Available in 0.10.12+.".format_with(ApplicationParameters.Features.ExitOnRebootDetected, ApplicationParameters.ExitCodes.ErrorFailNoActionReboot, ApplicationParameters.ExitCodes.ErrorInstallSuspend));
307308
}
308309

309310
private static bool set_feature_flag(string featureName, ConfigFileSettings configFileSettings, bool defaultEnabled, string description)
@@ -350,7 +351,7 @@ private static void set_global_options(IList<string> args, ChocolateyConfigurati
350351
option => config.Verbose = option != null)
351352
.Add("trace",
352353
"Trace - Show trace messaging. Very, very verbose trace messaging. Avoid except when needing super low-level .NET Framework debugging. Available in 0.10.4+.",
353-
option => config.Trace = option != null)
354+
option => config.Trace = option != null)
354355
.Add("nocolor|no-color",
355356
"No Color - Do not show colorization in logging output. This overrides the feature '{0}', set to '{1}'. Available in 0.10.9+.".format_with(ApplicationParameters.Features.LogWithoutColor, config.Features.LogWithoutColor),
356357
option => config.Features.LogWithoutColor = option != null)
@@ -378,8 +379,9 @@ private static void set_global_options(IList<string> args, ChocolateyConfigurati
378379
option =>
379380
{
380381
int timeout = 0;
381-
int.TryParse(option.remove_surrounding_quotes(), out timeout);
382-
if (timeout > 0)
382+
var timeoutString = option.remove_surrounding_quotes();
383+
int.TryParse(timeoutString, out timeout);
384+
if (timeout > 0 || timeoutString.is_equal_to("0"))
383385
{
384386
config.CommandExecutionTimeoutSeconds = timeout;
385387
}
@@ -413,7 +415,7 @@ private static void set_global_options(IList<string> args, ChocolateyConfigurati
413415
option => config.Proxy.BypassList = option.remove_surrounding_quotes())
414416
.Add("proxy-bypass-on-local",
415417
"Proxy Bypass On Local - Bypass proxy for local connections. Requires explicity proxy (`--proxy` or config setting). Overrides the default proxy bypass on local setting of '{0}'. Available in 0.10.4+.".format_with(config.Proxy.BypassOnLocal),
416-
option => config.Proxy.BypassOnLocal = option != null)
418+
option => config.Proxy.BypassOnLocal = option != null)
417419
.Add("log-file=",
418420
"Log File to output to in addition to regular loggers. Available in 0.10.8+.",
419421
option => config.AdditionalLogFileLocation= option.remove_surrounding_quotes())
@@ -472,16 +474,16 @@ the local options are parsed.
472474
(`""value""`) but in powershell.exe you should use backticks
473475
(`` `""value`"" ``) or apostrophes (`'value'`). Using the combination
474476
allows for both shells to work without issue, except for when the next
475-
section applies.
477+
section applies.
476478
* **Pass quotes in arguments**: When you need to pass quoted values to
477479
to something like a native installer, you are in for a world of fun. In
478480
cmd.exe you must pass it like this: `-ia ""/yo=""""Spaces spaces""""""`. In
479481
PowerShell.exe, you must pass it like this: `-ia '/yo=""""Spaces spaces""""'`.
480482
No other combination will work. In PowerShell.exe if you are on version
481483
v3+, you can try `--%` before `-ia` to just pass the args through as is,
482484
which means it should not require any special workarounds.
483-
* **Periods in PowerShell**: If you need to pass a period as part of a
484-
value or a path, PowerShell doesn't always handle it well. Please
485+
* **Periods in PowerShell**: If you need to pass a period as part of a
486+
value or a path, PowerShell doesn't always handle it well. Please
485487
quote those values using ""Quote Values"" section above.
486488
* Options and switches apply to all items passed, so if you are
487489
installing multiple packages, and you use `--version=1.0.0`, choco
@@ -614,7 +616,7 @@ private static void set_environment_options(ChocolateyConfiguration config)
614616
config.Information.IsUserRemoteDesktop = ProcessInformation.user_is_terminal_services();
615617
config.Information.IsUserRemote = ProcessInformation.user_is_remote();
616618
config.Information.IsProcessElevated = ProcessInformation.process_is_elevated();
617-
619+
618620
if (!string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("https_proxy")) && string.IsNullOrWhiteSpace(config.Proxy.Location))
619621
{
620622
config.Proxy.Location = Environment.GetEnvironmentVariable("https_proxy");
@@ -643,7 +645,7 @@ private static void set_licensed_options(ChocolateyConfiguration config, Chocola
643645
if (licensedConfigBuilder == null)
644646
{
645647
if (config.RegularOutput) "chocolatey".Log().Warn(ChocolateyLoggers.Important,
646-
@"Unable to set licensed configuration. Please upgrade to a newer
648+
@"Unable to set licensed configuration. Please upgrade to a newer
647649
licensed version (choco upgrade chocolatey.extension).");
648650
return;
649651
}
@@ -697,7 +699,7 @@ private static void set_hash_provider(ChocolateyConfiguration config, Container
697699
if (ex.InnerException != null && ex.InnerException.Message.contains("FIPS"))
698700
{
699701
"chocolatey".Log().Warn(ChocolateyLoggers.Important, @"
700-
FIPS Mode detected - run 'choco feature enable -n {0}'
702+
FIPS Mode detected - run 'choco feature enable -n {0}'
701703
to use Chocolatey.".format_with(ApplicationParameters.Features.UseFipsCompliantChecksums));
702704

703705
var errorMessage = "When FIPS Mode is enabled, Chocolatey requires {0} feature also be enabled.".format_with(ApplicationParameters.Features.UseFipsCompliantChecksums);

0 commit comments

Comments
 (0)