]> git.cworth.org Git - sup/blobdiff - bin/sup-recover-sources
Add new :crypto_default configuration option.
[sup] / bin / sup-recover-sources
old mode 100644 (file)
new mode 100755 (executable)
index af39b7d..43fa5f6
@@ -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