Skip to content

Commit

Permalink
Merge pull request #372 from okuramasafumi/patch-1
Browse files Browse the repository at this point in the history
Use cp_r in local backend with recursive option
  • Loading branch information
mattbrictson authored Mar 15, 2017
2 parents 4fecf03 + c4cb8f4 commit da3ff8f
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ appear at the top.

* Your contribution here!
* [#390](https://github.com/capistrano/sshkit/pull/390): Properly wrap Ruby StandardError w/ add'l context - [@mattbrictson](https://github.com/mattbrictson)
* [#372](https://github.com/capistrano/sshkit/pull/372): Use cp_r in local backend with recursive option - [@okuramasafumi](https://github.com/okuramasafumi)

## [1.12.0][] (2017-02-10)

Expand Down
8 changes: 6 additions & 2 deletions lib/sshkit/backends/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,13 @@ def initialize(_ = nil, &block)
super(Host.new(:local), &block)
end

def upload!(local, remote, _options = {})
def upload!(local, remote, options = {})
if local.is_a?(String)
FileUtils.cp(local, remote)
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)
Expand Down
24 changes: 24 additions & 0 deletions test/functional/backends/test_local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,30 @@ def setup
SSHKit.config.output = SSHKit::Formatter::BlackHole.new($stdout)
end

def test_upload
Dir.mktmpdir do |dir|
File.new("#{dir}/local", 'w')
Local.new do
upload!("#{dir}/local", "#{dir}/remote")
end.run
assert File.exist?("#{dir}/remote")
end
end

def test_upload_recursive
Dir.mktmpdir do |dir|
Dir.mkdir("#{dir}/local")
File.new("#{dir}/local/file1", 'w')
File.new("#{dir}/local/file2", 'w')
Local.new do
upload!("#{dir}/local", "#{dir}/remote", recursive: true)
end.run
assert File.directory?("#{dir}/remote")
assert File.exist?("#{dir}/remote/file1")
assert File.exist?("#{dir}/remote/file2")
end
end

def test_capture
captured_command_result = ''
Local.new do
Expand Down

0 comments on commit da3ff8f

Please sign in to comment.