Skip to content

Commit

Permalink
(chocolatey#2630) Re-instate setting of config properties
Browse files Browse the repository at this point in the history
Previously, in this commit:

chocolatey@da19356#diff-cb6a0471e41268b22a928bd57a59d51b70b7024e9beb30e89a330e193a089eba

The usage of the top level CacheLocation and
CommandExecutionTimeoutSeconds values had been removed, since these top
level properties within the chocolatey.config had been replaced with
values contained within the config section of the chocolatey.config
file.

However, the changes in that commit were too aggressive, and removed
the call to the set_config_item (which has subsequently been renamed to
SetConfigItem).  The method call does the work of taking any value that
is defined in the chocolatey.config for a given property name, and
adding it to the ChocolateyConfiguration instance.  When this method
call was removed, it stopped setting the property value on the
instance, and as a result, values that had been configured in the
chocolatey.config file were ignored.  They were still in play when the
configuration was passed in via a command line option, but not when
defining them in the chocolatey.config file.

The removal of this call to the set_config_item method also explains
why it was necessary to apply this bug fix in Chocolatey GUI:

chocolatey/ChocolateyGUI#1003

The method call also had the effect of setting the description on the
configuration value, which would have meant that Chocolatey GUI
wouldn't have thrown a null reference exception.  The change in
Chocolatey GUI is still valid though, as there are times when a config
value can have a missing description, so it makes sense to leave that
fix in place.
  • Loading branch information
gep13 committed Jun 22, 2023
1 parent 7156c9e commit f6d797e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions src/chocolatey/infrastructure.app/builders/ConfigurationBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ private static void SetMachineSources(ChocolateyConfiguration config, ConfigFile

private static void SetAllConfigItems(ChocolateyConfiguration config, ConfigFileSettings configFileSettings, IFileSystem fileSystem)
{
config.CacheLocation = Environment.ExpandEnvironmentVariables(
SetConfigItem(
ApplicationParameters.ConfigSettings.CacheLocation,
configFileSettings,
string.Empty,
"Cache location if not TEMP folder. Replaces `$env:TEMP` value for choco.exe process. It is highly recommended this be set to make Chocolatey more deterministic in cleanup."
)
);

if (string.IsNullOrWhiteSpace(config.CacheLocation))
{
config.CacheLocation = fileSystem.GetTempPath(); // System.Environment.GetEnvironmentVariable("TEMP");
Expand All @@ -233,10 +242,12 @@ private static void SetAllConfigItems(ChocolateyConfiguration config, ConfigFile
if (string.IsNullOrWhiteSpace(config.CacheLocation)) config.CacheLocation = fileSystem.CombinePaths(ApplicationParameters.InstallLocation, "temp");

var commandExecutionTimeoutSeconds = 0;
var commandExecutionTimeout = configFileSettings.ConfigSettings
.Where(f => f.Key.IsEqualTo(ApplicationParameters.ConfigSettings.CommandExecutionTimeoutSeconds))
.Select(c => c.Value)
.FirstOrDefault();
var commandExecutionTimeout = SetConfigItem(
ApplicationParameters.ConfigSettings.CommandExecutionTimeoutSeconds,
configFileSettings,
ApplicationParameters.DefaultWaitForExitInSeconds.ToStringSafe(),
"Default timeout for command execution. '0' for infinite."
);

int.TryParse(commandExecutionTimeout, out commandExecutionTimeoutSeconds);
config.CommandExecutionTimeoutSeconds = commandExecutionTimeoutSeconds;
Expand Down

0 comments on commit f6d797e

Please sign in to comment.