-
Notifications
You must be signed in to change notification settings - Fork 257
Expand file tree
/
Copy pathlocal.rb
More file actions
66 lines (58 loc) · 1.77 KB
/
Copy pathlocal.rb
File metadata and controls
66 lines (58 loc) · 1.77 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'open3'
require 'fileutils'
module SSHKit
module Backend
class Local < Abstract
def initialize(**options, &block)
super(Host.new(:local), **options, &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