Sha256: 52875974569694a9d604f55bab772ffe2c1163ca2ef9e6b3491f140a0209f3f6

Contents?: true

Size: 1.76 KB

Versions: 24

Compression:

Stored size: 1.76 KB

Contents

require 'open3'
require 'fileutils'
module SSHKit

  module Backend

    class Local < Abstract

      def initialize(_ = nil, &block)
        super(Host.new(:local), &block)
      end

      def upload!(local, remote, options = {})
        remote = File.join(pwd_path, remote) unless remote.to_s.start_with?("/") || pwd_path.nil?
        if local.is_a?(String)
          if options[:recursive]
            FileUtils.cp_r(local, remote)
          else
            FileUtils.cp(local, remote)
          end
        else
          File.open(remote, "wb") do |f|
            IO.copy_stream(local, f)
          end
        end
      end

      def download!(remote, local=nil, _options = {})
        remote = File.join(pwd_path, remote) unless remote.to_s.start_with?("/") || pwd_path.nil?
        if local.nil?
          FileUtils.cp(remote, File.basename(remote))
        else
          File.open(remote, "rb") do |f|
            IO.copy_stream(f, local)
          end
        end
      end

      private

      def execute_command(cmd)
        output.log_command_start(cmd.with_redaction)
        cmd.started = Time.now
        Open3.popen3(cmd.to_command) do |stdin, stdout, stderr, wait_thr|
          stdout_thread = Thread.new do
            while (line = stdout.gets) do
              cmd.on_stdout(stdin, line)
              output.log_command_data(cmd, :stdout, line)
            end
          end
          stderr_thread = Thread.new do
            while (line = stderr.gets) do
              cmd.on_stderr(stdin, line)
              output.log_command_data(cmd, :stderr, line)
            end
          end
          stdout_thread.join
          stderr_thread.join
          cmd.exit_status = wait_thr.value.to_i
          output.log_command_exit(cmd)
        end
      end

    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
sshkit-1.23.2 lib/sshkit/backends/local.rb
sshkit-1.23.1 lib/sshkit/backends/local.rb
sshkit-1.23.0 lib/sshkit/backends/local.rb
sshkit-1.22.2 lib/sshkit/backends/local.rb
sshkit-1.22.1 lib/sshkit/backends/local.rb
sshkit-1.22.0 lib/sshkit/backends/local.rb
sshkit-1.21.7 lib/sshkit/backends/local.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/sshkit-1.21.6/lib/sshkit/backends/local.rb
sshkit-1.21.6 lib/sshkit/backends/local.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/sshkit-1.21.5/lib/sshkit/backends/local.rb
sshkit-1.21.5 lib/sshkit/backends/local.rb
sshkit-1.21.4 lib/sshkit/backends/local.rb
sshkit-1.21.3 lib/sshkit/backends/local.rb
sshkit-1.21.2 lib/sshkit/backends/local.rb
sshkit-1.21.1 lib/sshkit/backends/local.rb
sshkit-1.21.0 lib/sshkit/backends/local.rb
honeybadger-4.5.3 vendor/bundle/ruby/2.6.0/gems/sshkit-1.18.2/lib/sshkit/backends/local.rb
sshkit-1.20.0 lib/sshkit/backends/local.rb
sshkit-1.19.1 lib/sshkit/backends/local.rb
sshkit-1.19.0 lib/sshkit/backends/local.rb