diff --git a/Gemfile b/Gemfile index e383124..b74bc35 100644 --- a/Gemfile +++ b/Gemfile @@ -13,3 +13,5 @@ if ENV["CI"] gem 'codecov', require: false, group: :test gem 'simplecov', require: false, group: :test end + +gem 'net-ssh' diff --git a/lib/net/sftp.rb b/lib/net/sftp.rb index 6e6941d..96cb68b 100644 --- a/lib/net/sftp.rb +++ b/lib/net/sftp.rb @@ -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) diff --git a/lib/net/sftp/operations/dir.rb b/lib/net/sftp/operations/dir.rb index 58a27b1..13037b7 100644 --- a/lib/net/sftp/operations/dir.rb +++ b/lib/net/sftp/operations/dir.rb @@ -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 diff --git a/lib/net/sftp/operations/file.rb b/lib/net/sftp/operations/file.rb index d031050..42d3543 100644 --- a/lib/net/sftp/operations/file.rb +++ b/lib/net/sftp/operations/file.rb @@ -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 @@ -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 @@ -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 diff --git a/lib/net/sftp/protocol/01/name.rb b/lib/net/sftp/protocol/01/name.rb index b3a8660..999967e 100644 --- a/lib/net/sftp/protocol/01/name.rb +++ b/lib/net/sftp/protocol/01/name.rb @@ -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 @@ -40,4 +40,4 @@ def file? end end -end; end; end; end \ No newline at end of file +end; end; end; end diff --git a/lib/net/sftp/protocol/04/name.rb b/lib/net/sftp/protocol/04/name.rb index 3e6044d..404b67b 100644 --- a/lib/net/sftp/protocol/04/name.rb +++ b/lib/net/sftp/protocol/04/name.rb @@ -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 @@ -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" : "-") @@ -64,4 +64,4 @@ def longname end end -end; end; end; end \ No newline at end of file +end; end; end; end diff --git a/test/test_start.rb b/test/test_start.rb index 51e68df..bdf5ea5 100644 --- a/test/test_start.rb +++ b/test/test_start.rb @@ -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