aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin H. Johnson <robbat2@gentoo.org>2015-02-25 15:47:54 -0800
committerRobin H. Johnson <robbat2@gentoo.org>2015-02-25 15:47:54 -0800
commitd706b559da30d046df7200c17293ece6d4af6ea2 (patch)
tree71c0b375c07d58937a9f097b9d9567e1dcc50e48
parentFix function name. (diff)
downloadbackend-d706b559da30d046df7200c17293ece6d4af6ea2.tar.gz
backend-d706b559da30d046df7200c17293ece6d4af6ea2.tar.bz2
backend-d706b559da30d046df7200c17293ece6d4af6ea2.zip
Refactor to simplify for a quick bug I hit.
Signed-off-by: Robin H. Johnson <robbat2@gentoo.org>
-rwxr-xr-xag23
1 files changed, 13 insertions, 10 deletions
diff --git a/ag b/ag
index b3fdb18..f3c106e 100755
--- a/ag
+++ b/ag
@@ -154,12 +154,8 @@ Ag::Utils.proc_count = $options.jobs
def do_full
abort "Wrong argument type: #{$options.argmode.to_s}" unless $options.argmode == :dir
- begin
- Ag::Storage.delete_index($options.name) unless $options.readonly
- rescue Elasticsearch::Transport::Transport::Errors::NotFound => e
- $stderr.puts "Index did not exist yet. Creating." if $options.debug
- end
- Ag::Storage.create_index($options.name)
+ do_delete_index(ignore_missing: true) unless $options.readonly
+ do_create_index(ignore_exists: true)
messages = $maildir.list(:cur)
@@ -184,6 +180,7 @@ end
def do_incremental
abort "Wrong argument type: #{$options.argmode.to_s}" unless $options.argmode == :dir
messages = $maildir.list(:new)
+ do_create_index(ignore_exists: true)
opts = {
:in_processes => Ag::Utils.proc_count,
@@ -218,18 +215,24 @@ def do_delete_msg
end
end
-def do_delete_index
+def do_delete_index(ignore_missing: false)
begin
Ag::Storage.delete_index($options.name)
rescue Elasticsearch::Transport::Transport::Errors::NotFound => e
- $stderr.puts "Index does not exist: #{e}"
+ $stderr.puts "Index does not exist: #{e}" unless ignore_missing
rescue => e
$stderr.puts "Cannot delete index: #{e}"
end
end
-def do_create_index
- Ag::Storage.create_index($options.name)
+def do_create_index(ignore_exists: false)
+ begin
+ Ag::Storage.create_index($options.name)
+ rescue Elasticsearch::Transport::Transport::Errors::BadRequest => e
+ if ignore_exists and e !~ /IndexAlreadyExistsException/
+ raise e
+ end
+ end
end
def do_reindex