From afb980a7cde8d4fc6c61eedc4a6e69065acdcf50 Mon Sep 17 00:00:00 2001 From: AdmiringWorm Date: Fri, 16 Sep 2022 18:02:59 +0200 Subject: [PATCH] (#1443) Reset config after handling package results This updates the action used when handling package results during upgrade to reset the configuration class that is initially set. This fixes a bug when useRememberedArguments is enabled that causes arguments to be reused in the chocolateyInstall.ps1 when multiple packages are upgraded. It happens because OptionSet.parse() sets the configuration via the actions specified in the UpgradeCommand optionSet setup (and likewise in configuration builder as well). It only sets options that are saved, so if a later package does not have an option, it is not set, and the previous option is reused. This fixes the bug because it resets the configuration at the ChocolateyPackageService level, which is enough to reset the configuration for action that runs the PowerShell as well. Co-authored-by: TheCakeIsNaOH --- .../services/ChocolateyPackageService.cs | 2 +- .../infrastructure.app/services/NugetService.cs | 14 ++++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs index d73307e83c..79e60637fb 100644 --- a/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs +++ b/src/chocolatey/infrastructure.app/services/ChocolateyPackageService.cs @@ -1,4 +1,4 @@ -// Copyright © 2017 - 2022 Chocolatey Software, Inc +// Copyright © 2017 - 2022 Chocolatey Software, Inc // Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 7cd49afe2d..ff46a72a56 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -1,4 +1,4 @@ -// Copyright © 2017 - 2022 Chocolatey Software, Inc +// Copyright © 2017 - 2022 Chocolatey Software, Inc // Copyright © 2011 - 2017 RealDimensions Software, LLC // // Licensed under the Apache License, Version 2.0 (the "License"); @@ -621,12 +621,13 @@ public virtual ConcurrentDictionary upgrade_run(Chocolate set_package_names_if_all_is_specified(config, () => { config.IgnoreDependencies = true; }); config.IgnoreDependencies = configIgnoreDependencies; - var originalConfig = config.deep_copy(); + config.start_backup(); foreach (string packageName in config.PackageNames.Split(new[] { ApplicationParameters.PackageNamesSeparator }, StringSplitOptions.RemoveEmptyEntries).or_empty_list_if_null()) { - // reset config each time through - config = originalConfig.deep_copy(); + // We need to ensure we are using a clean configuration file + // before we start reading it. + config.reset_config(); IPackage installedPackage = packageManager.LocalRepository.FindPackage(packageName); @@ -878,6 +879,11 @@ public virtual ConcurrentDictionary upgrade_run(Chocolate } } + // Reset the configuration again once we are completely done with the processing of + // configurations, and make sure that we are removing any backup that was created + // as part of this run. + config.reset_config(removeBackup: true); + return packageInstalls; }