bin/sup-dump in sup-0.11 vs bin/sup-dump in sup-0.12
- old
+ new
@@ -1,28 +1,41 @@
#!/usr/bin/env ruby
require 'rubygems'
+require 'xapian'
require 'trollop'
-require "sup"; Redwood::check_library_version_against "0.11"
+require 'set'
+BASE_DIR = ENV["SUP_BASE"] || File.join(ENV["HOME"], ".sup")
+
$opts = Trollop::options do
- version "sup-dump (sup #{Redwood::VERSION})"
+ version "sup-dump"
banner <<EOS
Dumps all message state from the sup index to standard out. You can
later use sup-sync --restored --restore <filename> to recover the index.
-This tool is primarily useful in the event that a Ferret upgrade breaks
-the index format. This happened, for example, at Ferret version 0.11.
+This tool is primarily useful in the event that a Sup upgrade breaks index
+format compatibility.
Usage:
sup-dump > <filename>
sup-dump | bzip2 > <filename> # even better
EOS
end
-index = Redwood::Index.init
-Redwood::SourceManager.init
-index.load
+xapian = Xapian::Database.new File.join(BASE_DIR, 'xapian')
+version = xapian.get_metadata 'rescue-version'
+version = '0' if version.empty?
-index.each_message :load_spam => true, :load_deleted => true, :load_killed => true do |m|
- puts "#{m.id} (#{m.labels.to_a.sort_by { |l| l.to_s } * ' '})"
+case version
+when '0'
+ xapian.postlist('Kmail').each do |x|
+ begin
+ entry = Marshal.load(xapian.document(x.docid).data)
+ puts "#{entry[:message_id]} (#{entry[:labels].sort_by { |l| l.to_s } * ' '})"
+ rescue
+ $stderr.puts "failed to dump document #{x.docid}"
+ end
+ end
+else
+ abort "this sup-dump version doesn't understand your index"
end