lib/sup/mbox/ssh-loader.rb in sup-0.0.7 vs lib/sup/mbox/ssh-loader.rb in sup-0.0.8
- old
+ new
@@ -1,16 +1,11 @@
require 'net/ssh'
module Redwood
module MBox
-## this is slightly complicated because SSHFile (and thus @f or
-## @loader) can throw a variety of exceptions, and we need to catch
-## those, reraise them as SourceErrors, and set ourselves as broken.
-
class SSHLoader < Source
- attr_reader_cloned :labels
attr_accessor :username, :password
def initialize uri, username=nil, password=nil, start_offset=nil, usual=true, archived=false, id=nil
raise ArgumentError, "not an mbox+ssh uri: #{uri.inspect}" unless uri =~ %r!^mbox\+ssh://!
@@ -30,20 +25,18 @@
@loader = Loader.new @f, start_offset, usual, archived, id
## heuristic: use the filename as a label, unless the file
## has a path that probably represents an inbox.
@labels = [:unread]
- @labels << :inbox unless archived?
@labels << File.basename(filename).intern unless File.dirname(filename) =~ /\b(var|usr|spool)\b/
end
def connect; safely { @f.connect }; end
def host; @parsed_uri.host; end
def filename; @parsed_uri.path[1..-1] end
def next
- return if broken?
safely do
offset, labels = @loader.next
self.cur_offset = @loader.cur_offset # superclass keeps @cur_offset which is used by yaml
[offset, (labels + @labels).uniq] # add our labels
end
@@ -60,14 +53,12 @@
def to_s; @parsed_uri.to_s; end
def safely
begin
yield
- rescue Net::SSH::Exception, SocketError, SSHFileError, SystemCallError => e
+ rescue Net::SSH::Exception, SocketError, SSHFileError, SystemCallError, IOError => e
m = "error communicating with SSH server #{host} (#{e.class.name}): #{e.message}"
- Redwood::log m
- self.broken_msg = @loader.broken_msg = m
- raise SourceError, m
+ raise FatalSourceError, m
end
end
[:start_offset, :load_header, :load_message, :raw_header, :raw_full_message].each do |meth|
define_method(meth) { |*a| safely { @loader.send meth, *a } }