diff options
author | Robin H. Johnson <robbat2@gentoo.org> | 2015-02-23 18:16:55 -0800 |
---|---|---|
committer | Robin H. Johnson <robbat2@gentoo.org> | 2015-02-23 18:16:55 -0800 |
commit | ef43e934de266b49dec9373cb6c281c0ee7c67dc (patch) | |
tree | 6f2847e47bb49bc515fd8d99b64ba0d8ec3c38c3 /ag | |
parent | Remove dead code. (diff) | |
download | backend-ef43e934de266b49dec9373cb6c281c0ee7c67dc.tar.gz backend-ef43e934de266b49dec9373cb6c281c0ee7c67dc.tar.bz2 backend-ef43e934de266b49dec9373cb6c281c0ee7c67dc.zip |
Improve delete code paths.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
Diffstat (limited to 'ag')
-rwxr-xr-x | ag | 37 |
1 files changed, 23 insertions, 14 deletions
@@ -26,41 +26,46 @@ $options.debug = false $options.readonly = false $options.jobs = false $options.progress = true +$options.need_argument = true +$options.argmode = nil op = OptionParser.new do |opts| opts.banner = "Usage: ag <<--index-full|--index-new|--delete-msg|--delete-index|--reindex|--info> <--list listname>> <[--file|--msgid|--hash] <maildir/file/hash/messageid>> [options]" - opts.on('--index-full', 'Read the full past archive from the .cur Maildir') do + opts.on('--index-full', 'Read the full past archive from Maildir/cur. Needs --list and a Maildir') do abort 'Can only select one action' if $options.action != nil $options.action = :do_full + $options.argmode = :dir end - opts.on('--index-new', 'Read new messages from .new and move them to .cur') do + opts.on('--index-new', 'Read new messages from Maildir/new and move them to Maildir/cur. Needs --list and a Maildir') do abort 'Can only select one action' if $options.action != nil $options.action = :do_incremental + $options.argmode = :dir end - opts.on('--delete-msg', 'Delete message. Needs --file, --msgid, or --hash') do + opts.on('--delete-msg', 'Delete message. Needs --list and one of --file, --msgid, or --hash') do abort 'Can only select one action' if $options.action != nil $options.action = :do_delete_msg end - - opts.on('--delete-Index', 'Delete index. Needs --list') do + + opts.on('--delete-index', 'Delete index. Needs --list') do abort 'Can only select one action' if $options.action != nil $options.action = :do_index + $options.need_argument = false end - opts.on('--info', 'Display message details. Needs --file, --msgid, or --hash') do + opts.on('--info', 'Display message details. Needs --list and one of --file, --msgid, or --hash') do abort 'Can only select one action' if $options.action != nil $options.action = :do_info end - opts.on('--reindex', 'Reindex message. Needs --file') do + opts.on('--reindex', 'Reindex message. Needs --list and --file') do abort 'Can only select one action' if $options.action != nil $options.action = :do_reindex @@ -105,7 +110,7 @@ op = OptionParser.new do |opts| opts.on('--jobs JOBS', 'Number of parallel jobs to run (defaults to 75% of core count)') do |jobs| $options.jobs = jobs.to_i end - + opts.on('--progress', 'Display the progress bar') do $options.progress = true end @@ -117,11 +122,13 @@ op.parse! abort op.help unless $options.action abort 'List name required' unless $options.name -$options.dir = ARGV[0] or abort 'Need a Maildir/File/Hash/Message-Id to work with' +$options.dir = ARGV[0] or abort 'Need a Maildir/File/Hash/Message-Id to work with' if $options.need_argument -# Open maildir and set serializer -$maildir = Maildir.new(File.join($options.dir), false) -$maildir.serializer = Maildir::Serializer::Mail.new +if($options.argmode == :dir) + # Open maildir and set serializer + $maildir = Maildir.new(File.join($options.dir), false) + $maildir.serializer = Maildir::Serializer::Mail.new +end # Connect to Elasticsearch $es = Elasticsearch::Client.new(log: false) @@ -132,12 +139,13 @@ Ag::Utils.proc_count = $options.jobs ############################################################################### def do_full + abort "Wrong argument type: #{$options.argmode.to_s}" unless $options.argmode == :dir Ag::Storage.create_index($options.name) messages = $maildir.list(:cur) opts = { - :in_processes => Ag::Utils.proc_count, + :in_processes => Ag::Utils.proc_count, } opts[:progress] = "Importing #{$options.name}" if $options.progress Parallel.each(messages, opts) do |maildir_message| @@ -155,10 +163,11 @@ def do_full end def do_incremental + abort "Wrong argument type: #{$options.argmode.to_s}" unless $options.argmode == :dir messages = $maildir.list(:cur) opts = { - :in_processes => Ag::Utils.proc_count, + :in_processes => Ag::Utils.proc_count, } opts[:progress] = "Importing #{$options.name}" if $options.progress Parallel.each(messages, opts) do |maildir_message| |