1 |
commit: d706b559da30d046df7200c17293ece6d4af6ea2 |
2 |
Author: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org> |
3 |
AuthorDate: Wed Feb 25 23:47:54 2015 +0000 |
4 |
Commit: Robin H. Johnson <robbat2 <AT> gentoo <DOT> org> |
5 |
CommitDate: Wed Feb 25 23:47:54 2015 +0000 |
6 |
URL: http://sources.gentoo.org/gitweb/?p=proj/ag.git;a=commit;h=d706b559 |
7 |
|
8 |
Refactor to simplify for a quick bug I hit. |
9 |
|
10 |
Signed-off-by: Robin H. Johnson <robbat2 <AT> gentoo.org> |
11 |
|
12 |
--- |
13 |
ag | 23 +++++++++++++---------- |
14 |
1 file changed, 13 insertions(+), 10 deletions(-) |
15 |
|
16 |
diff --git a/ag b/ag |
17 |
index b3fdb18..f3c106e 100755 |
18 |
--- a/ag |
19 |
+++ b/ag |
20 |
@@ -154,12 +154,8 @@ Ag::Utils.proc_count = $options.jobs |
21 |
|
22 |
def do_full |
23 |
abort "Wrong argument type: #{$options.argmode.to_s}" unless $options.argmode == :dir |
24 |
- begin |
25 |
- Ag::Storage.delete_index($options.name) unless $options.readonly |
26 |
- rescue Elasticsearch::Transport::Transport::Errors::NotFound => e |
27 |
- $stderr.puts "Index did not exist yet. Creating." if $options.debug |
28 |
- end |
29 |
- Ag::Storage.create_index($options.name) |
30 |
+ do_delete_index(ignore_missing: true) unless $options.readonly |
31 |
+ do_create_index(ignore_exists: true) |
32 |
|
33 |
messages = $maildir.list(:cur) |
34 |
|
35 |
@@ -184,6 +180,7 @@ end |
36 |
def do_incremental |
37 |
abort "Wrong argument type: #{$options.argmode.to_s}" unless $options.argmode == :dir |
38 |
messages = $maildir.list(:new) |
39 |
+ do_create_index(ignore_exists: true) |
40 |
|
41 |
opts = { |
42 |
:in_processes => Ag::Utils.proc_count, |
43 |
@@ -218,18 +215,24 @@ def do_delete_msg |
44 |
end |
45 |
end |
46 |
|
47 |
-def do_delete_index |
48 |
+def do_delete_index(ignore_missing: false) |
49 |
begin |
50 |
Ag::Storage.delete_index($options.name) |
51 |
rescue Elasticsearch::Transport::Transport::Errors::NotFound => e |
52 |
- $stderr.puts "Index does not exist: #{e}" |
53 |
+ $stderr.puts "Index does not exist: #{e}" unless ignore_missing |
54 |
rescue => e |
55 |
$stderr.puts "Cannot delete index: #{e}" |
56 |
end |
57 |
end |
58 |
|
59 |
-def do_create_index |
60 |
- Ag::Storage.create_index($options.name) |
61 |
+def do_create_index(ignore_exists: false) |
62 |
+ begin |
63 |
+ Ag::Storage.create_index($options.name) |
64 |
+ rescue Elasticsearch::Transport::Transport::Errors::BadRequest => e |
65 |
+ if ignore_exists and e !~ /IndexAlreadyExistsException/ |
66 |
+ raise e |
67 |
+ end |
68 |
+ end |
69 |
end |
70 |
|
71 |
def do_reindex |