dovecot-2.0: dsync: If mailbox exists in both sides, create it a...
dovecot at dovecot.org
dovecot at dovecot.org
Tue Dec 22 19:51:46 EET 2009
details: http://hg.dovecot.org/dovecot-2.0/rev/e3db0a5889b7
changeset: 10520:e3db0a5889b7
user: Timo Sirainen <tss at iki.fi>
date: Mon Dec 21 18:16:17 2009 -0500
description:
dsync: If mailbox exists in both sides, create it as name_guid in other side.
diffstat:
1 file changed, 58 insertions(+), 17 deletions(-)
src/dsync/dsync-worker-local.c | 75 ++++++++++++++++++++++++++++++----------
diffs (99 lines):
diff -r eba3e50fef36 -r e3db0a5889b7 src/dsync/dsync-worker-local.c
--- a/src/dsync/dsync-worker-local.c Mon Dec 21 15:17:08 2009 -0500
+++ b/src/dsync/dsync-worker-local.c Mon Dec 21 18:16:17 2009 -0500
@@ -984,37 +984,78 @@ local_worker_mailbox_alloc(struct local_
return mailbox_alloc(ns->list, name, NULL, 0);
}
-static void
-local_worker_create_mailbox(struct dsync_worker *_worker,
- const struct dsync_mailbox *dsync_box)
-{
- struct local_dsync_worker *worker =
- (struct local_dsync_worker *)_worker;
- struct mailbox *box;
+static int
+local_worker_create_allocated_mailbox(struct local_dsync_worker *worker,
+ struct mailbox *box,
+ const struct dsync_mailbox *dsync_box)
+{
struct mailbox_update update;
+ const char *errstr;
+ enum mail_error error;
int ret;
- box = local_worker_mailbox_alloc(worker, dsync_box, TRUE);
- if (box == NULL) {
- dsync_worker_set_failure(_worker);
- return;
- }
local_worker_copy_mailbox_update(dsync_box, &update);
ret = mailbox_create(box, &update, dsync_box->uid_validity == 0);
- if (ret < 0 && strcasecmp(dsync_box->name, "INBOX") == 0)
+ if (ret < 0 && strcasecmp(mailbox_get_name(box), "INBOX") == 0)
ret = mailbox_update(box, &update);
+ errstr = mail_storage_get_last_error(mailbox_get_storage(box), &error);
+ if (ret < 0 && error == MAIL_ERROR_EXISTS) {
+ /* mailbox already exists */
+ if (dsync_box->uid_validity != 0)
+ return 0;
+ else {
+ /* just a directory - no one cares */
+ return 1;
+ }
+ }
if (ret < 0) {
- dsync_worker_set_failure(_worker);
- i_error("Can't create mailbox %s: %s", dsync_box->name,
- mail_storage_get_last_error(mailbox_get_storage(box),
- NULL));
+ dsync_worker_set_failure(&worker->worker);
+ i_error("Can't create mailbox %s: %s", dsync_box->name, errstr);
} else {
local_dsync_worker_add_mailbox(worker,
mailbox_get_namespace(box),
mailbox_get_name(box),
&dsync_box->mailbox_guid);
}
+ return ret < 0 ? -1 : 1;
+}
+
+static void
+local_worker_create_mailbox(struct dsync_worker *_worker,
+ const struct dsync_mailbox *dsync_box)
+{
+ struct local_dsync_worker *worker =
+ (struct local_dsync_worker *)_worker;
+ struct mailbox *box;
+ struct mail_namespace *ns;
+ const char *new_name;
+ int ret;
+
+ box = local_worker_mailbox_alloc(worker, dsync_box, TRUE);
+ if (box == NULL) {
+ dsync_worker_set_failure(_worker);
+ return;
+ }
+
+ ret = local_worker_create_allocated_mailbox(worker, box, dsync_box);
+ if (ret != 0) {
+ mailbox_close(&box);
+ return;
+ }
+
+ /* mailbox name already exists. add mailbox guid to the name,
+ that shouldn't exist. */
+ new_name = t_strconcat(mailbox_get_name(box), "_",
+ dsync_guid_to_str(&dsync_box->mailbox_guid),
+ NULL);
+ ns = mailbox_get_namespace(box);
+ mailbox_close(&box);
+
+ local_dsync_worker_add_mailbox(worker, ns, new_name,
+ &dsync_box->mailbox_guid);
+ box = mailbox_alloc(ns->list, new_name, NULL, 0);
+ (void)local_worker_create_allocated_mailbox(worker, box, dsync_box);
mailbox_close(&box);
}
More information about the dovecot-cvs
mailing list