Skip to content

Commit

Permalink
(chocolatey#1443) Reset config after handling package results
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
AdmiringWorm and TheCakeIsNaOH committed Sep 20, 2022
1 parent c3171a1 commit afb980a
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -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");
Expand Down
14 changes: 10 additions & 4 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
@@ -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");
Expand Down Expand Up @@ -621,12 +621,13 @@ public virtual ConcurrentDictionary<string, PackageResult> 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);

Expand Down Expand Up @@ -878,6 +879,11 @@ public virtual ConcurrentDictionary<string, PackageResult> 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;
}

Expand Down

0 comments on commit afb980a

Please sign in to comment.