Skip to content

Commit 4b97897

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 102d90a commit 4b97897

File tree

2 files changed

+26
-6
lines changed

2 files changed

+26
-6
lines changed

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,18 @@ public virtual void configure_argument_parser(OptionSet optionSet, ChocolateyCon
133133
configuration.Features.ExitOnRebootDetected = false;
134134
}
135135
})
136+
.Add("userememberedargs|userememberedarguments|userememberedoptions|use-remembered-args|use-remembered-arguments|use-remembered-options",
137+
"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()),
138+
option =>
139+
{
140+
if (option != null) configuration.Features.UseRememberedArgumentsForUninstalls = true;
141+
})
142+
.Add("ignorerememberedargs|ignorerememberedarguments|ignorerememberedoptions|ignore-remembered-args|ignore-remembered-arguments|ignore-remembered-options",
143+
"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()),
144+
option =>
145+
{
146+
if (option != null) configuration.Features.UseRememberedArgumentsForUninstalls = false;
147+
})
136148
;
137149
}
138150

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

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -970,12 +970,7 @@ protected virtual ChocolateyConfiguration set_package_config_from_remembered_arg
970970

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

973-
var sensitiveArgs = true;
974-
if (!ArgumentsUtility.arguments_contain_sensitive_information(packageArgumentsUnencrypted))
975-
{
976-
sensitiveArgs = false;
977-
this.Log().Debug(ChocolateyLoggers.Verbose, "{0} - Adding remembered arguments: {1}".format_with(packageInfo.Package.Id, packageArgumentsUnencrypted.escape_curly_braces()));
978-
}
973+
var sensitiveArgs = ArgumentsUtility.arguments_contain_sensitive_information(packageArgumentsUnencrypted);
979974

980975
var packageArgumentsSplit = packageArgumentsUnencrypted.Split(new[] { " --" }, StringSplitOptions.RemoveEmptyEntries);
981976
var packageArguments = new List<string>();
@@ -990,10 +985,17 @@ protected virtual ChocolateyConfiguration set_package_config_from_remembered_arg
990985
if (optionValue.StartsWith("'")) optionValue.remove_surrounding_quotes();
991986
}
992987

988+
//Don't add install arguments during uninstall. We don't want a argument for the installer to be passed to the uninstaller.
989+
if (string.Equals(optionName, "install-arguments") && command == CommandNameType.uninstall) continue;
990+
993991
if (sensitiveArgs)
994992
{
995993
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()));
996994
}
995+
else
996+
{
997+
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()));
998+
}
997999
packageArguments.Add("--{0}{1}".format_with(optionName, string.IsNullOrWhiteSpace(optionValue) ? string.Empty : "=" + optionValue));
9981000
}
9991001

@@ -1441,6 +1443,9 @@ public virtual ConcurrentDictionary<string, PackageResult> uninstall_run(Chocola
14411443

14421444
foreach (var packageVersion in packageVersionsToRemove)
14431445
{
1446+
// reset config each time through
1447+
config = originalConfig.deep_copy();
1448+
14441449
var pkgInfo = _packageInfoService.get_package_information(packageVersion);
14451450
if (pkgInfo != null && pkgInfo.IsPinned)
14461451
{
@@ -1452,6 +1457,8 @@ public virtual ConcurrentDictionary<string, PackageResult> uninstall_run(Chocola
14521457
continue;
14531458
}
14541459

1460+
set_package_config_from_remembered_args(config, pkgInfo, CommandNameType.uninstall);
1461+
14551462
if (performAction)
14561463
{
14571464
try
@@ -1498,6 +1505,7 @@ public virtual ConcurrentDictionary<string, PackageResult> uninstall_run(Chocola
14981505
var result = packageUninstalls.GetOrAdd(packageVersion.Id.to_lower() + "." + packageVersion.Version.to_string(), new PackageResult(packageVersion, _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, packageVersion.Id)));
14991506
if (continueAction != null) continueAction.Invoke(result);
15001507
}
1508+
resetConfigAction.Invoke(originalConfig);
15011509
}
15021510
}
15031511

0 commit comments

Comments
 (0)