From e7d7d32f5389bd4ad0ebd9f1fcca69f579f0ccbd Mon Sep 17 00:00:00 2001 From: Jerry Aldrich Date: Mon, 27 Nov 2017 12:24:02 -0600 Subject: [PATCH] Make changes to integrate @jquick's cacheing magic Signed-off-by: Jerry Aldrich --- lib/train/transports/local.rb | 54 +++++++++++------------------------ 1 file changed, 16 insertions(+), 38 deletions(-) diff --git a/lib/train/transports/local.rb b/lib/train/transports/local.rb index 9f169937..bedb8be6 100644 --- a/lib/train/transports/local.rb +++ b/lib/train/transports/local.rb @@ -36,25 +36,10 @@ def initialize(options) end end - def run_command(cmd) - @runner.run_command(cmd) - rescue Errno::ENOENT => _ - CommandResult.new('', '', 1) - end - def local? true end - def file(path) - @files[path] ||= \ - if os.windows? - Train::File::Local::Windows.new(self, path) - else - Train::File::Local::Unix.new(self, path) - end - end - def login_command nil # none, open your shell end @@ -63,6 +48,22 @@ def uri 'local://' end + private + + def run_command_via_connection(cmd) + @runner.run_command(cmd) + rescue Errno::ENOENT => _ + CommandResult.new('', '', 1) + end + + def file_via_connection(path) + if os.windows? + Train::File::Local::Windows.new(self, path) + else + Train::File::Local::Unix.new(self, path) + end + end + class GenericRunner attr_writer :cmd_wrapper @@ -203,29 +204,6 @@ def start_pipe_server(pipe_name) at_exit { Process.kill('KILL', server_pid) } end end - - def run_command_via_connection(cmd) - if defined?(@platform) && @platform.windows? - start_named_pipe_server unless File.exist?('//localhost/pipe/InSpec') - res = run_powershell_using_named_pipe(cmd) - CommandResult.new(res['stdout'], res['stderr'], res['exitstatus']) - else - cmd = @cmd_wrapper.run(cmd) unless @cmd_wrapper.nil? - res = Mixlib::ShellOut.new(cmd) - res.run_command - CommandResult.new(res.stdout, res.stderr, res.exitstatus) - end - rescue Errno::ENOENT => _ - CommandResult.new('', '', 1) - end - - def file_via_connection(path) - if os.windows? - Train::File::Local::Windows.new(self, path) - else - Train::File::Local::Unix.new(self, path) - end - end end end end