Skip to content

Commit

Permalink
Merge pull request #410 from UnderpantsGnome/fix-pathname
Browse files Browse the repository at this point in the history
call #to_s on remote so Pathnames don't go 💥
  • Loading branch information
mattbrictson authored Nov 13, 2017
2 parents 4544954 + 5ee1c93 commit 05a4322
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ appear at the top.
## [Unreleased][]

* Your contribution here!
* [#410](https://github.com/capistrano/sshkit/pull/410): call #to_s on remote so Pathnames don't go :boom: - [@UnderpantsGnome](https://github.com/UnderpantsGnome)

## [1.15.0][] (2017-11-03)

Expand Down
4 changes: 2 additions & 2 deletions lib/sshkit/backends/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def initialize(_ = nil, &block)
end

def upload!(local, remote, options = {})
remote = File.join(pwd_path, remote) unless remote.start_with?("/")
remote = File.join(pwd_path, remote) unless remote.to_s.start_with?("/")
if local.is_a?(String)
if options[:recursive]
FileUtils.cp_r(local, remote)
Expand All @@ -26,7 +26,7 @@ def upload!(local, remote, options = {})
end

def download!(remote, local=nil, _options = {})
remote = File.join(pwd_path, remote) unless remote.start_with?("/")
remote = File.join(pwd_path, remote) unless remote.to_s.start_with?("/")
if local.nil?
FileUtils.cp(remote, File.basename(remote))
else
Expand Down
4 changes: 2 additions & 2 deletions lib/sshkit/backends/netssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ def assign_defaults

def upload!(local, remote, options = {})
summarizer = transfer_summarizer('Uploading', options)
remote = File.join(pwd_path, remote) unless remote.start_with?("/")
remote = File.join(pwd_path, remote) unless remote.to_s.start_with?("/")
with_ssh do |ssh|
ssh.scp.upload!(local, remote, options, &summarizer)
end
end

def download!(remote, local=nil, options = {})
summarizer = transfer_summarizer('Downloading', options)
remote = File.join(pwd_path, remote) unless remote.start_with?("/")
remote = File.join(pwd_path, remote) unless remote.to_s.start_with?("/")
with_ssh do |ssh|
ssh.scp.download!(remote, local, options, &summarizer)
end
Expand Down
10 changes: 10 additions & 0 deletions test/functional/backends/test_local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ def test_upload
end
end

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

def test_upload_within
file_contents = "Some Content"
actual_file_contents = nil
Expand Down
10 changes: 10 additions & 0 deletions test/functional/backends/test_netssh.rb
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,16 @@ def test_upload_large_file
assert_equal File.open(file_name).read, file_contents
end

def test_upload_via_pathname
file_contents = ""
Netssh.new(a_host) do |_host|
file_name = Pathname.new(File.join("/tmp", SecureRandom.uuid))
upload!(StringIO.new('example_io'), file_name)
file_contents = download!(file_name)
end.run
assert_equal "example_io", file_contents
end

def test_interaction_handler
captured_command_result = nil
Netssh.new(a_host) do
Expand Down

0 comments on commit 05a4322

Please sign in to comment.