diff --git a/src/chocolatey/infrastructure.app/services/NugetService.cs b/src/chocolatey/infrastructure.app/services/NugetService.cs index cd0bcadd06..76d72f2fa6 100644 --- a/src/chocolatey/infrastructure.app/services/NugetService.cs +++ b/src/chocolatey/infrastructure.app/services/NugetService.cs @@ -819,7 +819,7 @@ public virtual ConcurrentDictionary upgrade_run(Chocolate continue; } - set_package_config_for_upgrade(config, pkgInfo); + set_package_config_from_remembered_args(config, pkgInfo, CommandNameType.upgrade); if (performAction) { @@ -957,14 +957,16 @@ public virtual ConcurrentDictionary get_outdated(Chocolat } /// - /// Sets the configuration for the package upgrade + /// Sets the configuration from remembered args /// /// The configuration. /// The package information. - /// The original unmodified configuration, so it can be reset after upgrade - protected virtual ChocolateyConfiguration set_package_config_for_upgrade(ChocolateyConfiguration config, ChocolateyPackageInformation packageInfo) + /// The original unmodified configuration, so it can be reset after upgrade or uninstall + protected virtual ChocolateyConfiguration set_package_config_from_remembered_args(ChocolateyConfiguration config, ChocolateyPackageInformation packageInfo, CommandNameType command) { - if (!config.Features.UseRememberedArgumentsForUpgrades || string.IsNullOrWhiteSpace(packageInfo.Arguments)) return config; + if (string.IsNullOrWhiteSpace(packageInfo.Arguments)) return config; + if (command == CommandNameType.upgrade && !config.Features.UseRememberedArgumentsForUpgrades) return config; + if (command == CommandNameType.uninstall && !config.Features.UseRememberedArgumentsForUninstalls) return config; var packageArgumentsUnencrypted = packageInfo.Arguments.contains(" --") && packageInfo.Arguments.to_string().Length > 4 ? packageInfo.Arguments : NugetEncryptionUtility.DecryptString(packageInfo.Arguments); @@ -972,7 +974,7 @@ protected virtual ChocolateyConfiguration set_package_config_for_upgrade(Chocola if (!ArgumentsUtility.arguments_contain_sensitive_information(packageArgumentsUnencrypted)) { sensitiveArgs = false; - this.Log().Debug(ChocolateyLoggers.Verbose, "{0} - Adding remembered arguments for upgrade: {1}".format_with(packageInfo.Package.Id, packageArgumentsUnencrypted.escape_curly_braces())); + this.Log().Debug(ChocolateyLoggers.Verbose, "{0} - Adding remembered arguments: {1}".format_with(packageInfo.Package.Id, packageArgumentsUnencrypted.escape_curly_braces())); } var packageArgumentsSplit = packageArgumentsUnencrypted.Split(new[] { " --" }, StringSplitOptions.RemoveEmptyEntries); @@ -990,7 +992,7 @@ protected virtual ChocolateyConfiguration set_package_config_for_upgrade(Chocola if (sensitiveArgs) { - this.Log().Debug(ChocolateyLoggers.Verbose, "{0} - Adding '{1}' to upgrade arguments. Values not shown due to detected sensitive arguments".format_with(packageInfo.Package.Id, optionName.escape_curly_braces())); + this.Log().Debug(ChocolateyLoggers.Verbose, "{0} - Adding '{1}' to arguments. Values not shown due to detected sensitive arguments".format_with(packageInfo.Package.Id, optionName.escape_curly_braces())); } packageArguments.Add("--{0}{1}".format_with(optionName, string.IsNullOrWhiteSpace(optionValue) ? string.Empty : "=" + optionValue)); }