class Redwood::MBox::SSHFile

the file-like interface to a remote file

Constants

MAX_BUF_SIZE
MAX_TRANSFER_SIZE
REASONABLE_TRANSFER_SIZE
RECOVERABLE_ERRORS

upon these errors we'll try to rereconnect a few times

SIZE_CHECK_INTERVAL

Public Class Methods

new(host, fn, ssh_opts={}) click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 95
def initialize host, fn, ssh_opts={}
  @buf = Buffer.new
  @host = host
  @fn = fn
  @ssh_opts = ssh_opts
  @file_size = nil
  @offset = 0
  @say_id = nil
  @shell = nil
  @shell_mutex = nil
  @buf_mutex = Mutex.new
end

Public Instance Methods

connect() click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 110
def connect
  do_remote nil
end
eof() click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 115
def eof; eof?; end
eof?() click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 114
def eof?; @offset >= size; end
gets() click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 129
def gets
  return nil if eof?
  @buf_mutex.synchronize do
    make_buf_include @offset
    expand_buf_forward while @buf.index("\n", @offset).nil? && @buf.endd < size
    returning(@buf[@offset .. (@buf.index("\n", @offset) || -1)]) { |line| @offset += line.length }
  end
end
path() click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 119
def path; @fn end
read(n) click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 138
def read n
  return nil if eof?
  @buf_mutex.synchronize do
    make_buf_include @offset, n
    @buf[@offset ... (@offset += n)]
  end
end
seek(loc;) click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 116
def seek loc; @offset = loc; end
size() click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 121
def size
  if @file_size.nil? || (Time.now - @last_size_check) > SIZE_CHECK_INTERVAL
    @last_size_check = Time.now
    @file_size = do_remote("wc -c #@fn").split.first.to_i
  end
  @file_size
end
tell() click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 117
def tell; @offset; end
to_s() click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 108
def to_s; "mbox+ssh://#@host/#@fn"; end
total() click to toggle source
# File lib/sup/mbox/ssh-file.rb, line 118
def total; size; end