lib/sup/source.rb in sup-0.11 vs lib/sup/source.rb in sup-0.12
- old
+ new
@@ -57,56 +57,43 @@
## pummelled from multiple threads at once.
##
## Examples for you to look at: mbox/loader.rb, imap.rb, and
## maildir.rb.
- ## let's begin!
- ##
- ## dirty? means cur_offset has changed, so the source info needs to
- ## be re-saved to sources.yaml.
- bool_reader :usual, :archived, :dirty
- attr_reader :uri, :cur_offset
+ bool_accessor :usual, :archived
+ attr_reader :uri
attr_accessor :id
- def initialize uri, initial_offset=nil, usual=true, archived=false, id=nil
+ def initialize uri, usual=true, archived=false, id=nil
raise ArgumentError, "id must be an integer: #{id.inspect}" unless id.is_a? Fixnum if id
@uri = uri
- @cur_offset = initial_offset
@usual = usual
@archived = archived
@id = id
- @dirty = false
end
## overwrite me if you have a disk incarnation (currently used only for sup-sync-back)
def file_path; nil end
def to_s; @uri.to_s; end
- def seek_to! o; self.cur_offset = o; end
- def reset!; seek_to! start_offset; end
def == o; o.uri == uri; end
- def done?; start_offset.nil? || (self.cur_offset ||= start_offset) >= end_offset; end
def is_source_for? uri; uri == @uri; end
- ## check should throw a FatalSourceError or an OutOfSyncSourcError
- ## if it can detect a problem. it is called when the sup starts up
- ## to proactively notify the user of any source problems.
- def check; end
+ def read?; false; end
- ## yields successive offsets and labels, starting at #cur_offset.
- ##
- ## when implementing a source, you can overwrite either #each or #next. the
- ## default #each just calls next over and over.
- def each
- self.cur_offset ||= start_offset
- until done?
- offset, labels = self.next
- yield offset, labels
- end
+ ## Yields values of the form [Symbol, Hash]
+ ## add: info, labels, progress
+ ## delete: info, progress
+ def poll
+ unimplemented
end
+ def valid? info
+ true
+ end
+
## utility method to read a raw email header from an IO stream and turn it
## into a hash of key-value pairs. minor special semantics for certain headers.
##
## THIS IS A SPEED-CRITICAL SECTION. Everything you do here will have a
## significant effect on Sup's processing speed of email from ALL sources.
@@ -152,15 +139,10 @@
def parse_raw_email_header f; self.class.parse_raw_email_header f end
def Source.expand_filesystem_uri uri
uri.gsub "~", File.expand_path("~")
end
-
- def cur_offset= o
- @cur_offset = o
- @dirty = true
- end
end
## if you have a @labels instance variable, include this
## to serialize them nicely as an array, rather than as a
## nasty set.
@@ -208,19 +190,19 @@
def source_for uri; sources.find { |s| s.is_source_for? uri }; end
def usual_sources; sources.find_all { |s| s.usual? }; end
def unusual_sources; sources.find_all { |s| !s.usual? }; end
def load_sources fn=Redwood::SOURCE_FN
- source_array = (Redwood::load_yaml_obj(fn) || []).map { |o| Recoverable.new o }
+ source_array = Redwood::load_yaml_obj(fn) || []
@source_mutex.synchronize do
@sources = Hash[*(source_array).map { |s| [s.id, s] }.flatten]
@sources_dirty = false
end
end
def save_sources fn=Redwood::SOURCE_FN
@source_mutex.synchronize do
- if @sources_dirty || @sources.any? { |id, s| s.dirty? }
+ if @sources_dirty
bakfn = fn + ".bak"
if File.exists? fn
File.chmod 0600, fn
FileUtils.mv fn, bakfn, :force => true unless File.exists?(bakfn) && File.size(fn) == 0
end