From: William Morgan Date: Mon, 4 May 2009 12:29:54 +0000 (-0700) Subject: make sup-sync's --start-at actually useful X-Git-Url: https://git.cworth.org/git?a=commitdiff_plain;h=de8e4e9c60e0b30186c1638b5ee9da9480242feb;p=sup 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.) --- diff --git a/bin/sup-sync b/bin/sup-sync index 91710d4..4d7a3d3 100644 --- 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 index 7fe9129..65d0bd1 100644 --- 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