aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2015-02-23 18:16:55 -0800
committerRobin H. Johnson <robbat2@gentoo.org>2015-02-23 18:16:55 -0800
commitef43e934de266b49dec9373cb6c281c0ee7c67dc (patch)
tree6f2847e47bb49bc515fd8d99b64ba0d8ec3c38c3
parentRemove dead code. (diff)
downloadbackend-ef43e934de266b49dec9373cb6c281c0ee7c67dc.tar.gz
backend-ef43e934de266b49dec9373cb6c281c0ee7c67dc.tar.bz2
backend-ef43e934de266b49dec9373cb6c281c0ee7c67dc.zip
Improve delete code paths.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-rwxr-xr-xag37
-rw-r--r--lib/storage.rb4
-rw-r--r--lib/utils.rb6
3 files changed, 33 insertions, 14 deletions
diff --git a/ag b/ag
index 57dc0a4..ffe714b 100755
--- a/ag
+++ b/ag
@@ -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|
diff --git a/lib/storage.rb b/lib/storage.rb
index 8ab2d4e..68de268 100644
--- a/lib/storage.rb
+++ b/lib/storage.rb
@@ -141,6 +141,10 @@ module Ag::Storage
resolve_by_field(list, :raw_filename, filename)
end
+ def resolve_hash(list, hash = nil)
+ resolve_by_field(list, :_id, hash)
+ end
+
def store(list, message, filename)
content = get_content(message, filename)
diff --git a/lib/utils.rb b/lib/utils.rb
index 38349e0..b9156cd 100644
--- a/lib/utils.rb
+++ b/lib/utils.rb
@@ -33,6 +33,12 @@ module Ag
id = Ag::Storage.resolve_message_id($options.name, $options.dir)
when :file
id = Ag::Storage.resolve_filename($options.name, $options.dir)
+ when :hash
+ id = Ag::Storage.resolve_hash($options.name, $options.dir)
+ when :dir
+ abort 'Cannot perform resolve a directory to a message id'
+ when nil
+ abort 'Cannot resolve a nil id'
end
id