Skip to content

Commit 6a0680e

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 e2b2dc7 commit 6a0680e

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
@@ -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: 15 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,18 @@ 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+
if (string.Equals(optionName, "override-argument") && command == CommandNameType.uninstall) continue;
991+
993992
if (sensitiveArgs)
994993
{
995994
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()));
996995
}
996+
else
997+
{
998+
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()));
999+
}
9971000
packageArguments.Add("--{0}{1}".format_with(optionName, string.IsNullOrWhiteSpace(optionValue) ? string.Empty : "=" + optionValue));
9981001
}
9991002

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

14421445
foreach (var packageVersion in packageVersionsToRemove)
14431446
{
1447+
// reset config each time through
1448+
config = originalConfig.deep_copy();
1449+
14441450
var pkgInfo = _packageInfoService.get_package_information(packageVersion);
14451451
if (pkgInfo != null && pkgInfo.IsPinned)
14461452
{
@@ -1452,6 +1458,8 @@ public virtual ConcurrentDictionary<string, PackageResult> uninstall_run(Chocola
14521458
continue;
14531459
}
14541460

1461+
set_package_config_from_remembered_args(config, pkgInfo, CommandNameType.uninstall);
1462+
14551463
if (performAction)
14561464
{
14571465
try
@@ -1498,6 +1506,7 @@ public virtual ConcurrentDictionary<string, PackageResult> uninstall_run(Chocola
14981506
var result = packageUninstalls.GetOrAdd(packageVersion.Id.to_lower() + "." + packageVersion.Version.to_string(), new PackageResult(packageVersion, _fileSystem.combine_paths(ApplicationParameters.PackagesLocation, packageVersion.Id)));
14991507
if (continueAction != null) continueAction.Invoke(result);
15001508
}
1509+
resetConfigAction.Invoke(originalConfig);
15011510
}
15021511
}
15031512

0 commit comments

Comments
 (0)