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.)
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
## 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|
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