Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle frozen strings #157

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ if ENV["CI"]
gem 'codecov', require: false, group: :test
gem 'simplecov', require: false, group: :test
end

gem 'net-ssh'
2 changes: 1 addition & 1 deletion lib/net/sftp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ module SFTP
#
# Extra parameters can be passed:
# - The Net::SSH connection options (see Net::SSH for more information)
# - The Net::SFTP connection options (only :version is supported, to let you
# - The Net::SFTP connection options (only :version is supported, to let you
# set the SFTP protocol version to be used)
def self.start(host, user, ssh_options={}, sftp_options={}, &block)
session = Net::SSH.start(host, user, ssh_options)
Expand Down
2 changes: 1 addition & 1 deletion lib/net/sftp/operations/dir.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def glob(path, pattern, flags=0)

if entry.directory? && !%w(. ..).include?(::File.basename(entry.name))
queue += entries("#{path}/#{entry.name}").map do |e|
e.name.replace("#{entry.name}/#{e.name}")
e.name = "#{entry.name}/#{e.name}"
e
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/net/sftp/operations/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ def initialize(sftp, handle)
@pos = 0
@real_pos = 0
@real_eof = false
@buffer = ""
@buffer = +""
end

# Repositions the file pointer to the given offset (relative to the
# start of the file). This will also reset the EOF flag.
def pos=(offset)
@real_pos = @pos = offset
@buffer = ""
@buffer = +""
@real_eof = false
end

Expand Down Expand Up @@ -69,9 +69,9 @@ def read(n=nil)
end

if n
result, @buffer = @buffer[0,n], (@buffer[n..-1] || "")
result, @buffer = @buffer[0,n], (@buffer[n..-1] || +"")
else
result, @buffer = @buffer, ""
result, @buffer = @buffer, +""
end

@pos += result.length
Expand Down Expand Up @@ -113,7 +113,7 @@ def gets(sep_or_limit=$/, limit=Float::INFINITY)
elsif !fill
return nil if @buffer.empty?
@pos += @buffer.length
line, @buffer = @buffer, ""
line, @buffer = @buffer, +""
return line
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/net/sftp/protocol/01/name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Net; module SFTP; module Protocol; module V01
# for use when displaying directory data, and has no specified format.
class Name
# The name of the item on the remote server.
attr_reader :name
attr_accessor :name

# The display-ready name of the item, possibly with other attributes.
attr_reader :longname
Expand Down Expand Up @@ -40,4 +40,4 @@ def file?
end
end

end; end; end; end
end; end; end; end
10 changes: 5 additions & 5 deletions lib/net/sftp/protocol/04/name.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ module Net; module SFTP; module Protocol; module V04
# a directory listing.
class Name
# The name of the item on the remote server.
attr_reader :name
attr_accessor :name

# Attributes instance describing this item.
attr_reader :attributes
Expand Down Expand Up @@ -39,11 +39,11 @@ def file?
def longname
@longname ||= begin
longname = if directory?
"d"
+"d"
elsif symlink?
"l"
+"l"
else
"-"
+"-"
end

longname << (attributes.permissions & 0400 != 0 ? "r" : "-")
Expand All @@ -64,4 +64,4 @@ def longname
end
end

end; end; end; end
end; end; end; end
10 changes: 5 additions & 5 deletions test/test_start.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,23 @@ def test_with_block
Net::SFTP::Session.expects(:new).with(ssh, nil).returns(sftp)
sftp.expects(:connect!).returns(sftp)
sftp.expects(:loop)

Net::SFTP.start('host', 'user') do
# NOTE: currently not called!
end
end

def test_with_block_and_options
ssh = mock('ssh')
ssh.expects(:close)
Net::SSH.expects(:start).with('host', 'user', auth_methods: ["password"]).returns(ssh)
Net::SSH.expects(:start).with('host', 'user', { auth_methods: ["password"] }).returns(ssh)

sftp = mock('sftp')
Net::SFTP::Session.expects(:new).with(ssh, 3).returns(sftp)
sftp.expects(:connect!).returns(sftp)
sftp.expects(:loop)
Net::SFTP.start('host', 'user', {auth_methods: ["password"]}, {version: 3}) do

Net::SFTP.start('host', 'user', { auth_methods: ["password"] }, { version: 3 }) do
# NOTE: currently not called!
end
end
Expand Down