summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Higgins <pete@peterhiggins.org>2020-05-28 18:08:15 -0700
committerPete Higgins <pete@peterhiggins.org>2020-06-03 11:46:53 -0700
commit6ffb5cafd1292a0a5f2149f82e2b978db120607d (patch)
tree8d2686c48b4dec9aa4bf1ad542c8ad10ad874301
parent8b7af81b7a4e3f177c9f02bf4738558d922c4b4f (diff)
downloadchef-6ffb5cafd1292a0a5f2149f82e2b978db120607d.tar.gz
Cleanup some shared code in WindowsScript and children.
Signed-off-by: Pete Higgins <pete@peterhiggins.org>
-rw-r--r--lib/chef/provider/batch.rb2
-rw-r--r--lib/chef/provider/powershell_script.rb2
-rw-r--r--lib/chef/provider/windows_script.rb32
3 files changed, 16 insertions, 20 deletions
diff --git a/lib/chef/provider/batch.rb b/lib/chef/provider/batch.rb
index a8504fa656..500cac7bcd 100644
--- a/lib/chef/provider/batch.rb
+++ b/lib/chef/provider/batch.rb
@@ -25,8 +25,6 @@ class Chef
provides :batch
def command
- basepath = is_forced_32bit ? wow64_directory : run_context.node["kernel"]["os_info"]["system_directory"]
-
interpreter_path = Chef::Util::PathHelper.join(basepath, interpreter)
"\"#{interpreter_path}\" #{flags} \"#{script_file.path}\""
diff --git a/lib/chef/provider/powershell_script.rb b/lib/chef/provider/powershell_script.rb
index e0d6704936..b55bed224d 100644
--- a/lib/chef/provider/powershell_script.rb
+++ b/lib/chef/provider/powershell_script.rb
@@ -32,8 +32,6 @@ class Chef
end
def command
- basepath = is_forced_32bit ? wow64_directory : run_context.node["kernel"]["os_info"]["system_directory"]
-
# Powershell.exe is always in "v1.0" folder (for backwards compatibility)
interpreter_path = Chef::Util::PathHelper.join(basepath, "WindowsPowerShell", "v1.0", interpreter)
diff --git a/lib/chef/provider/windows_script.rb b/lib/chef/provider/windows_script.rb
index dcc38e94f7..050407030a 100644
--- a/lib/chef/provider/windows_script.rb
+++ b/lib/chef/provider/windows_script.rb
@@ -23,24 +23,24 @@ class Chef
class Provider
class WindowsScript < Chef::Provider::Script
- attr_reader :is_forced_32bit
-
protected
include Chef::Mixin::WindowsArchitectureHelper
- def initialize(new_resource, run_context)
- super
-
- target_architecture = if new_resource.architecture.nil?
- node_windows_architecture(run_context.node)
- else
- new_resource.architecture
- end
-
- @is_wow64 = wow64_architecture_override_required?(run_context.node, target_architecture)
+ def target_architecture
+ @target_architecture ||= if new_resource.architecture.nil?
+ node_windows_architecture(run_context.node)
+ else
+ new_resource.architecture
+ end
+ end
- @is_forced_32bit = forced_32bit_override_required?(run_context.node, target_architecture)
+ def basepath
+ if forced_32bit_override_required?(run_context.node, target_architecture)
+ wow64_directory
+ else
+ run_context.node["kernel"]["os_info"]["system_directory"]
+ end
end
public
@@ -48,8 +48,8 @@ class Chef
action :run do
wow64_redirection_state = nil
- if @is_wow64
- wow64_redirection_state = disable_wow64_file_redirection(@run_context.node)
+ if wow64_architecture_override_required?(run_context.node, target_architecture)
+ wow64_redirection_state = disable_wow64_file_redirection(run_context.node)
end
begin
@@ -58,7 +58,7 @@ class Chef
raise
ensure
unless wow64_redirection_state.nil?
- restore_wow64_file_redirection(@run_context.node, wow64_redirection_state)
+ restore_wow64_file_redirection(run_context.node, wow64_redirection_state)
end
end
end