Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(#1185) Add original powershell host run as deprecated method #2831

Merged
merged 2 commits into from
Sep 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017 - 2021 Chocolatey Software, Inc
// Copyright © 2017 - 2022 Chocolatey Software, Inc
// Copyright © 2011 - 2017 RealDimensions Software, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -68,6 +68,10 @@ public interface IPowershellService
bool before_modify(ChocolateyConfiguration configuration, PackageResult packageResult);

void prepare_powershell_environment(IPackage package, ChocolateyConfiguration configuration, string packageDirectory);

[Obsolete("This version of running the powershell host do not support running additional hooks. Use the appropriate overload instead")]
PowerShellExecutionResults run_host(ChocolateyConfiguration config, string chocoPowerShellScript, Action<Pipeline> additionalActionsBeforeScript);

PowerShellExecutionResults run_host(ChocolateyConfiguration config, string chocoPowerShellScript, Action<Pipeline> additionalActionsBeforeScript, IEnumerable<string> hookPreScriptPathList, IEnumerable<string> hookPostScriptPathList);
}
}
21 changes: 12 additions & 9 deletions src/chocolatey/infrastructure.app/services/PowershellService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright © 2017 - 2021 Chocolatey Software, Inc
// Copyright © 2017 - 2022 Chocolatey Software, Inc
// Copyright © 2011 - 2017 RealDimensions Software, LLC
//
// Licensed under the Apache License, Version 2.0 (the "License");
Expand All @@ -23,10 +23,7 @@ namespace chocolatey.infrastructure.app.services
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Reflection;
using System.Security.Cryptography;
using System.Text;
using adapters;
using builders;
using commandline;
using configuration;
using cryptography;
Expand All @@ -38,8 +35,6 @@ namespace chocolatey.infrastructure.app.services
using powershell;
using results;
using utility;
using Assembly = adapters.Assembly;
using Console = System.Console;
using CryptoHashProvider = cryptography.CryptoHashProvider;
using Environment = System.Environment;
using IFileSystem = filesystem.IFileSystem;
Expand Down Expand Up @@ -112,12 +107,15 @@ private IEnumerable<string> get_hook_scripts(ChocolateyConfiguration configurati
case CommandNameType.install:
filenameBase += "install-";
break;

case CommandNameType.uninstall:
filenameBase += "uninstall-";
break;

case CommandNameType.upgrade:
filenameBase += "beforemodify-";
break;

default:
throw new ApplicationException("Could not find CommandNameType '{0}' to get hook scripts".format_with(command));
}
Expand Down Expand Up @@ -353,7 +351,6 @@ public bool run_action(ChocolateyConfiguration configuration, PackageResult pack
`choco -h` for details.");
}


if (result.ExitCode != 0)
{
Environment.ExitCode = result.ExitCode;
Expand Down Expand Up @@ -534,7 +531,7 @@ public void prepare_powershell_environment(IPackage package, ChocolateyConfigura
}
}

SecurityProtocol.set_protocol(configuration, provideWarning:false);
SecurityProtocol.set_protocol(configuration, provideWarning: false);
}

private ResolveEventHandler _handler = null;
Expand Down Expand Up @@ -593,6 +590,12 @@ private void remove_assembly_resolver()
}
}

[Obsolete("This version of running the powershell host do not support running additional hooks. Use the appropriate overload instead")]
public PowerShellExecutionResults run_host(ChocolateyConfiguration config, string chocoPowershellScript, Action<Pipeline> additionalActionsBeforeScript)
{
return run_host(config, chocoPowershellScript, additionalActionsBeforeScript, Enumerable.Empty<string>(), Enumerable.Empty<string>());
}

public PowerShellExecutionResults run_host(ChocolateyConfiguration config, string chocoPowerShellScript, Action<Pipeline> additionalActionsBeforeScript, IEnumerable<string> hookPreScriptPathList, IEnumerable<string> hookPostScriptPathList)
{
// since we control output in the host, always set these true
Expand Down Expand Up @@ -732,11 +735,11 @@ public PowerShellExecutionResults run_host(ChocolateyConfiguration config, strin
if (host.ExitCode == 0) host.SetShouldExit(1);
host.HostException = pipeline.PipelineStateInfo.Reason;
break;

case PipelineState.Completed:
if (host.ExitCode == -1) host.SetShouldExit(0);
break;
}

}
}
}
Expand Down