From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id BA3EA138A87 for ; Wed, 25 Feb 2015 23:48:04 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 61C63E086C; Wed, 25 Feb 2015 23:48:03 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 068C9E086C for ; Wed, 25 Feb 2015 23:48:02 +0000 (UTC) Received: from oystercatcher.gentoo.org (oystercatcher.gentoo.org [148.251.78.52]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id D74AF340B0A for ; Wed, 25 Feb 2015 23:48:01 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id 79F5B128D2 for ; Wed, 25 Feb 2015 23:48:00 +0000 (UTC) From: "Robin H. Johnson" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Robin H. Johnson" Message-ID: <1424908074.d706b559da30d046df7200c17293ece6d4af6ea2.robbat2@gentoo> Subject: [gentoo-commits] proj/ag:master commit in: / X-VCS-Repository: proj/ag X-VCS-Files: ag X-VCS-Directories: / X-VCS-Committer: robbat2 X-VCS-Committer-Name: Robin H. Johnson X-VCS-Revision: d706b559da30d046df7200c17293ece6d4af6ea2 X-VCS-Branch: master Date: Wed, 25 Feb 2015 23:48:00 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: bbcaca27-ae0a-410f-9176-1bedd637c202 X-Archives-Hash: 72dbc6c06630fd409091766775f06e48 commit: d706b559da30d046df7200c17293ece6d4af6ea2 Author: Robin H. Johnson gentoo org> AuthorDate: Wed Feb 25 23:47:54 2015 +0000 Commit: Robin H. Johnson gentoo org> CommitDate: Wed Feb 25 23:47:54 2015 +0000 URL: http://sources.gentoo.org/gitweb/?p=proj/ag.git;a=commit;h=d706b559 Refactor to simplify for a quick bug I hit. Signed-off-by: Robin H. Johnson gentoo.org> --- ag | 23 +++++++++++++---------- 1 file 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