commit de8e4e9c60e0b30186c1638b5ee9da9480242feb
parent 4f20ab55d1b6b609562a18b86bf87ce4c77c36a7
Author: William Morgan <wmorgan-sup@masanjin.net>
Date: Mon, 4 May 2009 05:29:54 -0700
make sup-sync's --start-at actually useful
Using --start-at with sup-sync will now seek forward to the next valid message
if given an offset that's not on a message boundary. This makes it possible to
use that option without going through the laborious process of finding the
exact message boundary.
Also die unless --start-at is used with only one source, since using it across
multiple sources is almost definitely an error. (And if that's really what you
want, you can just call sup-sync multiple times.)
Diffstat:
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/bin/sup-sync b/bin/sup-sync
@@ -122,7 +122,9 @@ begin
unless target == :new
if opts[:start_at]
- sources.each { |s| s.seek_to! opts[:start_at] }
+ Trollop::die :start_at, "can only be used on one source" unless sources.size == 1
+ sources.first.seek_to! opts[:start_at]
+ sources.first.correct_offset! if sources.first.respond_to?(:correct_offset!)
else
sources.each { |s| s.reset! }
end
@@ -200,9 +202,7 @@ begin
## API.
##
## TODO: move this to Index, i suppose.
-
-
- if target == :all || target == :changed
+ if (target == :all || target == :changed) && !opts[:start_at]
$stderr.puts "Deleting missing messages from the index..."
num_del, num_scanned = 0, 0
sources.each do |source|
diff --git a/lib/sup/mbox/loader.rb b/lib/sup/mbox/loader.rb
@@ -81,6 +81,18 @@ class Loader < Source
end
end
+ ## scan forward until we're at the valid start of a message
+ def correct_offset!
+ @mutex.synchronize do
+ @f.seek cur_offset
+ string = ""
+ until @f.eof? || (l = @f.gets) =~ BREAK_RE
+ string << l
+ end
+ self.cur_offset += string.length
+ end
+ end
+
def raw_header offset
ret = ""
@mutex.synchronize do