From 1f484ed3a56e4b7ffccc16620a832d20c66b6518 Mon Sep 17 00:00:00 2001 From: TheCakeIsNaOH Date: Wed, 9 Mar 2022 23:55:22 -0600 Subject: [PATCH] (#1479) Rework set package config method This brings out the functionality from the set_package_config_for_upgrade method to a more generic name, and adds in another parameter to prepare for setting remembered args for uninstall as well as upgrade. It also updates the logging and comments to make them generic for both upgrades and uninstalls. An alias/forwarding method is added for backwards compatibility. --- .../infrastructure.app/services/INugetService.cs | 3 ++- .../infrastructure.app/services/NugetService.cs | 15 +++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/chocolatey/infrastructure.app/services/INugetService.cs b/src/chocolatey/infrastructure.app/services/INugetService.cs index 9ea50e0078..b18eed288e 100644 --- a/src/chocolatey/infrastructure.app/services/INugetService.cs +++ b/src/chocolatey/infrastructure.app/services/INugetService.cs @@ -74,9 +74,10 @@ public interface INugetService : ISourceRunner /// /// The original configuration. /// The package information. + /// The command type /// The modified configuration, so it can be used ChocolateyConfiguration GetPackageConfigFromRememberedArguments(ChocolateyConfiguration config, - ChocolateyPackageInformation packageInfo); + ChocolateyPackageInformation packageInfo, CommandNameType commandType = CommandNameType.Upgrade); #pragma warning disable IDE0022, IDE1006 [Obsolete("This overload is deprecated and will be removed in v3.")] diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index 1f8caf3f00..af758ff5a9 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -1781,9 +1781,10 @@ public virtual ConcurrentDictionary GetOutdated(Chocolate } [Obsolete("This method is deprecated and will be removed in v3.")] - protected virtual ChocolateyConfiguration SetConfigFromRememberedArguments(ChocolateyConfiguration config, ChocolateyPackageInformation packageInfo) + protected virtual ChocolateyConfiguration SetConfigFromRememberedArguments(ChocolateyConfiguration config, ChocolateyPackageInformation packageInfo, CommandNameType commandType = CommandNameType.Upgrade) { - if (!config.Features.UseRememberedArgumentsForUpgrades || string.IsNullOrWhiteSpace(packageInfo.Arguments)) + if ((commandType == CommandNameType.Upgrade && !config.Features.UseRememberedArgumentsForUpgrades) || + (commandType == CommandNameType.Uninstall && !config.Features.UseRememberedArgumentsForUninstalls) || string.IsNullOrWhiteSpace(packageInfo.Arguments)) { return config; } @@ -1794,7 +1795,7 @@ protected virtual ChocolateyConfiguration SetConfigFromRememberedArguments(Choco if (!ArgumentsUtility.SensitiveArgumentsProvided(packageArgumentsUnencrypted)) { sensitiveArgs = false; - this.Log().Debug(ChocolateyLoggers.Verbose, "{0} - Adding remembered arguments for upgrade: {1}".FormatWith(packageInfo.Package.Id, packageArgumentsUnencrypted.EscapeCurlyBraces())); + this.Log().Debug(ChocolateyLoggers.Verbose, "{0} - Adding remembered arguments: {1}".FormatWith(packageInfo.Package.Id, packageArgumentsUnencrypted.EscapeCurlyBraces())); } var packageArgumentsSplit = packageArgumentsUnencrypted.Split(new[] { " --" }, StringSplitOptions.RemoveEmptyEntries); @@ -1815,7 +1816,7 @@ protected virtual ChocolateyConfiguration SetConfigFromRememberedArguments(Choco if (sensitiveArgs) { - this.Log().Debug(ChocolateyLoggers.Verbose, "{0} - Adding '{1}' to upgrade arguments. Values not shown due to detected sensitive arguments".FormatWith(packageInfo.Package.Id, optionName.EscapeCurlyBraces())); + this.Log().Debug(ChocolateyLoggers.Verbose, "{0} - Adding '{1}' to arguments. Values not shown due to detected sensitive arguments".FormatWith(packageInfo.Package.Id, optionName.EscapeCurlyBraces())); } packageArguments.Add("--{0}{1}".FormatWith(optionName, string.IsNullOrWhiteSpace(optionValue) ? string.Empty : "=" + optionValue)); } @@ -1873,10 +1874,12 @@ protected virtual ChocolateyConfiguration SetConfigFromRememberedArguments(Choco /// /// The original configuration. /// The package information. + /// The command type /// The modified configuration, so it can be used - public virtual ChocolateyConfiguration GetPackageConfigFromRememberedArguments(ChocolateyConfiguration config, ChocolateyPackageInformation packageInfo) + public virtual ChocolateyConfiguration GetPackageConfigFromRememberedArguments(ChocolateyConfiguration config, ChocolateyPackageInformation packageInfo, CommandNameType commandType = CommandNameType.Upgrade) { - if (!config.Features.UseRememberedArgumentsForUpgrades || string.IsNullOrWhiteSpace(packageInfo.Arguments)) + if ((commandType == CommandNameType.Upgrade && !config.Features.UseRememberedArgumentsForUpgrades) || + (commandType == CommandNameType.Uninstall && !config.Features.UseRememberedArgumentsForUninstalls) || string.IsNullOrWhiteSpace(packageInfo.Arguments)) { return config; }