lib/sup/source.rb in sup-0.12 vs lib/sup/source.rb in sup-0.12.1
- old
+ new
@@ -38,10 +38,11 @@
## - load_header offset
## - load_message offset
## - raw_header offset
## - raw_message offset
## - check (optional)
+ ## - go_idle (optional)
## - next (or each, if you prefer): should return a message and an
## array of labels.
##
## ... where "offset" really means unique id. (You can tell I
## started with mbox.)
@@ -79,10 +80,15 @@
def == o; o.uri == uri; end
def is_source_for? uri; uri == @uri; end
def read?; false; end
+ ## release resources that are easy to reacquire. it is called
+ ## after processing a source (e.g. polling) to prevent resource
+ ## leaks (esp. file descriptors).
+ def go_idle; end
+
## Yields values of the form [Symbol, Hash]
## add: info, labels, progress
## delete: info, progress
def poll
unimplemented
@@ -147,11 +153,11 @@
## to serialize them nicely as an array, rather than as a
## nasty set.
module SerializeLabelsNicely
def before_marshal # can return an object
c = clone
- c.instance_eval { @labels = @labels.to_a.map { |l| l.to_s } }
+ c.instance_eval { @labels = (@labels.to_a.map { |l| l.to_s }).sort }
c
end
def after_unmarshal!
@labels = Set.new(@labels.map { |s| s.to_sym })
@@ -185,11 +191,15 @@
def sources
## favour the inbox by listing non-archived sources first
@source_mutex.synchronize { @sources.values }.sort_by { |s| s.id }.partition { |s| !s.archived? }.flatten
end
- def source_for uri; sources.find { |s| s.is_source_for? uri }; end
+ def source_for uri
+ expanded_uri = Source.expand_filesystem_uri(uri)
+ sources.find { |s| s.is_source_for? expanded_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) || []
@@ -200,16 +210,10 @@
end
def save_sources fn=Redwood::SOURCE_FN
@source_mutex.synchronize do
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
- Redwood::save_yaml_obj sources, fn, true
- File.chmod 0600, fn
+ Redwood::save_yaml_obj sources, fn, false, true
end
@sources_dirty = false
end
end
end