X-Git-Url: https://git.cworth.org/git?a=blobdiff_plain;f=bin%2Fsup-recover-sources;h=43fa5f640f0fcd862ceac622388a471a8573edc2;hb=b98727cc2feb8175c6834e9b435796c333e96ee3;hp=af39b7df4ed466afa3907cc93128a83ef0eb08dc;hpb=d66683c3375b48810d8f6ca49805943f9997c84f;p=sup diff --git a/bin/sup-recover-sources b/bin/sup-recover-sources index af39b7d..43fa5f6 100755 --- a/bin/sup-recover-sources +++ b/bin/sup-recover-sources @@ -48,13 +48,14 @@ EOS end.parse(ARGV) require "sup" +Redwood::start puts "loading index..." -index = Redwood::Index.new +index = Redwood::Index.init index.load puts "loaded index of #{index.size} messages" ARGV.each do |fn| - next if index.source_for fn + next if Redwood::SourceManager.source_for fn ## TODO: merge this code with the same snippet in import source = @@ -69,29 +70,23 @@ ARGV.each do |fn| Redwood::MBox::Loader.new(fn, nil, !$opts[:unusual], $opts[:archive]) end - source_ids = {} + source_ids = Hash.new 0 count = 0 source.each do |offset, labels| - begin - m = Redwood::Message.new :source => source, :source_info => offset - docid, entry = index.load_entry_for_id m.id - next unless entry - #puts "# #{source} #{offset} #{entry[:source_id]}" - - source_ids[entry[:source_id]] = (source_ids[entry[:source_id]] || 0) + 1 - count += 1 - break if count == $opts[:scan_num] - rescue Redwood::MessageFormatError => e - puts "# #{e.message}" - end + m = Redwood::Message.new :source => source, :source_info => offset + m.load_from_source! + source_id = Redwood::SourceManager.source_for_id m.id + next unless source_id + source_ids[source_id] += 1 + count += 1 + break if count == $opts[:scan_num] end if source_ids.size == 1 id = source_ids.keys.first.to_i puts "assigned #{source} to #{source_ids.keys.first}" source.id = id - source.seek_to! source.total - index.add_source source + Redwood::SourceManager.add_source source else puts ">> unable to determine #{source}: #{source_ids.inspect}" end