Skip to content

Commit

Permalink
(chocolatey#1479) Uninstall run add in resetConfigAction
Browse files Browse the repository at this point in the history
Adds the ability for implementations of uninstall_run to reset the
config in ChocolateyPackageService via the resetConfigAction.
This will be required to prevent an issue similar to chocolatey#1443 for
uninstall, once useRememberedArgumentsForUninstall is added in.
  • Loading branch information
TheCakeIsNaOH committed Mar 10, 2022
1 parent f037ba8 commit 58ba2ee
Show file tree
Hide file tree
Showing 8 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -858,6 +858,8 @@ public virtual ConcurrentDictionary<string, PackageResult> uninstall_run(Chocola

try
{
var resetConfigAction = new Action<ChocolateyConfiguration>(newConfig => config = newConfig.deep_copy());

Action<PackageResult> action = null;
if (config.SourceType == SourceType.normal)
{
Expand All @@ -866,7 +868,7 @@ public virtual ConcurrentDictionary<string, PackageResult> uninstall_run(Chocola

var environmentBefore = get_environment_before(config);
var beforeUninstallAction = new Action<PackageResult>(packageResult => before_package_modify(packageResult, config));
var results = perform_source_runner_function(config, r => r.uninstall_run(config, action, beforeUninstallAction));
var results = perform_source_runner_function(config, r => r.uninstall_run(config, action, resetConfigAction, beforeUninstallAction));

foreach (var result in results)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public void uninstall_noop(ChocolateyConfiguration config, Action<PackageResult>
this.Log().Warn(ChocolateyLoggers.Important, "{0} does not implement uninstall".format_with(APP_NAME));
}

public ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeUninstallAction = null)
public ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<ChocolateyConfiguration> resetConfigAction, Action<PackageResult> beforeUninstallAction = null)
{
throw new NotImplementedException("{0} does not implement upgrade".format_with(APP_NAME));
}
Expand Down
3 changes: 2 additions & 1 deletion src/chocolatey/infrastructure.app/services/ISourceRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,9 @@ public interface ISourceRunner
/// </summary>
/// <param name="config">The configuration.</param>
/// <param name="continueAction">The action to continue with when upgrade is successful.</param>
/// <param name="resetConfigAction">The action that can be used to reset the configuration in the caller</param>
/// <param name="beforeUninstallAction">The action (if any) to run on any currently installed package before triggering the uninstall.</param>
/// <returns>results of installs</returns>
ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeUninstallAction = null);
ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<ChocolateyConfiguration> resetConfigAction, Action<PackageResult> beforeUninstallAction = null);
}
}
9 changes: 5 additions & 4 deletions src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1235,20 +1235,21 @@ private void remove_nuget_cache_for_package(IPackage installedPackage)

public void uninstall_noop(ChocolateyConfiguration config, Action<PackageResult> continueAction)
{
var results = uninstall_run(config, continueAction, performAction: false);
var resetConfigAction = new Action<ChocolateyConfiguration>(newConfig => { });
var results = uninstall_run(config, continueAction, false, resetConfigAction);
foreach (var packageResult in results.or_empty_list_if_null())
{
var package = packageResult.Value.Package;
if (package != null) this.Log().Warn("Would have uninstalled {0} v{1}.".format_with(package.Id, package.Version.to_string()));
}
}

public ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeUninstallAction = null)
public ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<ChocolateyConfiguration> resetConfigAction, Action<PackageResult> beforeUninstallAction = null)
{
return uninstall_run(config, continueAction, performAction: true, beforeUninstallAction: beforeUninstallAction);
return uninstall_run(config, continueAction, true, resetConfigAction, beforeUninstallAction);
}

public virtual ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, bool performAction, Action<PackageResult> beforeUninstallAction = null)
public virtual ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, bool performAction, Action<ChocolateyConfiguration> resetConfigAction, Action<PackageResult> beforeUninstallAction = null)
{
var packageUninstalls = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ public void uninstall_noop(ChocolateyConfiguration config, Action<PackageResult>
this.Log().Info("Would have run '{0} {1}'".format_with(_exePath.escape_curly_braces(), args.escape_curly_braces()));
}

public ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeUninstallAction = null)
public ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<ChocolateyConfiguration> resetConfigAction, Action<PackageResult> beforeUninstallAction = null)
{
set_executable_path_if_not_set();
var args = build_args(config, _uninstallArguments);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public void uninstall_noop(ChocolateyConfiguration config, Action<PackageResult>
this.Log().Warn(ChocolateyLoggers.Important, "{0} does not implement uninstall".format_with(APP_NAME));
}

public ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeUninstallAction = null)
public ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<ChocolateyConfiguration> resetConfigAction, Action<PackageResult> beforeUninstallAction = null)
{
throw new NotImplementedException("{0} does not implement uninstall".format_with(APP_NAME));
}
Expand Down
2 changes: 1 addition & 1 deletion src/chocolatey/infrastructure.app/services/WebPiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public void uninstall_noop(ChocolateyConfiguration config, Action<PackageResult>
this.Log().Warn(ChocolateyLoggers.Important, "{0} does not implement uninstall".format_with(APP_NAME));
}

public ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeUninstallAction = null)
public ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<ChocolateyConfiguration> resetConfigAction, Action<PackageResult> beforeUninstallAction = null)
{
throw new NotImplementedException("{0} does not implement uninstall".format_with(APP_NAME));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public void uninstall_noop(ChocolateyConfiguration config, Action<PackageResult>
this.Log().Info("Would have run '{0} {1}'".format_with(_exePath.escape_curly_braces(), args.escape_curly_braces()));
}

public ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<PackageResult> beforeUninstallAction = null)
public ConcurrentDictionary<string, PackageResult> uninstall_run(ChocolateyConfiguration config, Action<PackageResult> continueAction, Action<ChocolateyConfiguration> resetConfigAction, Action<PackageResult> beforeUninstallAction = null)
{
set_executable_path_if_not_set();
var args = build_args(config, _uninstallArguments);
Expand Down

0 comments on commit 58ba2ee

Please sign in to comment.