diff options
Diffstat (limited to 'ag')
-rwxr-xr-x | ag | 23 |
1 files changed, 13 insertions, 10 deletions
@@ -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 |