Skip to content

Commit d627fcb

Browse files
committed
(#1479) Implement using remembed arguments for uninstalls
This adds the ability for the remembered argument to be reused for uninstalls. It can be controlled via the userememberedargs and ignorerememberedargs arguments, or via the previously added feature.
1 parent 82e1052 commit d627fcb

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

src/chocolatey/infrastructure.app/commands/ChocolateyUninstallCommand.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,18 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
137137
"Skip hooks - Do not run hook scripts. Available in 1.2.0+",
138138
option => configuration.SkipHookScripts = option != null
139139
)
140+
.Add("userememberedargs|userememberedarguments|userememberedoptions|use-remembered-args|use-remembered-arguments|use-remembered-options",
141+
"Use Remembered Options for Uninstall - use the arguments and options used during install/upgrade for uninstall. Does not override arguments being passed at runtime. Overrides the default feature '{0}' set to '{1}'. Available in 1.1.0+.".format_with(ApplicationParameters.Features.UseRememberedArgumentsForUninstalls, configuration.Features.UseRememberedArgumentsForUninstalls.to_string()),
142+
option =>
143+
{
144+
if (option != null) configuration.Features.UseRememberedArgumentsForUninstalls = true;
145+
})
146+
.Add("ignorerememberedargs|ignorerememberedarguments|ignorerememberedoptions|ignore-remembered-args|ignore-remembered-arguments|ignore-remembered-options",
147+
"Ignore Remembered Options for Uninstall - ignore the arguments and options used during install for Uninstall. Overrides the default feature '{0}' set to '{1}'. Available in 1.1.0+.".format_with(ApplicationParameters.Features.UseRememberedArgumentsForUninstalls, configuration.Features.UseRememberedArgumentsForUninstalls.to_string()),
148+
option =>
149+
{
150+
if (option != null) configuration.Features.UseRememberedArgumentsForUninstalls = false;
151+
})
140152
;
141153
}
142154

src/chocolatey/infrastructure.app/services/NugetService.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1006,12 +1006,7 @@ protected virtual ChocolateyConfiguration set_package_config_from_remembered_arg
10061006

10071007
var packageArgumentsUnencrypted = packageInfo.Arguments.contains(" --") && packageInfo.Arguments.to_string().Length > 4 ? packageInfo.Arguments : NugetEncryptionUtility.DecryptString(packageInfo.Arguments);
10081008

1009-
var sensitiveArgs = true;
1010-
if (!ArgumentsUtility.arguments_contain_sensitive_information(packageArgumentsUnencrypted))
1011-
{
1012-
sensitiveArgs = false;
1013-
this.Log().Debug(ChocolateyLoggers.Verbose, "{0} - Adding remembered arguments: {1}".format_with(packageInfo.Package.Id, packageArgumentsUnencrypted.escape_curly_braces()));
1014-
}
1009+
var sensitiveArgs = ArgumentsUtility.arguments_contain_sensitive_information(packageArgumentsUnencrypted);
10151010

10161011
var packageArgumentsSplit = packageArgumentsUnencrypted.Split(new[] { " --" }, StringSplitOptions.RemoveEmptyEntries);
10171012
var packageArguments = new List<string>();
@@ -1026,10 +1021,18 @@ protected virtual ChocolateyConfiguration set_package_config_from_remembered_arg
10261021
if (optionValue.StartsWith("'")) optionValue.remove_surrounding_quotes();
10271022
}
10281023

1024+
//Don't add install arguments during uninstall. We don't want a argument for the installer to be passed to the uninstaller.
1025+
if (string.Equals(optionName, "install-arguments") && commandType == CommandNameType.uninstall) continue;
1026+
if (string.Equals(optionName, "override-argument") && commandType == CommandNameType.uninstall) continue;
1027+
10291028
if (sensitiveArgs)
10301029
{
10311030
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()));
10321031
}
1032+
else
1033+
{
1034+
this.Log().Debug(ChocolateyLoggers.Verbose, "{0} - Adding '{1}' to arguments with a value of '{2}'".format_with(packageInfo.Package.Id, optionName.escape_curly_braces(), optionValue.escape_curly_braces()));
1035+
}
10331036
packageArguments.Add("--{0}{1}".format_with(optionName, string.IsNullOrWhiteSpace(optionValue) ? string.Empty : "=" + optionValue));
10341037
}
10351038

@@ -1478,6 +1481,9 @@ public virtual ConcurrentDictionary<string, PackageResult> uninstall_run(Chocola
14781481

14791482
foreach (var packageVersion in packageVersionsToRemove)
14801483
{
1484+
// reset config each time through
1485+
config.reset_config();
1486+
14811487
var pkgInfo = _packageInfoService.get_package_information(packageVersion);
14821488
if (pkgInfo != null && pkgInfo.IsPinned)
14831489
{
@@ -1489,6 +1495,8 @@ public virtual ConcurrentDictionary<string, PackageResult> uninstall_run(Chocola
14891495
continue;
14901496
}
14911497

1498+
set_package_config_from_remembered_args(config, pkgInfo, CommandNameType.uninstall);
1499+
14921500
if (performAction)
14931501
{
14941502
try
@@ -1535,6 +1543,7 @@ public virtual ConcurrentDictionary<string, PackageResult> uninstall_run(Chocola
15351543
var result = packageUninstalls.GetOrAdd(packageVersion.Id.to_lower() + "." + packageVersion.Version.to_string(), new PackageResult(packageVersion, _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, packageVersion.Id)));
15361544
if (continueAction != null) continueAction.Invoke(result);
15371545
}
1546+
config.reset_config();
15381547
}
15391548
}
15401549

0 commit comments

Comments
 (0)