summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormwrock <matt@mattwrock.com>2020-10-30 13:54:16 -0700
committermwrock <matt@mattwrock.com>2020-10-30 13:54:16 -0700
commit31e13be0222e96d3f9b194b2530d6a0a1892a117 (patch)
tree2fd2cab8ea623d9abca2f9252132c9d3a49b80cc
parentb5eab58d40da1c69178aa6f59d05b49fd2b44300 (diff)
downloadchef-31e13be0222e96d3f9b194b2530d6a0a1892a117.tar.gz
fix habitat adembly resolution failures
Signed-off-by: mwrock <matt@mattwrock.com>
-rw-r--r--lib/chef/powershell.rb10
1 files changed, 9 insertions, 1 deletions
diff --git a/lib/chef/powershell.rb b/lib/chef/powershell.rb
index 905b92ebfb..4800708dfc 100644
--- a/lib/chef/powershell.rb
+++ b/lib/chef/powershell.rb
@@ -63,7 +63,15 @@ class Chef
def exec(script)
FFI.ffi_lib @dll
FFI.attach_function :execute_powershell, :ExecuteScript, [:string], :pointer
- execution = FFI.execute_powershell(script).read_utf16string
+ # This is a temporary fix for running in a Habitat environment
+ # In habitat we set CHEF_POWERSHELL_BIN so that .Net resolves our
+ # managed shim assembly from the correct location.
+ # It seems that that is preventing .Net from successfully loading GAC assemblies
+ # and can break all sorts of edge (and not so edge) scenarios. Once we are actually
+ # inside the powershell run space, we know our shim was loaded and can unset
+ # CHEF_POWERSHELL_BIN which will bypass our custom resolver logic. The real fix is
+ # to fix our resolver. Oh and OH MY GOD this was a pain to track down.
+ execution = FFI.execute_powershell("$ENV:CHEF_POWERSHELL_BIN=$NULL;#{script}").read_utf16string
hashed_outcome = Chef::JSONCompat.parse(execution)
@result = Chef::JSONCompat.parse(hashed_outcome["result"])
@errors = hashed_outcome["errors"]