Skip to content

Commit

Permalink
(chocolatey#1092) Update ISourceRunner install_run
Browse files Browse the repository at this point in the history
This addition is necessary, as many occasions may arise where installing
one package involves updating an already-installed dependency. In these
cases we should still be running a beforeModify script if it's present,
and this facilitates that.

(cherry picked from commit 3a30cbc)

# Conflicts:
#	src/chocolatey.tests/infrastructure.app/services/ChocolateyPackageServiceSpecs.cs
  • Loading branch information
vexx32 committed Mar 15, 2023
1 parent 7bfe1ac commit 3ba08c7
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ public override void Context()
var expectedResult = new ConcurrentDictionary<string, PackageResult>();
expectedResult.TryAdd("test-feature", new PackageResult(package.Object, "windowsfeatures", null));

FeaturesRunner.Setup(r => r.install_run(It.IsAny<ChocolateyConfiguration>(), It.IsAny<Action<PackageResult, ChocolateyConfiguration>>()))
FeaturesRunner.Setup(r => r.install_run(It.IsAny<ChocolateyConfiguration>(), It.IsAny<Action<PackageResult, ChocolateyConfiguration>>(), It.IsAny<Action<PackageResult, ChocolateyConfiguration>>()))
.Returns(expectedResult);
NormalRunner.Setup(r => r.install_run(It.IsAny<ChocolateyConfiguration>(), It.IsAny<Action<PackageResult, ChocolateyConfiguration>>()))
NormalRunner.Setup(r => r.install_run(It.IsAny<ChocolateyConfiguration>(), It.IsAny<Action<PackageResult, ChocolateyConfiguration>>(), It.IsAny<Action<PackageResult, ChocolateyConfiguration>>()))
.Returns(new ConcurrentDictionary<string, PackageResult>());
SourceRunners.AddRange(new[] { NormalRunner.Object, FeaturesRunner.Object });

Expand Down Expand Up @@ -127,20 +127,20 @@ public void should_return_package_that_should_have_been_installed()
[Test]
public void should_have_called_runner_for_windows_features_source()
{
FeaturesRunner.Verify(r => r.install_run(It.Is<ChocolateyConfiguration>(c => c.PackageNames == "test-feature"), It.IsAny<Action<PackageResult, ChocolateyConfiguration>>()), Times.Once);
FeaturesRunner.Verify(r => r.install_run(It.Is<ChocolateyConfiguration>(c => c.PackageNames == "test-feature"), It.IsAny<Action<PackageResult, ChocolateyConfiguration>>(), It.IsAny<Action<PackageResult, ChocolateyConfiguration>>()), Times.Once);
}

[Test]
public void should_not_have_called_runner_for_windows_features_source_with_other_package_names()
{
FeaturesRunner.Verify(r => r.install_run(It.Is<ChocolateyConfiguration>(c => c.PackageNames != "test-feature"), It.IsAny<Action<PackageResult, ChocolateyConfiguration>>()), Times.Never);
FeaturesRunner.Verify(r => r.install_run(It.Is<ChocolateyConfiguration>(c => c.PackageNames != "test-feature"), It.IsAny<Action<PackageResult, ChocolateyConfiguration>>(), It.IsAny<Action<PackageResult, ChocolateyConfiguration>>()), Times.Never);
}

[Test]
public void should_not_have_called_normal_source_runner_for_non_empty_packages()
{
// The normal source runners will be called with an argument
NormalRunner.Verify(r => r.install_run(It.Is<ChocolateyConfiguration>(c => c.PackageNames != string.Empty), It.IsAny<Action<PackageResult, ChocolateyConfiguration>>()), Times.Never);
NormalRunner.Verify(r => r.install_run(It.Is<ChocolateyConfiguration>(c => c.PackageNames != string.Empty), It.IsAny<Action<PackageResult, ChocolateyConfiguration>>(), It.IsAny<Action<PackageResult, ChocolateyConfiguration>>()), Times.Never);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -613,7 +613,8 @@ public virtual ConcurrentDictionary<string, PackageResult> install_run(Chocolate
action = (packageResult, configuration) => handle_package_result(packageResult, configuration, CommandNameType.install);
}

var results = perform_source_runner_function(packageConfig, r => r.install_run(packageConfig, action));
var beforeModifyAction = new Action<PackageResult, ChocolateyConfiguration>((packageResult, configuration) => before_package_modify(packageResult, configuration));
var results = perform_source_runner_function(packageConfig, r => r.install_run(packageConfig, action, beforeModifyAction));

foreach (var result in results)
{
Expand Down
5 changes: 5 additions & 0 deletions src/chocolatey/infrastructure.app/services/CygwinService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,11 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult, C
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> continueAction)
{
return install_run(config, continueAction, beforeModifyAction: null);
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> continueAction, Action<PackageResult, ChocolateyConfiguration> beforeModifyAction)
{
var args = build_args(config, _installArguments);
var packageResults = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
Expand Down
11 changes: 10 additions & 1 deletion src/chocolatey/infrastructure.app/services/ISourceRunner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,15 @@ public interface ISourceRunner
/// <returns>results of installs</returns>
ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> continueAction);

/// <summary>
/// Installs packages from the source feed
/// </summary>
/// <param name="config">The configuration.</param>
/// <param name="continueAction">The action to continue with when install is successful.</param>
/// <param name="beforeModifyAction">The action (if any) to run on any currently installed package dependencies before triggering the install or updating those dependencies.</param>
/// <returns>results of installs</returns>
ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> continueAction, Action<PackageResult, ChocolateyConfiguration> beforeModifyAction);

/// <summary>
/// Run upgrade in noop mode
/// </summary>
Expand All @@ -89,7 +98,7 @@ 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="beforeUpgradeAction">The action (if any) to run on any currently installed package before triggering the upgrade.</param>
/// <param name="beforeUpgradeAction">The action (if any) to run on any currently installed package or its dependencies before triggering the upgrade.</param>
/// <returns>results of installs</returns>
ConcurrentDictionary<string, PackageResult> upgrade_run(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> continueAction, Action<PackageResult, ChocolateyConfiguration> beforeUpgradeAction = null);

Expand Down
7 changes: 6 additions & 1 deletion src/chocolatey/infrastructure.app/services/NugetService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,11 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult, C
}

public virtual ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> continueAction)
{
return install_run(config, continueAction, beforeModifyAction: null);
}

public virtual ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> continueAction, Action<PackageResult, ChocolateyConfiguration> beforeModifyAction)
{
_fileSystem.create_directory_if_not_exists(ApplicationParameters.PackagesLocation);
var packageResultsToReturn = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
Expand Down Expand Up @@ -1013,7 +1018,7 @@ public virtual ConcurrentDictionary<string, PackageResult> upgrade_run(Chocolate
}
else
{
var installResults = install_run(config, continueAction);
var installResults = install_run(config, continueAction, beforeUpgradeAction);
foreach (var result in installResults)
{
packageResultsToReturn.GetOrAdd(result.Key, result.Value);
Expand Down
5 changes: 5 additions & 0 deletions src/chocolatey/infrastructure.app/services/PythonService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -337,6 +337,11 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult, C
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> continueAction)
{
return install_run(config, continueAction, beforeModifyAction: null);
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> continueAction, Action<PackageResult, ChocolateyConfiguration> beforeModifyAction)
{
set_executable_path_if_not_set();
var args = build_args(config, _installArguments);
Expand Down
5 changes: 5 additions & 0 deletions src/chocolatey/infrastructure.app/services/RubyGemsService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,11 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult, C
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> continueAction)
{
return install_run(config, continueAction, beforeModifyAction: null);
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> continueAction, Action<PackageResult, ChocolateyConfiguration> beforeModifyAction)
{
var packageResults = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
var args = ExternalCommandArgsBuilder.build_arguments(config, _installArguments);
Expand Down
5 changes: 5 additions & 0 deletions src/chocolatey/infrastructure.app/services/WebPiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,11 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult, C
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> continueAction)
{
return install_run(config, continueAction, beforeModifyAction: null);
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> continueAction, Action<PackageResult, ChocolateyConfiguration> beforeModifyAction)
{
write_deprecation_warning();
var packageResults = new ConcurrentDictionary<string, PackageResult>(StringComparer.InvariantCultureIgnoreCase);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,11 @@ public void install_noop(ChocolateyConfiguration config, Action<PackageResult, C
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> continueAction)
{
return install_run(config, continueAction, beforeModifyAction: null);
}

public ConcurrentDictionary<string, PackageResult> install_run(ChocolateyConfiguration config, Action<PackageResult, ChocolateyConfiguration> continueAction, Action<PackageResult, ChocolateyConfiguration> beforeModifyAction)
{
set_executable_path_if_not_set();
var args = build_args(config, _installArguments);
Expand Down

0 comments on commit 3ba08c7

Please sign in to comment.