Skip to content

Commit

Permalink
(chocolatey#933) Re-use chocolatey that we already have
Browse files Browse the repository at this point in the history
We can't just tell it not to append the logger. If we do that, we cause a regression of 697. But we can use the instance we already have, and just backup and restore the config.
  • Loading branch information
corbob committed Aug 25, 2022
1 parent 6524dbf commit 88d5fb0
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,8 @@ public async Task<PackageOperationResult> InstallPackage(
using (await Lock.WriteLockAsync())
{
var logger = new SerilogLogger(Logger, _progressService);
var choco = Lets.GetChocolatey(initializeLogging: false).SetCustomLogging(logger, logExistingMessages: false, addToExistingLoggers: false);
choco.Set(
var currentConfig = _choco.GetConfiguration();
_choco.Set(
config =>
{
config.CommandName = CommandNameType.install.ToString();
Expand Down Expand Up @@ -244,14 +244,18 @@ public async Task<PackageOperationResult> InstallPackage(

using (logger.Intercept(grabErrors))
{
await choco.RunAsync();
await _choco.RunAsync();

if (Environment.ExitCode != 0)
{
Environment.ExitCode = 0;
return new PackageOperationResult { Successful = false, Messages = errors.ToArray() };
}

_choco.Set(config =>
{
config = currentConfig;
});
return PackageOperationResult.SuccessfulCached;
}
}
Expand Down

0 comments on commit 88d5fb0

Please sign in to comment.