Mercurial > dovecot > core-2.2
annotate src/doveadm/dsync/dsync-brain.c @ 14253:91e035840dc6
Increased initial memory pool sizes and marked some of them as "growing".
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Fri, 02 Mar 2012 14:33:41 +0200 |
parents | ba770cba5598 |
children | b2076acc3715 5f280c1ec9fd |
rev | line source |
---|---|
14133
ba770cba5598
Updated copyright notices to include year 2012.
Timo Sirainen <tss@iki.fi>
parents:
14021
diff
changeset
|
1 /* Copyright (c) 2009-2012 Dovecot authors, see the included COPYING file */ |
9559 | 2 |
3 #include "lib.h" | |
4 #include "array.h" | |
5 #include "hash.h" | |
6 #include "dsync-worker.h" | |
7 #include "dsync-brain-private.h" | |
8 | |
11687
b37c85676f8e
dsync: When -v parameter is given, show progress counter of saving new messages.
Timo Sirainen <tss@iki.fi>
parents:
11684
diff
changeset
|
9 #include <unistd.h> |
b37c85676f8e
dsync: When -v parameter is given, show progress counter of saving new messages.
Timo Sirainen <tss@iki.fi>
parents:
11684
diff
changeset
|
10 |
11727
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
11 #define DSYNC_WRONG_DIRECTION_ERROR_MSG \ |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
12 "dsync backup: " \ |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
13 "Looks like you're trying to run backup in wrong direction. " \ |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
14 "Source is empty and destination is not." |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
15 |
9559 | 16 static void |
17 dsync_brain_mailbox_list_deinit(struct dsync_brain_mailbox_list **list); | |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
18 static void |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
19 dsync_brain_subs_list_deinit(struct dsync_brain_subs_list **list); |
9559 | 20 |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
21 struct dsync_brain * |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
22 dsync_brain_init(struct dsync_worker *src_worker, |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
23 struct dsync_worker *dest_worker, |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
24 const char *mailbox, enum dsync_brain_flags flags) |
9559 | 25 { |
26 struct dsync_brain *brain; | |
27 | |
28 brain = i_new(struct dsync_brain, 1); | |
29 brain->src_worker = src_worker; | |
30 brain->dest_worker = dest_worker; | |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
31 brain->mailbox = i_strdup(mailbox); |
9686
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
32 brain->flags = flags; |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
33 brain->verbose = (flags & DSYNC_BRAIN_FLAG_VERBOSE) != 0; |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
34 brain->backup = (flags & DSYNC_BRAIN_FLAG_BACKUP) != 0; |
11687
b37c85676f8e
dsync: When -v parameter is given, show progress counter of saving new messages.
Timo Sirainen <tss@iki.fi>
parents:
11684
diff
changeset
|
35 brain->stdout_tty = isatty(STDOUT_FILENO) > 0; |
11734
ba9f33f9c6c3
dsync: If verbosity is enabled, log why desyncing was caused.
Timo Sirainen <tss@iki.fi>
parents:
11727
diff
changeset
|
36 |
ba9f33f9c6c3
dsync: If verbosity is enabled, log why desyncing was caused.
Timo Sirainen <tss@iki.fi>
parents:
11727
diff
changeset
|
37 if ((flags & DSYNC_BRAIN_FLAG_VERBOSE) != 0) { |
ba9f33f9c6c3
dsync: If verbosity is enabled, log why desyncing was caused.
Timo Sirainen <tss@iki.fi>
parents:
11727
diff
changeset
|
38 dsync_worker_set_verbose(src_worker); |
ba9f33f9c6c3
dsync: If verbosity is enabled, log why desyncing was caused.
Timo Sirainen <tss@iki.fi>
parents:
11727
diff
changeset
|
39 dsync_worker_set_verbose(dest_worker); |
ba9f33f9c6c3
dsync: If verbosity is enabled, log why desyncing was caused.
Timo Sirainen <tss@iki.fi>
parents:
11727
diff
changeset
|
40 } |
9559 | 41 return brain; |
42 } | |
43 | |
9686
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
44 void dsync_brain_fail(struct dsync_brain *brain) |
9559 | 45 { |
46 brain->failed = TRUE; | |
13875
4c827134997f
Merged dsync into "doveadm dsync".
Timo Sirainen <tss@iki.fi>
parents:
12851
diff
changeset
|
47 io_loop_stop(current_ioloop); |
9559 | 48 } |
49 | |
50 int dsync_brain_deinit(struct dsync_brain **_brain) | |
51 { | |
52 struct dsync_brain *brain = *_brain; | |
53 int ret = brain->failed ? -1 : 0; | |
54 | |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
55 if (brain->state != DSYNC_STATE_SYNC_END) |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
56 ret = -1; |
11775 | 57 if (brain->to != NULL) |
58 timeout_remove(&brain->to); | |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
59 |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
60 if (ret < 0) { |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
61 /* make sure we unreference save input streams before workers |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
62 are deinitialized, so they can destroy the streams */ |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
63 dsync_worker_msg_save_cancel(brain->src_worker); |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
64 dsync_worker_msg_save_cancel(brain->dest_worker); |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
65 } |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
66 |
9559 | 67 if (brain->mailbox_sync != NULL) |
68 dsync_brain_msg_sync_deinit(&brain->mailbox_sync); | |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
69 |
9559 | 70 if (brain->src_mailbox_list != NULL) |
71 dsync_brain_mailbox_list_deinit(&brain->src_mailbox_list); | |
72 if (brain->dest_mailbox_list != NULL) | |
73 dsync_brain_mailbox_list_deinit(&brain->dest_mailbox_list); | |
74 | |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
75 if (brain->src_subs_list != NULL) |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
76 dsync_brain_subs_list_deinit(&brain->src_subs_list); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
77 if (brain->dest_subs_list != NULL) |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
78 dsync_brain_subs_list_deinit(&brain->dest_subs_list); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
79 |
11680
49b226835cd2
dsync: Another try at not increasing mailbox uidnext/highestmodseq on failure
Timo Sirainen <tss@iki.fi>
parents:
11677
diff
changeset
|
80 if (dsync_worker_has_failed(brain->src_worker) || |
49b226835cd2
dsync: Another try at not increasing mailbox uidnext/highestmodseq on failure
Timo Sirainen <tss@iki.fi>
parents:
11677
diff
changeset
|
81 dsync_worker_has_failed(brain->dest_worker)) |
49b226835cd2
dsync: Another try at not increasing mailbox uidnext/highestmodseq on failure
Timo Sirainen <tss@iki.fi>
parents:
11677
diff
changeset
|
82 ret = -1; |
49b226835cd2
dsync: Another try at not increasing mailbox uidnext/highestmodseq on failure
Timo Sirainen <tss@iki.fi>
parents:
11677
diff
changeset
|
83 |
9559 | 84 *_brain = NULL; |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
85 i_free(brain->mailbox); |
9559 | 86 i_free(brain); |
87 return ret; | |
88 } | |
89 | |
90 static void dsync_brain_mailbox_list_finished(struct dsync_brain *brain) | |
91 { | |
92 if (brain->src_mailbox_list->iter != NULL || | |
93 brain->dest_mailbox_list->iter != NULL) | |
94 return; | |
95 | |
96 /* both lists are finished */ | |
97 brain->state++; | |
98 dsync_brain_sync(brain); | |
99 } | |
100 | |
101 static void dsync_worker_mailbox_input(void *context) | |
102 { | |
103 struct dsync_brain_mailbox_list *list = context; | |
104 struct dsync_mailbox dsync_box, *dup_box; | |
105 int ret; | |
106 | |
107 while ((ret = dsync_worker_mailbox_iter_next(list->iter, | |
108 &dsync_box)) > 0) { | |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
109 if (list->brain->mailbox != NULL && |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
110 strcmp(list->brain->mailbox, dsync_box.name) != 0) |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
111 continue; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
112 |
9559 | 113 dup_box = dsync_mailbox_dup(list->pool, &dsync_box); |
10545
96db209efe22
dsync: Initial code to sync mailbox list without dir GUID support.
Timo Sirainen <tss@iki.fi>
parents:
10519
diff
changeset
|
114 if (!dsync_mailbox_is_noselect(dup_box)) |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
115 array_append(&list->mailboxes, &dup_box, 1); |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
116 else |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
117 array_append(&list->dirs, &dup_box, 1); |
9559 | 118 } |
119 if (ret < 0) { | |
120 /* finished listing mailboxes */ | |
121 if (dsync_worker_mailbox_iter_deinit(&list->iter) < 0) | |
122 dsync_brain_fail(list->brain); | |
123 array_sort(&list->mailboxes, dsync_mailbox_p_guid_cmp); | |
11524
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
124 array_sort(&list->dirs, dsync_mailbox_p_name_sha1_cmp); |
9559 | 125 dsync_brain_mailbox_list_finished(list->brain); |
126 } | |
127 } | |
128 | |
129 static struct dsync_brain_mailbox_list * | |
130 dsync_brain_mailbox_list_init(struct dsync_brain *brain, | |
131 struct dsync_worker *worker) | |
132 { | |
133 struct dsync_brain_mailbox_list *list; | |
134 pool_t pool; | |
135 | |
136 pool = pool_alloconly_create("dsync brain mailbox list", 10240); | |
137 list = p_new(pool, struct dsync_brain_mailbox_list, 1); | |
138 list->pool = pool; | |
139 list->brain = brain; | |
140 list->worker = worker; | |
141 list->iter = dsync_worker_mailbox_iter_init(worker); | |
142 p_array_init(&list->mailboxes, pool, 128); | |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
143 p_array_init(&list->dirs, pool, 32); |
9559 | 144 dsync_worker_set_input_callback(worker, dsync_worker_mailbox_input, |
145 list); | |
146 return list; | |
147 } | |
148 | |
149 static void | |
150 dsync_brain_mailbox_list_deinit(struct dsync_brain_mailbox_list **_list) | |
151 { | |
152 struct dsync_brain_mailbox_list *list = *_list; | |
153 | |
154 *_list = NULL; | |
155 | |
156 if (list->iter != NULL) | |
157 (void)dsync_worker_mailbox_iter_deinit(&list->iter); | |
158 pool_unref(&list->pool); | |
159 } | |
160 | |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
161 static void dsync_brain_subs_list_finished(struct dsync_brain *brain) |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
162 { |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
163 if (brain->src_subs_list->iter != NULL || |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
164 brain->dest_subs_list->iter != NULL) |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
165 return; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
166 |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
167 /* both lists are finished */ |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
168 brain->state++; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
169 dsync_brain_sync(brain); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
170 } |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
171 |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
172 static int |
10331
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
173 dsync_worker_subscription_cmp(const struct dsync_worker_subscription *s1, |
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
174 const struct dsync_worker_subscription *s2) |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
175 { |
10331
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
176 return strcmp(s1->vname, s2->vname); |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
177 } |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
178 |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
179 static int |
10331
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
180 dsync_worker_unsubscription_cmp(const struct dsync_worker_unsubscription *u1, |
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
181 const struct dsync_worker_unsubscription *u2) |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
182 { |
10331
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
183 int ret; |
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
184 |
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
185 ret = strcmp(u1->ns_prefix, u2->ns_prefix); |
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
186 return ret != 0 ? ret : |
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
187 dsync_guid_cmp(&u1->name_sha1, &u2->name_sha1); |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
188 } |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
189 |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
190 static void dsync_worker_subs_input(void *context) |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
191 { |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
192 struct dsync_brain_subs_list *list = context; |
10331
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
193 struct dsync_worker_subscription subs; |
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
194 struct dsync_worker_unsubscription unsubs; |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
195 int ret; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
196 |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
197 memset(&subs, 0, sizeof(subs)); |
10331
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
198 while ((ret = dsync_worker_subs_iter_next(list->iter, &subs)) > 0) { |
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
199 subs.vname = p_strdup(list->pool, subs.vname); |
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
200 subs.storage_name = p_strdup(list->pool, subs.storage_name); |
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
201 subs.ns_prefix = p_strdup(list->pool, subs.ns_prefix); |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
202 array_append(&list->subscriptions, &subs, 1); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
203 } |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
204 if (ret == 0) |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
205 return; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
206 |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
207 memset(&unsubs, 0, sizeof(unsubs)); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
208 while ((ret = dsync_worker_subs_iter_next_un(list->iter, |
10331
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
209 &unsubs)) > 0) { |
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
210 unsubs.ns_prefix = p_strdup(list->pool, unsubs.ns_prefix); |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
211 array_append(&list->unsubscriptions, &unsubs, 1); |
10331
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
212 } |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
213 |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
214 if (ret < 0) { |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
215 /* finished listing subscriptions */ |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
216 if (dsync_worker_subs_iter_deinit(&list->iter) < 0) |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
217 dsync_brain_fail(list->brain); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
218 array_sort(&list->subscriptions, |
10331
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
219 dsync_worker_subscription_cmp); |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
220 array_sort(&list->unsubscriptions, |
10331
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
221 dsync_worker_unsubscription_cmp); |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
222 dsync_brain_subs_list_finished(list->brain); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
223 } |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
224 } |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
225 |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
226 static struct dsync_brain_subs_list * |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
227 dsync_brain_subs_list_init(struct dsync_brain *brain, |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
228 struct dsync_worker *worker) |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
229 { |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
230 struct dsync_brain_subs_list *list; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
231 pool_t pool; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
232 |
14253
91e035840dc6
Increased initial memory pool sizes and marked some of them as "growing".
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
233 pool = pool_alloconly_create(MEMPOOL_GROWING"dsync brain subs list", |
91e035840dc6
Increased initial memory pool sizes and marked some of them as "growing".
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
234 1024*4); |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
235 list = p_new(pool, struct dsync_brain_subs_list, 1); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
236 list->pool = pool; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
237 list->brain = brain; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
238 list->worker = worker; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
239 list->iter = dsync_worker_subs_iter_init(worker); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
240 p_array_init(&list->subscriptions, pool, 128); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
241 p_array_init(&list->unsubscriptions, pool, 64); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
242 dsync_worker_set_input_callback(worker, dsync_worker_subs_input, list); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
243 return list; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
244 } |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
245 |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
246 static void |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
247 dsync_brain_subs_list_deinit(struct dsync_brain_subs_list **_list) |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
248 { |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
249 struct dsync_brain_subs_list *list = *_list; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
250 |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
251 *_list = NULL; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
252 |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
253 if (list->iter != NULL) |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
254 (void)dsync_worker_subs_iter_deinit(&list->iter); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
255 pool_unref(&list->pool); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
256 } |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
257 |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
258 enum dsync_brain_mailbox_action { |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
259 DSYNC_BRAIN_MAILBOX_ACTION_NONE, |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
260 DSYNC_BRAIN_MAILBOX_ACTION_CREATE, |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
261 DSYNC_BRAIN_MAILBOX_ACTION_DELETE |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
262 }; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
263 |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
264 static void |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
265 dsync_brain_mailbox_action(struct dsync_brain *brain, |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
266 enum dsync_brain_mailbox_action action, |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
267 struct dsync_worker *action_worker, |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
268 struct dsync_mailbox *action_box) |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
269 { |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
270 struct dsync_mailbox new_box; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
271 |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
272 if (brain->backup && action_worker == brain->src_worker) { |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
273 /* backup mode: switch actions */ |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
274 action_worker = brain->dest_worker; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
275 switch (action) { |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
276 case DSYNC_BRAIN_MAILBOX_ACTION_NONE: |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
277 break; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
278 case DSYNC_BRAIN_MAILBOX_ACTION_CREATE: |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
279 action = DSYNC_BRAIN_MAILBOX_ACTION_DELETE; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
280 break; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
281 case DSYNC_BRAIN_MAILBOX_ACTION_DELETE: |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
282 action = DSYNC_BRAIN_MAILBOX_ACTION_CREATE; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
283 break; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
284 } |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
285 } |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
286 |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
287 switch (action) { |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
288 case DSYNC_BRAIN_MAILBOX_ACTION_NONE: |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
289 break; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
290 case DSYNC_BRAIN_MAILBOX_ACTION_CREATE: |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
291 new_box = *action_box; |
11763
0ece958ef45b
dsync: Fixed creating mailboxes with remote dsync.
Timo Sirainen <tss@iki.fi>
parents:
11734
diff
changeset
|
292 new_box.uid_next = action_box->uid_validity == 0 ? 0 : 1; |
12851
ad393de782ce
dsync: Preserve \Recent flags state (instead of setting everything \Recent).
Timo Sirainen <tss@iki.fi>
parents:
12846
diff
changeset
|
293 new_box.first_recent_uid = 0; |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
294 new_box.highest_modseq = 0; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
295 dsync_worker_create_mailbox(action_worker, &new_box); |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
296 break; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
297 case DSYNC_BRAIN_MAILBOX_ACTION_DELETE: |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
298 if (!dsync_mailbox_is_noselect(action_box)) |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
299 dsync_worker_delete_mailbox(action_worker, action_box); |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
300 else |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
301 dsync_worker_delete_dir(action_worker, action_box); |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
302 break; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
303 } |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
304 } |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
305 |
11727
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
306 static bool |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
307 dsync_mailbox_list_is_empty(const ARRAY_TYPE(dsync_mailbox) *boxes_arr) |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
308 { |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
309 struct dsync_mailbox *const *boxes; |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
310 unsigned int count; |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
311 |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
312 boxes = array_get(boxes_arr, &count); |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
313 if (count == 0) |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
314 return TRUE; |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
315 if (count == 1 && strcasecmp(boxes[0]->name, "INBOX") == 0 && |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
316 boxes[0]->message_count == 0) |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
317 return TRUE; |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
318 return FALSE; |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
319 } |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
320 |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
321 static void dsync_brain_sync_mailboxes(struct dsync_brain *brain) |
9559 | 322 { |
11684
9798d57644ba
dsync: Potential crashfix, plus some compiler warning fixes.
Timo Sirainen <tss@iki.fi>
parents:
11681
diff
changeset
|
323 struct dsync_mailbox *const *src_boxes, *const *dest_boxes; |
9798d57644ba
dsync: Potential crashfix, plus some compiler warning fixes.
Timo Sirainen <tss@iki.fi>
parents:
11681
diff
changeset
|
324 struct dsync_mailbox *action_box = NULL; |
9798d57644ba
dsync: Potential crashfix, plus some compiler warning fixes.
Timo Sirainen <tss@iki.fi>
parents:
11681
diff
changeset
|
325 struct dsync_worker *action_worker = NULL; |
9559 | 326 unsigned int src, dest, src_count, dest_count; |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
327 enum dsync_brain_mailbox_action action; |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
328 bool src_deleted, dest_deleted; |
9559 | 329 int ret; |
330 | |
11727
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
331 if (brain->backup && |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
332 dsync_mailbox_list_is_empty(&brain->src_mailbox_list->mailboxes) && |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
333 !dsync_mailbox_list_is_empty(&brain->dest_mailbox_list->mailboxes)) { |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
334 i_fatal(DSYNC_WRONG_DIRECTION_ERROR_MSG); |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
335 } |
42dfcf9c896b
dsync backup: Fail if it looks like backup is running in wrong direction.
Timo Sirainen <tss@iki.fi>
parents:
11688
diff
changeset
|
336 |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
337 /* create/delete missing mailboxes. the mailboxes are sorted by |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
338 GUID, so we can do this quickly. */ |
9559 | 339 src_boxes = array_get(&brain->src_mailbox_list->mailboxes, &src_count); |
340 dest_boxes = array_get(&brain->dest_mailbox_list->mailboxes, &dest_count); | |
341 for (src = dest = 0; src < src_count && dest < dest_count; ) { | |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
342 action = DSYNC_BRAIN_MAILBOX_ACTION_NONE; |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
343 src_deleted = (src_boxes[src]->flags & |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
344 DSYNC_MAILBOX_FLAG_DELETED_MAILBOX) != 0; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
345 dest_deleted = (dest_boxes[dest]->flags & |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
346 DSYNC_MAILBOX_FLAG_DELETED_MAILBOX) != 0; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
347 ret = dsync_mailbox_guid_cmp(src_boxes[src], |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
348 dest_boxes[dest]); |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
349 if (ret < 0) { |
9559 | 350 /* exists only in source */ |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
351 if (!src_deleted) { |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
352 action = DSYNC_BRAIN_MAILBOX_ACTION_CREATE; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
353 action_worker = brain->dest_worker; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
354 action_box = src_boxes[src]; |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
355 } |
9559 | 356 src++; |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
357 } else if (ret > 0) { |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
358 /* exists only in dest */ |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
359 if (!dest_deleted) { |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
360 action = DSYNC_BRAIN_MAILBOX_ACTION_CREATE; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
361 action_worker = brain->src_worker; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
362 action_box = dest_boxes[dest]; |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
363 } |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
364 dest++; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
365 } else if (src_deleted) { |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
366 /* delete from dest too */ |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
367 if (!dest_deleted) { |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
368 action = DSYNC_BRAIN_MAILBOX_ACTION_DELETE; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
369 action_worker = brain->dest_worker; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
370 action_box = dest_boxes[dest]; |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
371 } |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
372 src++; dest++; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
373 } else if (dest_deleted) { |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
374 /* delete from src too */ |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
375 action = DSYNC_BRAIN_MAILBOX_ACTION_DELETE; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
376 action_worker = brain->src_worker; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
377 action_box = src_boxes[src]; |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
378 src++; dest++; |
9559 | 379 } else { |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
380 src++; dest++; |
9559 | 381 } |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
382 dsync_brain_mailbox_action(brain, action, |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
383 action_worker, action_box); |
9559 | 384 } |
385 for (; src < src_count; src++) { | |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
386 if ((src_boxes[src]->flags & |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
387 DSYNC_MAILBOX_FLAG_DELETED_MAILBOX) != 0) |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
388 continue; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
389 |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
390 dsync_brain_mailbox_action(brain, |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
391 DSYNC_BRAIN_MAILBOX_ACTION_CREATE, |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
392 brain->dest_worker, src_boxes[src]); |
9559 | 393 } |
9686
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
394 for (; dest < dest_count; dest++) { |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
395 if ((dest_boxes[dest]->flags & |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
396 DSYNC_MAILBOX_FLAG_DELETED_MAILBOX) != 0) |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
397 continue; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
398 |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
399 dsync_brain_mailbox_action(brain, |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
400 DSYNC_BRAIN_MAILBOX_ACTION_CREATE, |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
401 brain->src_worker, dest_boxes[dest]); |
9638
b11a3eda2477
dsync: Use expunged messages' GUIDs to determine what to do with missing messages at end of mailbox.
Timo Sirainen <tss@iki.fi>
parents:
9592
diff
changeset
|
402 } |
9559 | 403 } |
404 | |
11524
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
405 static void dsync_brain_sync_dirs(struct dsync_brain *brain) |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
406 { |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
407 struct dsync_mailbox *const *src_boxes, *const *dest_boxes, *action_box; |
11524
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
408 unsigned int src, dest, src_count, dest_count; |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
409 enum dsync_brain_mailbox_action action; |
11684
9798d57644ba
dsync: Potential crashfix, plus some compiler warning fixes.
Timo Sirainen <tss@iki.fi>
parents:
11681
diff
changeset
|
410 struct dsync_worker *action_worker = NULL; |
11524
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
411 bool src_deleted, dest_deleted; |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
412 int ret; |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
413 |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
414 /* create/delete missing directories. */ |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
415 src_boxes = array_get(&brain->src_mailbox_list->dirs, &src_count); |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
416 dest_boxes = array_get(&brain->dest_mailbox_list->dirs, &dest_count); |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
417 for (src = dest = 0; src < src_count && dest < dest_count; ) { |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
418 action = DSYNC_BRAIN_MAILBOX_ACTION_NONE; |
11684
9798d57644ba
dsync: Potential crashfix, plus some compiler warning fixes.
Timo Sirainen <tss@iki.fi>
parents:
11681
diff
changeset
|
419 action_box = NULL; |
9798d57644ba
dsync: Potential crashfix, plus some compiler warning fixes.
Timo Sirainen <tss@iki.fi>
parents:
11681
diff
changeset
|
420 |
11524
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
421 src_deleted = (src_boxes[src]->flags & |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
422 DSYNC_MAILBOX_FLAG_DELETED_DIR) != 0; |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
423 dest_deleted = (dest_boxes[dest]->flags & |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
424 DSYNC_MAILBOX_FLAG_DELETED_DIR) != 0; |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
425 ret = memcmp(src_boxes[src]->name_sha1.guid, |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
426 dest_boxes[dest]->name_sha1.guid, |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
427 sizeof(src_boxes[src]->name_sha1.guid)); |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
428 if (ret < 0) { |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
429 /* exists only in source */ |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
430 if (!src_deleted) { |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
431 action = DSYNC_BRAIN_MAILBOX_ACTION_CREATE; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
432 action_worker = brain->dest_worker; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
433 action_box = src_boxes[src]; |
11524
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
434 } |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
435 src++; |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
436 } else if (ret > 0) { |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
437 /* exists only in dest */ |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
438 if (!dest_deleted) { |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
439 action = DSYNC_BRAIN_MAILBOX_ACTION_CREATE; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
440 action_worker = brain->src_worker; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
441 action_box = dest_boxes[dest]; |
11524
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
442 } |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
443 dest++; |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
444 } else if (src_deleted) { |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
445 /* delete from dest too */ |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
446 if (!dest_deleted) { |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
447 action = DSYNC_BRAIN_MAILBOX_ACTION_DELETE; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
448 action_worker = brain->dest_worker; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
449 action_box = dest_boxes[dest]; |
11524
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
450 } |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
451 src++; dest++; |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
452 } else if (dest_deleted) { |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
453 /* delete from src too */ |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
454 action = DSYNC_BRAIN_MAILBOX_ACTION_DELETE; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
455 action_worker = brain->src_worker; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
456 action_box = src_boxes[src]; |
11524
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
457 src++; dest++; |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
458 } else { |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
459 src++; dest++; |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
460 } |
11684
9798d57644ba
dsync: Potential crashfix, plus some compiler warning fixes.
Timo Sirainen <tss@iki.fi>
parents:
11681
diff
changeset
|
461 i_assert(action_box == NULL || |
9798d57644ba
dsync: Potential crashfix, plus some compiler warning fixes.
Timo Sirainen <tss@iki.fi>
parents:
11681
diff
changeset
|
462 dsync_mailbox_is_noselect(action_box)); |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
463 dsync_brain_mailbox_action(brain, action, |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
464 action_worker, action_box); |
11524
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
465 } |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
466 for (; src < src_count; src++) { |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
467 if ((src_boxes[src]->flags & |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
468 DSYNC_MAILBOX_FLAG_DELETED_DIR) != 0) |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
469 continue; |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
470 |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
471 dsync_brain_mailbox_action(brain, |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
472 DSYNC_BRAIN_MAILBOX_ACTION_CREATE, |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
473 brain->dest_worker, src_boxes[src]); |
11524
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
474 } |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
475 for (; dest < dest_count; dest++) { |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
476 if ((dest_boxes[dest]->flags & |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
477 DSYNC_MAILBOX_FLAG_DELETED_DIR) != 0) |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
478 continue; |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
479 |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
480 dsync_brain_mailbox_action(brain, |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
481 DSYNC_BRAIN_MAILBOX_ACTION_CREATE, |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
482 brain->src_worker, dest_boxes[dest]); |
11524
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
483 } |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
484 } |
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
485 |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
486 static bool |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
487 dsync_brain_is_unsubscribed(struct dsync_brain_subs_list *list, |
10519
eba3e50fef36
dsync: Write mailbox changelog records using original timestamps.
Timo Sirainen <tss@iki.fi>
parents:
10373
diff
changeset
|
488 const struct dsync_worker_subscription *subs, |
eba3e50fef36
dsync: Write mailbox changelog records using original timestamps.
Timo Sirainen <tss@iki.fi>
parents:
10373
diff
changeset
|
489 time_t *last_change_r) |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
490 { |
10331
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
491 const struct dsync_worker_unsubscription *unsubs; |
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
492 struct dsync_worker_unsubscription lookup; |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
493 |
10331
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
494 lookup.ns_prefix = subs->ns_prefix; |
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
495 dsync_str_sha_to_guid(subs->storage_name, &lookup.name_sha1); |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
496 unsubs = array_bsearch(&list->unsubscriptions, &lookup, |
10331
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
497 dsync_worker_unsubscription_cmp); |
10519
eba3e50fef36
dsync: Write mailbox changelog records using original timestamps.
Timo Sirainen <tss@iki.fi>
parents:
10373
diff
changeset
|
498 if (unsubs == NULL) { |
eba3e50fef36
dsync: Write mailbox changelog records using original timestamps.
Timo Sirainen <tss@iki.fi>
parents:
10373
diff
changeset
|
499 *last_change_r = 0; |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
500 return FALSE; |
10519
eba3e50fef36
dsync: Write mailbox changelog records using original timestamps.
Timo Sirainen <tss@iki.fi>
parents:
10373
diff
changeset
|
501 } else if (unsubs->last_change <= subs->last_change) { |
eba3e50fef36
dsync: Write mailbox changelog records using original timestamps.
Timo Sirainen <tss@iki.fi>
parents:
10373
diff
changeset
|
502 *last_change_r = subs->last_change; |
eba3e50fef36
dsync: Write mailbox changelog records using original timestamps.
Timo Sirainen <tss@iki.fi>
parents:
10373
diff
changeset
|
503 return FALSE; |
eba3e50fef36
dsync: Write mailbox changelog records using original timestamps.
Timo Sirainen <tss@iki.fi>
parents:
10373
diff
changeset
|
504 } else { |
eba3e50fef36
dsync: Write mailbox changelog records using original timestamps.
Timo Sirainen <tss@iki.fi>
parents:
10373
diff
changeset
|
505 *last_change_r = unsubs->last_change; |
eba3e50fef36
dsync: Write mailbox changelog records using original timestamps.
Timo Sirainen <tss@iki.fi>
parents:
10373
diff
changeset
|
506 return TRUE; |
eba3e50fef36
dsync: Write mailbox changelog records using original timestamps.
Timo Sirainen <tss@iki.fi>
parents:
10373
diff
changeset
|
507 } |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
508 } |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
509 |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
510 static void dsync_brain_sync_subscriptions(struct dsync_brain *brain) |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
511 { |
10331
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
512 const struct dsync_worker_subscription *src_subs, *dest_subs; |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
513 const struct dsync_worker_subscription *action_subs; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
514 struct dsync_worker *action_worker; |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
515 unsigned int src, dest, src_count, dest_count; |
10519
eba3e50fef36
dsync: Write mailbox changelog records using original timestamps.
Timo Sirainen <tss@iki.fi>
parents:
10373
diff
changeset
|
516 time_t last_change; |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
517 bool subscribe; |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
518 int ret; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
519 |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
520 /* subscriptions are sorted by name. */ |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
521 src_subs = array_get(&brain->src_subs_list->subscriptions, &src_count); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
522 dest_subs = array_get(&brain->dest_subs_list->subscriptions, &dest_count); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
523 for (src = dest = 0;; ) { |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
524 if (src == src_count) { |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
525 if (dest == dest_count) |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
526 break; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
527 ret = 1; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
528 } else if (dest == dest_count) { |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
529 ret = -1; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
530 } else { |
10331
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
531 ret = strcmp(src_subs[src].vname, |
b5b253d35612
dsync: Fixed subscription syncing to work with namespace prefixes.
Timo Sirainen <tss@iki.fi>
parents:
10328
diff
changeset
|
532 dest_subs[dest].vname); |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
533 if (ret == 0) { |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
534 src++; dest++; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
535 continue; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
536 } |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
537 } |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
538 |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
539 if (ret < 0) { |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
540 /* subscribed only in source */ |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
541 action_subs = &src_subs[src]; |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
542 if (dsync_brain_is_unsubscribed(brain->dest_subs_list, |
10519
eba3e50fef36
dsync: Write mailbox changelog records using original timestamps.
Timo Sirainen <tss@iki.fi>
parents:
10373
diff
changeset
|
543 &src_subs[src], |
eba3e50fef36
dsync: Write mailbox changelog records using original timestamps.
Timo Sirainen <tss@iki.fi>
parents:
10373
diff
changeset
|
544 &last_change)) { |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
545 action_worker = brain->src_worker; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
546 subscribe = FALSE; |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
547 } else { |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
548 action_worker = brain->dest_worker; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
549 subscribe = TRUE; |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
550 } |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
551 src++; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
552 } else { |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
553 /* subscribed only in dest */ |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
554 action_subs = &dest_subs[dest]; |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
555 if (dsync_brain_is_unsubscribed(brain->src_subs_list, |
10519
eba3e50fef36
dsync: Write mailbox changelog records using original timestamps.
Timo Sirainen <tss@iki.fi>
parents:
10373
diff
changeset
|
556 &dest_subs[dest], |
eba3e50fef36
dsync: Write mailbox changelog records using original timestamps.
Timo Sirainen <tss@iki.fi>
parents:
10373
diff
changeset
|
557 &last_change)) { |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
558 action_worker = brain->dest_worker; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
559 subscribe = FALSE; |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
560 } else { |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
561 action_worker = brain->src_worker; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
562 subscribe = TRUE; |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
563 } |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
564 dest++; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
565 } |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
566 |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
567 if (brain->backup && action_worker == brain->src_worker) { |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
568 /* backup mode: switch action */ |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
569 action_worker = brain->dest_worker; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
570 subscribe = !subscribe; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
571 last_change = ioloop_time; |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
572 } |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
573 dsync_worker_set_subscribed(action_worker, action_subs->vname, |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
574 last_change, subscribe); |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
575 } |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
576 } |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
577 |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
578 static bool dsync_mailbox_has_changed_msgs(struct dsync_brain *brain, |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
579 const struct dsync_mailbox *box1, |
9639
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
580 const struct dsync_mailbox *box2) |
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
581 { |
9759
ab4e247d326d
dsync: Minor verbose logging improvements.
Timo Sirainen <tss@iki.fi>
parents:
9736
diff
changeset
|
582 const char *name = *box1->name != '\0' ? box1->name : box2->name; |
ab4e247d326d
dsync: Minor verbose logging improvements.
Timo Sirainen <tss@iki.fi>
parents:
9736
diff
changeset
|
583 |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
584 if (box1->uid_validity != box2->uid_validity) { |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
585 if (brain->verbose) { |
11688
b94e6bf6b9c9
dsync: Changed verbose "xx changed" messages to be clearer what they mean.
Timo Sirainen <tss@iki.fi>
parents:
11687
diff
changeset
|
586 i_info("%s: uidvalidity changed: %u != %u", name, |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
587 box1->uid_validity, box2->uid_validity); |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
588 } |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
589 return TRUE; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
590 } |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
591 if (box1->uid_next != box2->uid_next) { |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
592 if (brain->verbose) { |
11688
b94e6bf6b9c9
dsync: Changed verbose "xx changed" messages to be clearer what they mean.
Timo Sirainen <tss@iki.fi>
parents:
11687
diff
changeset
|
593 i_info("%s: uidnext changed: %u != %u", name, |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
594 box1->uid_next, box2->uid_next); |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
595 } |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
596 return TRUE; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
597 } |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
598 if (box1->highest_modseq != box2->highest_modseq) { |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
599 if (brain->verbose) { |
11688
b94e6bf6b9c9
dsync: Changed verbose "xx changed" messages to be clearer what they mean.
Timo Sirainen <tss@iki.fi>
parents:
11687
diff
changeset
|
600 i_info("%s: highest_modseq changed: %llu != %llu", name, |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
601 (unsigned long long)box1->highest_modseq, |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
602 (unsigned long long)box2->highest_modseq); |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
603 } |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
604 return TRUE; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
605 } |
11681
28639e01a479
dsync: Find changed mailboxes also based on number of messages in them.
Timo Sirainen <tss@iki.fi>
parents:
11680
diff
changeset
|
606 if (box1->message_count != box2->message_count) { |
28639e01a479
dsync: Find changed mailboxes also based on number of messages in them.
Timo Sirainen <tss@iki.fi>
parents:
11680
diff
changeset
|
607 if (brain->verbose) { |
11688
b94e6bf6b9c9
dsync: Changed verbose "xx changed" messages to be clearer what they mean.
Timo Sirainen <tss@iki.fi>
parents:
11687
diff
changeset
|
608 i_info("%s: message_count changed: %u != %u", name, |
11681
28639e01a479
dsync: Find changed mailboxes also based on number of messages in them.
Timo Sirainen <tss@iki.fi>
parents:
11680
diff
changeset
|
609 box1->message_count, box2->message_count); |
28639e01a479
dsync: Find changed mailboxes also based on number of messages in them.
Timo Sirainen <tss@iki.fi>
parents:
11680
diff
changeset
|
610 } |
28639e01a479
dsync: Find changed mailboxes also based on number of messages in them.
Timo Sirainen <tss@iki.fi>
parents:
11680
diff
changeset
|
611 return TRUE; |
28639e01a479
dsync: Find changed mailboxes also based on number of messages in them.
Timo Sirainen <tss@iki.fi>
parents:
11680
diff
changeset
|
612 } |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
613 return FALSE; |
9639
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
614 } |
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
615 |
10371 | 616 static bool dsync_mailbox_has_changes(struct dsync_brain *brain, |
617 const struct dsync_mailbox *box1, | |
618 const struct dsync_mailbox *box2) | |
619 { | |
620 if (strcmp(box1->name, box2->name) != 0) | |
621 return TRUE; | |
622 return dsync_mailbox_has_changed_msgs(brain, box1, box2); | |
623 } | |
624 | |
9639
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
625 static void |
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
626 dsync_brain_get_changed_mailboxes(struct dsync_brain *brain, |
9686
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
627 ARRAY_TYPE(dsync_brain_mailbox) *brain_boxes, |
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
628 bool full_sync) |
9639
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
629 { |
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
630 struct dsync_mailbox *const *src_boxes, *const *dest_boxes; |
9686
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
631 struct dsync_brain_mailbox *brain_box; |
9639
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
632 unsigned int src, dest, src_count, dest_count; |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
633 bool src_deleted, dest_deleted; |
9639
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
634 int ret; |
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
635 |
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
636 src_boxes = array_get(&brain->src_mailbox_list->mailboxes, &src_count); |
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
637 dest_boxes = array_get(&brain->dest_mailbox_list->mailboxes, &dest_count); |
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
638 |
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
639 for (src = dest = 0; src < src_count && dest < dest_count; ) { |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
640 src_deleted = (src_boxes[src]->flags & |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
641 DSYNC_MAILBOX_FLAG_DELETED_MAILBOX) != 0; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
642 dest_deleted = (dest_boxes[dest]->flags & |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
643 DSYNC_MAILBOX_FLAG_DELETED_MAILBOX) != 0; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
644 |
9639
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
645 ret = dsync_mailbox_guid_cmp(src_boxes[src], dest_boxes[dest]); |
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
646 if (ret == 0) { |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
647 if ((full_sync || |
10371 | 648 dsync_mailbox_has_changes(brain, src_boxes[src], |
649 dest_boxes[dest])) && | |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
650 !src_deleted && !dest_deleted) { |
9686
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
651 brain_box = array_append_space(brain_boxes); |
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
652 brain_box->box = *src_boxes[src]; |
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
653 |
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
654 brain_box->box.highest_modseq = |
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
655 I_MAX(src_boxes[src]->highest_modseq, |
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
656 dest_boxes[dest]->highest_modseq); |
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
657 brain_box->box.uid_next = |
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
658 I_MAX(src_boxes[src]->uid_next, |
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
659 dest_boxes[dest]->uid_next); |
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
660 brain_box->src = src_boxes[src]; |
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
661 brain_box->dest = dest_boxes[dest]; |
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
662 } |
9639
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
663 src++; dest++; |
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
664 } else if (ret < 0) { |
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
665 /* exists only in source */ |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
666 if (!src_deleted) { |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
667 brain_box = array_append_space(brain_boxes); |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
668 brain_box->box = *src_boxes[src]; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
669 brain_box->src = src_boxes[src]; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
670 if (brain->verbose) { |
12846
0a1a0d33c1b2
dsync: When showing mailbox names, show also their GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
671 i_info("%s: only in source (guid=%s)", |
0a1a0d33c1b2
dsync: When showing mailbox names, show also their GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
672 brain_box->box.name, |
0a1a0d33c1b2
dsync: When showing mailbox names, show also their GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
673 dsync_guid_to_str(&brain_box->box.mailbox_guid)); |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
674 } |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
675 } |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
676 src++; |
9639
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
677 } else { |
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
678 /* exists only in dest */ |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
679 if (!dest_deleted) { |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
680 brain_box = array_append_space(brain_boxes); |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
681 brain_box->box = *dest_boxes[dest]; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
682 brain_box->dest = dest_boxes[dest]; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
683 if (brain->verbose) { |
12846
0a1a0d33c1b2
dsync: When showing mailbox names, show also their GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
684 i_info("%s: only in dest (guid=%s)", |
0a1a0d33c1b2
dsync: When showing mailbox names, show also their GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
685 brain_box->box.name, |
0a1a0d33c1b2
dsync: When showing mailbox names, show also their GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
686 dsync_guid_to_str(&brain_box->box.mailbox_guid)); |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
687 } |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
688 } |
9639
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
689 dest++; |
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
690 } |
ffda7bd92ebc
dsync: Skip syncing mailboxes whose uidvalidity/uidnext/highest-modseq hasn't changed.
Timo Sirainen <tss@iki.fi>
parents:
9638
diff
changeset
|
691 } |
9686
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
692 for (; src < src_count; src++) { |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
693 if ((src_boxes[src]->flags & |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
694 DSYNC_MAILBOX_FLAG_DELETED_MAILBOX) != 0) |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
695 continue; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
696 |
9686
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
697 brain_box = array_append_space(brain_boxes); |
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
698 brain_box->box = *src_boxes[src]; |
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
699 brain_box->src = src_boxes[src]; |
12846
0a1a0d33c1b2
dsync: When showing mailbox names, show also their GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
700 if (brain->verbose) { |
0a1a0d33c1b2
dsync: When showing mailbox names, show also their GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
701 i_info("%s: only in source (guid=%s)", |
0a1a0d33c1b2
dsync: When showing mailbox names, show also their GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
702 brain_box->box.name, |
0a1a0d33c1b2
dsync: When showing mailbox names, show also their GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
703 dsync_guid_to_str(&brain_box->box.mailbox_guid)); |
0a1a0d33c1b2
dsync: When showing mailbox names, show also their GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
704 } |
9559 | 705 } |
9686
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
706 for (; dest < dest_count; dest++) { |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
707 if ((dest_boxes[dest]->flags & |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
708 DSYNC_MAILBOX_FLAG_DELETED_MAILBOX) != 0) |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
709 continue; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
710 |
9686
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
711 brain_box = array_append_space(brain_boxes); |
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
712 brain_box->box = *dest_boxes[dest]; |
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
713 brain_box->dest = dest_boxes[dest]; |
12846
0a1a0d33c1b2
dsync: When showing mailbox names, show also their GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
714 if (brain->verbose) { |
0a1a0d33c1b2
dsync: When showing mailbox names, show also their GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
715 i_info("%s: only in dest (guid=%s)", |
0a1a0d33c1b2
dsync: When showing mailbox names, show also their GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
716 brain_box->box.name, |
0a1a0d33c1b2
dsync: When showing mailbox names, show also their GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
717 dsync_guid_to_str(&brain_box->box.mailbox_guid)); |
0a1a0d33c1b2
dsync: When showing mailbox names, show also their GUIDs.
Timo Sirainen <tss@iki.fi>
parents:
12782
diff
changeset
|
718 } |
9559 | 719 } |
720 } | |
721 | |
11804
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
722 static bool dsync_brain_sync_msgs(struct dsync_brain *brain) |
9559 | 723 { |
9686
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
724 ARRAY_TYPE(dsync_brain_mailbox) mailboxes; |
10217 | 725 pool_t pool; |
11804
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
726 bool ret; |
9559 | 727 |
14253
91e035840dc6
Increased initial memory pool sizes and marked some of them as "growing".
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
728 pool = pool_alloconly_create(MEMPOOL_GROWING"dsync changed mailboxes", |
91e035840dc6
Increased initial memory pool sizes and marked some of them as "growing".
Timo Sirainen <tss@iki.fi>
parents:
14133
diff
changeset
|
729 10240); |
10217 | 730 p_array_init(&mailboxes, pool, 128); |
9686
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
731 dsync_brain_get_changed_mailboxes(brain, &mailboxes, |
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
732 (brain->flags & DSYNC_BRAIN_FLAG_FULL_SYNC) != 0); |
11804
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
733 if (array_count(&mailboxes) > 0) { |
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
734 brain->mailbox_sync = |
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
735 dsync_brain_msg_sync_init(brain, &mailboxes); |
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
736 dsync_brain_msg_sync_more(brain->mailbox_sync); |
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
737 ret = TRUE; |
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
738 } else { |
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
739 ret = FALSE; |
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
740 } |
10217 | 741 pool_unref(&pool); |
11804
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
742 return ret; |
9559 | 743 } |
744 | |
745 static void | |
10371 | 746 dsync_brain_sync_rename_mailbox(struct dsync_brain *brain, |
747 const struct dsync_brain_mailbox *mailbox) | |
748 { | |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
749 if (mailbox->src->last_change > mailbox->dest->last_change || |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
750 brain->backup) { |
10371 | 751 dsync_worker_rename_mailbox(brain->dest_worker, |
752 &mailbox->box.mailbox_guid, | |
10373
036db604f86c
dsync: Fixed problems with syncing mailbox names that are invalid on other side.
Timo Sirainen <tss@iki.fi>
parents:
10371
diff
changeset
|
753 mailbox->src); |
10371 | 754 } else { |
755 dsync_worker_rename_mailbox(brain->src_worker, | |
756 &mailbox->box.mailbox_guid, | |
10373
036db604f86c
dsync: Fixed problems with syncing mailbox names that are invalid on other side.
Timo Sirainen <tss@iki.fi>
parents:
10371
diff
changeset
|
757 mailbox->dest); |
10371 | 758 } |
759 } | |
760 | |
761 static void | |
762 dsync_brain_sync_update_mailboxes(struct dsync_brain *brain) | |
9559 | 763 { |
10000
c610321584ca
Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents:
9759
diff
changeset
|
764 const struct dsync_brain_mailbox *mailbox; |
11680
49b226835cd2
dsync: Another try at not increasing mailbox uidnext/highestmodseq on failure
Timo Sirainen <tss@iki.fi>
parents:
11677
diff
changeset
|
765 bool failed_changes = dsync_brain_has_unexpected_changes(brain) || |
49b226835cd2
dsync: Another try at not increasing mailbox uidnext/highestmodseq on failure
Timo Sirainen <tss@iki.fi>
parents:
11677
diff
changeset
|
766 dsync_worker_has_failed(brain->src_worker) || |
49b226835cd2
dsync: Another try at not increasing mailbox uidnext/highestmodseq on failure
Timo Sirainen <tss@iki.fi>
parents:
11677
diff
changeset
|
767 dsync_worker_has_failed(brain->dest_worker); |
9559 | 768 |
11804
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
769 if (brain->mailbox_sync == NULL) { |
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
770 /* no mailboxes changed */ |
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
771 return; |
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
772 } |
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
773 |
10000
c610321584ca
Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents:
9759
diff
changeset
|
774 array_foreach(&brain->mailbox_sync->mailboxes, mailbox) { |
11677
b4f029f7793a
dsync: If dsync fails in any way, don't increase mailboxes' next_uid/highestmodseq.
Timo Sirainen <tss@iki.fi>
parents:
11676
diff
changeset
|
775 /* don't update mailboxes if any changes had failed. |
b4f029f7793a
dsync: If dsync fails in any way, don't increase mailboxes' next_uid/highestmodseq.
Timo Sirainen <tss@iki.fi>
parents:
11676
diff
changeset
|
776 for example if some messages couldn't be saved, we don't |
b4f029f7793a
dsync: If dsync fails in any way, don't increase mailboxes' next_uid/highestmodseq.
Timo Sirainen <tss@iki.fi>
parents:
11676
diff
changeset
|
777 want to increase the next_uid to jump over them */ |
b4f029f7793a
dsync: If dsync fails in any way, don't increase mailboxes' next_uid/highestmodseq.
Timo Sirainen <tss@iki.fi>
parents:
11676
diff
changeset
|
778 if (!brain->backup && !failed_changes) { |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
779 dsync_worker_update_mailbox(brain->src_worker, |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
780 &mailbox->box); |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
781 } |
11677
b4f029f7793a
dsync: If dsync fails in any way, don't increase mailboxes' next_uid/highestmodseq.
Timo Sirainen <tss@iki.fi>
parents:
11676
diff
changeset
|
782 if (!failed_changes) { |
b4f029f7793a
dsync: If dsync fails in any way, don't increase mailboxes' next_uid/highestmodseq.
Timo Sirainen <tss@iki.fi>
parents:
11676
diff
changeset
|
783 dsync_worker_update_mailbox(brain->dest_worker, |
b4f029f7793a
dsync: If dsync fails in any way, don't increase mailboxes' next_uid/highestmodseq.
Timo Sirainen <tss@iki.fi>
parents:
11676
diff
changeset
|
784 &mailbox->box); |
b4f029f7793a
dsync: If dsync fails in any way, don't increase mailboxes' next_uid/highestmodseq.
Timo Sirainen <tss@iki.fi>
parents:
11676
diff
changeset
|
785 } |
10373
036db604f86c
dsync: Fixed problems with syncing mailbox names that are invalid on other side.
Timo Sirainen <tss@iki.fi>
parents:
10371
diff
changeset
|
786 |
10371 | 787 if (mailbox->src != NULL && mailbox->dest != NULL && |
788 strcmp(mailbox->src->name, mailbox->dest->name) != 0) | |
789 dsync_brain_sync_rename_mailbox(brain, mailbox); | |
9559 | 790 } |
791 } | |
792 | |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
793 static void dsync_brain_worker_finished(bool success, void *context) |
9559 | 794 { |
795 struct dsync_brain *brain = context; | |
796 | |
10976
f6c2c0866aff
dsync: Added extra sanity check.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
797 switch (brain->state) { |
f6c2c0866aff
dsync: Added extra sanity check.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
798 case DSYNC_STATE_SYNC_MSGS_FLUSH: |
f6c2c0866aff
dsync: Added extra sanity check.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
799 case DSYNC_STATE_SYNC_MSGS_FLUSH2: |
f6c2c0866aff
dsync: Added extra sanity check.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
800 case DSYNC_STATE_SYNC_FLUSH: |
f6c2c0866aff
dsync: Added extra sanity check.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
801 case DSYNC_STATE_SYNC_FLUSH2: |
f6c2c0866aff
dsync: Added extra sanity check.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
802 break; |
f6c2c0866aff
dsync: Added extra sanity check.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
803 default: |
f6c2c0866aff
dsync: Added extra sanity check.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
804 i_panic("dsync brain state=%d", brain->state); |
f6c2c0866aff
dsync: Added extra sanity check.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
805 } |
f6c2c0866aff
dsync: Added extra sanity check.
Timo Sirainen <tss@iki.fi>
parents:
10582
diff
changeset
|
806 |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
807 if (!success) |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
808 dsync_brain_fail(brain); |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
809 |
9559 | 810 brain->state++; |
11786
fd33ccbf235e
dsync: Fixed brain unit test not to crash at deinit.
Timo Sirainen <tss@iki.fi>
parents:
11775
diff
changeset
|
811 if (brain->to == NULL && (brain->flags & DSYNC_BRAIN_FLAG_LOCAL) == 0) |
11775 | 812 brain->to = timeout_add(0, dsync_brain_sync, brain); |
9559 | 813 } |
814 | |
815 void dsync_brain_sync(struct dsync_brain *brain) | |
816 { | |
12028
6ef21adeb61d
dsync: If worker fails, abort earlier.
Timo Sirainen <tss@iki.fi>
parents:
11971
diff
changeset
|
817 if (dsync_worker_has_failed(brain->src_worker) || |
6ef21adeb61d
dsync: If worker fails, abort earlier.
Timo Sirainen <tss@iki.fi>
parents:
11971
diff
changeset
|
818 dsync_worker_has_failed(brain->dest_worker)) { |
6ef21adeb61d
dsync: If worker fails, abort earlier.
Timo Sirainen <tss@iki.fi>
parents:
11971
diff
changeset
|
819 /* we can't safely continue, especially with backup */ |
6ef21adeb61d
dsync: If worker fails, abort earlier.
Timo Sirainen <tss@iki.fi>
parents:
11971
diff
changeset
|
820 return; |
6ef21adeb61d
dsync: If worker fails, abort earlier.
Timo Sirainen <tss@iki.fi>
parents:
11971
diff
changeset
|
821 } |
6ef21adeb61d
dsync: If worker fails, abort earlier.
Timo Sirainen <tss@iki.fi>
parents:
11971
diff
changeset
|
822 |
11775 | 823 if (brain->to != NULL) |
824 timeout_remove(&brain->to); | |
9559 | 825 switch (brain->state) { |
826 case DSYNC_STATE_GET_MAILBOXES: | |
827 i_assert(brain->src_mailbox_list == NULL); | |
828 brain->src_mailbox_list = | |
829 dsync_brain_mailbox_list_init(brain, brain->src_worker); | |
830 brain->dest_mailbox_list = | |
831 dsync_brain_mailbox_list_init(brain, brain->dest_worker); | |
832 dsync_worker_mailbox_input(brain->src_mailbox_list); | |
833 dsync_worker_mailbox_input(brain->dest_mailbox_list); | |
834 break; | |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
835 case DSYNC_STATE_GET_SUBSCRIPTIONS: |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
836 i_assert(brain->src_subs_list == NULL); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
837 brain->src_subs_list = |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
838 dsync_brain_subs_list_init(brain, brain->src_worker); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
839 brain->dest_subs_list = |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
840 dsync_brain_subs_list_init(brain, brain->dest_worker); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
841 dsync_worker_subs_input(brain->src_subs_list); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
842 dsync_worker_subs_input(brain->dest_subs_list); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
843 break; |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
844 case DSYNC_STATE_SYNC_MAILBOXES: |
11804
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
845 dsync_worker_set_input_callback(brain->src_worker, NULL, NULL); |
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
846 dsync_worker_set_input_callback(brain->dest_worker, NULL, NULL); |
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
847 |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
848 dsync_brain_sync_mailboxes(brain); |
11524
c955d4789553
dsync: Fixed syncing \noselect mailboxes.
Timo Sirainen <tss@iki.fi>
parents:
10976
diff
changeset
|
849 dsync_brain_sync_dirs(brain); |
9559 | 850 brain->state++; |
851 /* fall through */ | |
10328
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
852 case DSYNC_STATE_SYNC_SUBSCRIPTIONS: |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
853 dsync_brain_sync_subscriptions(brain); |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
854 brain->state++; |
b63fd6156663
dsync: Added support for subscription syncing.
Timo Sirainen <tss@iki.fi>
parents:
10323
diff
changeset
|
855 /* fall through */ |
9686
4d5cc6ce68aa
dsync: Lots of improvements and fixes. Appears to be somewhat working now.
Timo Sirainen <tss@iki.fi>
parents:
9644
diff
changeset
|
856 case DSYNC_STATE_SYNC_MSGS: |
11804
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
857 if (dsync_brain_sync_msgs(brain)) |
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
858 break; |
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
859 brain->state++; |
5e285530914c
dsync: Don't give errors when doing a remote sync and there are no changes.
Timo Sirainen <tss@iki.fi>
parents:
11786
diff
changeset
|
860 /* no mailboxes changed */ |
10323
513cff2a7008
dsync: Wait for all saves to finish before updating mailboxes' metadata.
Timo Sirainen <tss@iki.fi>
parents:
10217
diff
changeset
|
861 case DSYNC_STATE_SYNC_MSGS_FLUSH: |
513cff2a7008
dsync: Wait for all saves to finish before updating mailboxes' metadata.
Timo Sirainen <tss@iki.fi>
parents:
10217
diff
changeset
|
862 /* wait until all saves are done, so we don't try to close |
513cff2a7008
dsync: Wait for all saves to finish before updating mailboxes' metadata.
Timo Sirainen <tss@iki.fi>
parents:
10217
diff
changeset
|
863 the mailbox too early */ |
513cff2a7008
dsync: Wait for all saves to finish before updating mailboxes' metadata.
Timo Sirainen <tss@iki.fi>
parents:
10217
diff
changeset
|
864 dsync_worker_finish(brain->src_worker, |
513cff2a7008
dsync: Wait for all saves to finish before updating mailboxes' metadata.
Timo Sirainen <tss@iki.fi>
parents:
10217
diff
changeset
|
865 dsync_brain_worker_finished, brain); |
513cff2a7008
dsync: Wait for all saves to finish before updating mailboxes' metadata.
Timo Sirainen <tss@iki.fi>
parents:
10217
diff
changeset
|
866 dsync_worker_finish(brain->dest_worker, |
513cff2a7008
dsync: Wait for all saves to finish before updating mailboxes' metadata.
Timo Sirainen <tss@iki.fi>
parents:
10217
diff
changeset
|
867 dsync_brain_worker_finished, brain); |
513cff2a7008
dsync: Wait for all saves to finish before updating mailboxes' metadata.
Timo Sirainen <tss@iki.fi>
parents:
10217
diff
changeset
|
868 break; |
513cff2a7008
dsync: Wait for all saves to finish before updating mailboxes' metadata.
Timo Sirainen <tss@iki.fi>
parents:
10217
diff
changeset
|
869 case DSYNC_STATE_SYNC_MSGS_FLUSH2: |
513cff2a7008
dsync: Wait for all saves to finish before updating mailboxes' metadata.
Timo Sirainen <tss@iki.fi>
parents:
10217
diff
changeset
|
870 break; |
10371 | 871 case DSYNC_STATE_SYNC_UPDATE_MAILBOXES: |
872 dsync_brain_sync_update_mailboxes(brain); | |
9559 | 873 brain->state++; |
874 /* fall through */ | |
875 case DSYNC_STATE_SYNC_FLUSH: | |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
876 dsync_worker_finish(brain->src_worker, |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
877 dsync_brain_worker_finished, brain); |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
878 dsync_worker_finish(brain->dest_worker, |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
879 dsync_brain_worker_finished, brain); |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
880 break; |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
881 case DSYNC_STATE_SYNC_FLUSH2: |
9559 | 882 break; |
883 case DSYNC_STATE_SYNC_END: | |
13875
4c827134997f
Merged dsync into "doveadm dsync".
Timo Sirainen <tss@iki.fi>
parents:
12851
diff
changeset
|
884 io_loop_stop(current_ioloop); |
9559 | 885 break; |
9736
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
886 default: |
d9a96da46d4a
dsync: Lots of updates and fixes.
Timo Sirainen <tss@iki.fi>
parents:
9686
diff
changeset
|
887 i_unreached(); |
9559 | 888 } |
889 } | |
10354
22ffa2eb68c0
dsync convert <source> converts mailbox without proxying. Renamed -e parameter to "mirror".
Timo Sirainen <tss@iki.fi>
parents:
10331
diff
changeset
|
890 |
22ffa2eb68c0
dsync convert <source> converts mailbox without proxying. Renamed -e parameter to "mirror".
Timo Sirainen <tss@iki.fi>
parents:
10331
diff
changeset
|
891 void dsync_brain_sync_all(struct dsync_brain *brain) |
22ffa2eb68c0
dsync convert <source> converts mailbox without proxying. Renamed -e parameter to "mirror".
Timo Sirainen <tss@iki.fi>
parents:
10331
diff
changeset
|
892 { |
22ffa2eb68c0
dsync convert <source> converts mailbox without proxying. Renamed -e parameter to "mirror".
Timo Sirainen <tss@iki.fi>
parents:
10331
diff
changeset
|
893 enum dsync_state old_state; |
22ffa2eb68c0
dsync convert <source> converts mailbox without proxying. Renamed -e parameter to "mirror".
Timo Sirainen <tss@iki.fi>
parents:
10331
diff
changeset
|
894 |
22ffa2eb68c0
dsync convert <source> converts mailbox without proxying. Renamed -e parameter to "mirror".
Timo Sirainen <tss@iki.fi>
parents:
10331
diff
changeset
|
895 while (brain->state != DSYNC_STATE_SYNC_END) { |
22ffa2eb68c0
dsync convert <source> converts mailbox without proxying. Renamed -e parameter to "mirror".
Timo Sirainen <tss@iki.fi>
parents:
10331
diff
changeset
|
896 old_state = brain->state; |
22ffa2eb68c0
dsync convert <source> converts mailbox without proxying. Renamed -e parameter to "mirror".
Timo Sirainen <tss@iki.fi>
parents:
10331
diff
changeset
|
897 dsync_brain_sync(brain); |
11971 | 898 |
14021
2a4b425b05dc
dsync: If brain fails but workers don't, exit without assert-crashing.
Timo Sirainen <tss@iki.fi>
parents:
13875
diff
changeset
|
899 if (dsync_brain_has_failed(brain)) |
11971 | 900 break; |
901 | |
10354
22ffa2eb68c0
dsync convert <source> converts mailbox without proxying. Renamed -e parameter to "mirror".
Timo Sirainen <tss@iki.fi>
parents:
10331
diff
changeset
|
902 i_assert(brain->state != old_state); |
22ffa2eb68c0
dsync convert <source> converts mailbox without proxying. Renamed -e parameter to "mirror".
Timo Sirainen <tss@iki.fi>
parents:
10331
diff
changeset
|
903 } |
22ffa2eb68c0
dsync convert <source> converts mailbox without proxying. Renamed -e parameter to "mirror".
Timo Sirainen <tss@iki.fi>
parents:
10331
diff
changeset
|
904 } |
10368
9f2e8d230bd5
dsync: If some uid/modseq changes couldn't be done, exit with different value.
Timo Sirainen <tss@iki.fi>
parents:
10356
diff
changeset
|
905 |
9f2e8d230bd5
dsync: If some uid/modseq changes couldn't be done, exit with different value.
Timo Sirainen <tss@iki.fi>
parents:
10356
diff
changeset
|
906 bool dsync_brain_has_unexpected_changes(struct dsync_brain *brain) |
9f2e8d230bd5
dsync: If some uid/modseq changes couldn't be done, exit with different value.
Timo Sirainen <tss@iki.fi>
parents:
10356
diff
changeset
|
907 { |
11676
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
908 return brain->unexpected_changes || |
cf7f6912af02
dsync: Added backup command, which syncs source to destination, discarding any changes in dest.
Timo Sirainen <tss@iki.fi>
parents:
11524
diff
changeset
|
909 dsync_worker_has_unexpected_changes(brain->src_worker) || |
10368
9f2e8d230bd5
dsync: If some uid/modseq changes couldn't be done, exit with different value.
Timo Sirainen <tss@iki.fi>
parents:
10356
diff
changeset
|
910 dsync_worker_has_unexpected_changes(brain->dest_worker); |
9f2e8d230bd5
dsync: If some uid/modseq changes couldn't be done, exit with different value.
Timo Sirainen <tss@iki.fi>
parents:
10356
diff
changeset
|
911 } |
12124
eb5adb193064
dsync: Don't crash/hang if syncing fails before ioloop is started.
Timo Sirainen <tss@iki.fi>
parents:
12028
diff
changeset
|
912 |
eb5adb193064
dsync: Don't crash/hang if syncing fails before ioloop is started.
Timo Sirainen <tss@iki.fi>
parents:
12028
diff
changeset
|
913 bool dsync_brain_has_failed(struct dsync_brain *brain) |
eb5adb193064
dsync: Don't crash/hang if syncing fails before ioloop is started.
Timo Sirainen <tss@iki.fi>
parents:
12028
diff
changeset
|
914 { |
eb5adb193064
dsync: Don't crash/hang if syncing fails before ioloop is started.
Timo Sirainen <tss@iki.fi>
parents:
12028
diff
changeset
|
915 return brain->failed || |
eb5adb193064
dsync: Don't crash/hang if syncing fails before ioloop is started.
Timo Sirainen <tss@iki.fi>
parents:
12028
diff
changeset
|
916 dsync_worker_has_failed(brain->src_worker) || |
eb5adb193064
dsync: Don't crash/hang if syncing fails before ioloop is started.
Timo Sirainen <tss@iki.fi>
parents:
12028
diff
changeset
|
917 dsync_worker_has_failed(brain->dest_worker); |
eb5adb193064
dsync: Don't crash/hang if syncing fails before ioloop is started.
Timo Sirainen <tss@iki.fi>
parents:
12028
diff
changeset
|
918 } |