Skip to content

Commit 05a4322

Browse files
authored
Merge pull request #410 from UnderpantsGnome/fix-pathname
call #to_s on remote so Pathnames don't go 💥
2 parents 4544954 + 5ee1c93 commit 05a4322

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ appear at the top.
66
## [Unreleased][]
77

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

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

lib/sshkit/backends/local.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ def initialize(_ = nil, &block)
1111
end
1212

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

2828
def download!(remote, local=nil, _options = {})
29-
remote = File.join(pwd_path, remote) unless remote.start_with?("/")
29+
remote = File.join(pwd_path, remote) unless remote.to_s.start_with?("/")
3030
if local.nil?
3131
FileUtils.cp(remote, File.basename(remote))
3232
else

lib/sshkit/backends/netssh.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,15 +63,15 @@ def assign_defaults
6363

6464
def upload!(local, remote, options = {})
6565
summarizer = transfer_summarizer('Uploading', options)
66-
remote = File.join(pwd_path, remote) unless remote.start_with?("/")
66+
remote = File.join(pwd_path, remote) unless remote.to_s.start_with?("/")
6767
with_ssh do |ssh|
6868
ssh.scp.upload!(local, remote, options, &summarizer)
6969
end
7070
end
7171

7272
def download!(remote, local=nil, options = {})
7373
summarizer = transfer_summarizer('Downloading', options)
74-
remote = File.join(pwd_path, remote) unless remote.start_with?("/")
74+
remote = File.join(pwd_path, remote) unless remote.to_s.start_with?("/")
7575
with_ssh do |ssh|
7676
ssh.scp.download!(remote, local, options, &summarizer)
7777
end

test/functional/backends/test_local.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,16 @@ def test_upload
2020
end
2121
end
2222

23+
def test_upload_via_pathname
24+
Dir.mktmpdir do |dir|
25+
File.new("#{dir}/local", 'w')
26+
Local.new do
27+
upload!("#{dir}/local", Pathname.new("#{dir}/remote"))
28+
end.run
29+
assert File.exist?("#{dir}/remote")
30+
end
31+
end
32+
2333
def test_upload_within
2434
file_contents = "Some Content"
2535
actual_file_contents = nil

test/functional/backends/test_netssh.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,16 @@ def test_upload_large_file
145145
assert_equal File.open(file_name).read, file_contents
146146
end
147147

148+
def test_upload_via_pathname
149+
file_contents = ""
150+
Netssh.new(a_host) do |_host|
151+
file_name = Pathname.new(File.join("/tmp", SecureRandom.uuid))
152+
upload!(StringIO.new('example_io'), file_name)
153+
file_contents = download!(file_name)
154+
end.run
155+
assert_equal "example_io", file_contents
156+
end
157+
148158
def test_interaction_handler
149159
captured_command_result = nil
150160
Netssh.new(a_host) do

0 commit comments

Comments
 (0)