Class: Redwood::MBox::SSHFile
Overview
the file-like interface to a remote file
Constant Summary collapse
- MAX_BUF_SIZE =
bytes
1024 * 1024
- MAX_TRANSFER_SIZE =
1024 * 128
- REASONABLE_TRANSFER_SIZE =
1024 * 32
- SIZE_CHECK_INTERVAL =
seconds
60 * 1
- RECOVERABLE_ERRORS =
upon these errors we’ll try to rereconnect a few times
[ Errno::EPIPE, Errno::ETIMEDOUT ]
- @@shells =
{}
- @@shells_mutex =
Mutex.new
Instance Method Summary collapse
- #connect ⇒ Object
-
#eof ⇒ Object
lame but IO’s method is named this and rmail calls that.
- #eof? ⇒ Boolean
- #gets ⇒ Object
-
#initialize(host, fn, ssh_opts = {}) ⇒ SSHFile
constructor
A new instance of SSHFile.
- #read(n) ⇒ Object
- #seek(loc) ⇒ Object
- #size ⇒ Object
- #tell ⇒ Object
-
#to_s ⇒ Object
TODO: remove this EVILness.
- #total ⇒ Object
Constructor Details
#initialize(host, fn, ssh_opts = {}) ⇒ SSHFile
Returns a new instance of SSHFile.
101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/sup/mbox/ssh-file.rb', line 101 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 |
Instance Method Details
#connect ⇒ Object
116 117 118 |
# File 'lib/sup/mbox/ssh-file.rb', line 116 def connect do_remote nil end |
#eof ⇒ Object
lame but IO’s method is named this and rmail calls that
121 |
# File 'lib/sup/mbox/ssh-file.rb', line 121 def eof; eof?; end |
#eof? ⇒ Boolean
120 |
# File 'lib/sup/mbox/ssh-file.rb', line 120 def eof?; @offset >= size; end |
#gets ⇒ Object
134 135 136 137 138 139 140 141 |
# File 'lib/sup/mbox/ssh-file.rb', line 134 def gets return nil if eof? @buf_mutex.synchronize do make_buf_include @offset while @buf.index("\n", @offset).nil? && @buf.endd < size returning(@buf[@offset .. (@buf.index("\n", @offset) || -1)]) { |line| @offset += line.length } end end |
#read(n) ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/sup/mbox/ssh-file.rb', line 143 def read n return nil if eof? @buf_mutex.synchronize do make_buf_include @offset, n @buf[@offset ... (@offset += n)] end end |
#seek(loc) ⇒ Object
122 |
# File 'lib/sup/mbox/ssh-file.rb', line 122 def seek loc; @offset = loc; end |
#size ⇒ Object
126 127 128 129 130 131 132 |
# File 'lib/sup/mbox/ssh-file.rb', line 126 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 ⇒ Object
123 |
# File 'lib/sup/mbox/ssh-file.rb', line 123 def tell; @offset; end |
#to_s ⇒ Object
TODO: remove this EVILness
114 |
# File 'lib/sup/mbox/ssh-file.rb', line 114 def to_s; "mbox+ssh://#@host/#@fn"; end |
#total ⇒ Object
124 |
# File 'lib/sup/mbox/ssh-file.rb', line 124 def total; size; end |