dsync-brain-mailbox-tree-sync.c revision ec047a9c54a02338e85fb1767120b0923f6d4148
/* Copyright (c) 2013 Dovecot authors, see the included COPYING file */
#include "lib.h"
#include "mail-namespace.h"
#include "mail-storage.h"
#include "dsync-mailbox-tree.h"
#include "dsync-brain-private.h"
static int
{
struct mailbox_metadata metadata;
struct mailbox_update update;
enum mail_error error;
const char *errstr;
int ret;
if (error != MAIL_ERROR_EXISTS) {
i_error("Can't create mailbox %s: %s",
return -1;
}
}
/* sync the mailbox so we can look up its latest status */
i_error("Can't sync mailbox %s: %s",
return -1;
}
/* verify that the GUID is what we wanted. if it's not, it probably
means that the mailbox had already been created. then we'll use the
GUID that is higher.
mismatching UIDVALIDITY is handled later, because we choose it by
checking which mailbox has more messages */
i_error("Can't get mailbox GUID %s: %s",
return -1;
}
if (ret > 0) {
i_debug("brain %c: Changing mailbox %s GUID %s -> %s",
}
sizeof(update.mailbox_guid));
i_error("Can't update mailbox GUID %s: %s",
return -1;
}
/* verify that the update worked */
&metadata) < 0) {
i_error("Can't get mailbox GUID %s: %s",
return -1;
}
i_error("Backend didn't update mailbox %s GUID",
return -1;
}
} else if (ret < 0) {
i_debug("brain %c: Other brain should change mailbox "
"%s GUID %s -> %s",
}
}
return 0;
}
const struct dsync_mailbox_tree_sync_change *change)
{
enum mail_error error;
int ret = -1;
if (brain->backup_send) {
return 0;
}
/* make sure we're deleting the correct mailbox */
if (ret < 0) {
i_error("Mailbox sync: Couldn't allocate mailbox GUID %s: %s",
return -1;
}
if (ret == 0) {
i_debug("brain %c: Mailbox GUID %s sync: "
"Deletion conflict: %s",
}
return ret;
}
break;
return 0;
if (error == MAIL_ERROR_NOTFOUND ||
error == MAIL_ERROR_EXISTS) {
i_debug("brain %c: Mailbox %s sync: "
"mailbox_list_delete_dir conflict: %s",
}
return 0;
} else {
i_error("Mailbox sync: mailbox_list_delete_dir failed: %s",
errstr);
return -1;
}
default:
break;
}
mailbox_free(&box);
return ret;
func_name = "mailbox_create";
break;
func_name = "mailbox_delete";
break;
i_unreached();
change->rename_dest_name, 0);
func_name = "mailbox_rename";
break;
func_name = "mailbox_set_subscribed";
break;
func_name = "mailbox_set_subscribed";
break;
}
if (ret < 0) {
if (error == MAIL_ERROR_EXISTS ||
error == MAIL_ERROR_NOTFOUND) {
/* mailbox was already created or was already deleted.
let the next sync figure out what to do */
i_debug("brain %c: Mailbox %s sync: %s conflict: %s",
}
ret = 0;
} else {
i_error("Mailbox %s sync: %s failed: %s",
}
}
mailbox_free(&box);
return ret;
}