changeset 12115:7305a7787536

dsync: Don't create \Noselect mailboxes as selectable mailboxes, rather just don't create them. This fixes creating extra empty mailboxes when mirroring mbox+fs layout and maildir++ layout.
author Timo Sirainen <tss@iki.fi>
date Tue, 14 Sep 2010 16:20:18 +0100
parents ba924e3ee4ae
children 02d78c4a0a51
files src/dsync/dsync-worker-local.c
diffstat 1 files changed, 36 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/dsync/dsync-worker-local.c	Tue Sep 14 16:18:13 2010 +0100
+++ b/src/dsync/dsync-worker-local.c	Tue Sep 14 16:20:18 2010 +0100
@@ -1130,6 +1130,33 @@
 	return mailbox_alloc(ns->list, name, 0);
 }
 
+static int local_worker_create_dir(struct mailbox *box,
+				   const struct dsync_mailbox *dsync_box)
+{
+	struct mailbox_list *list = mailbox_get_namespace(box)->list;
+	const char *errstr;
+	enum mail_error error;
+
+	if (mailbox_list_create_dir(list, mailbox_get_name(box)) == 0)
+		return 0;
+
+	errstr = mailbox_list_get_last_error(list, &error);
+	switch (error) {
+	case MAIL_ERROR_EXISTS:
+		/* directory already exists - that's ok */
+		return 0;
+	case MAIL_ERROR_NOTPOSSIBLE:
+		/* \noselect mailboxes not supported - just ignore them
+		   (we don't want to create a selectable mailbox if the other
+		   side of the sync doesn't support dual-use mailboxes,
+		   e.g. mbox) */
+		return 0;
+	default:
+		i_error("Can't create mailbox %s: %s", dsync_box->name, errstr);
+		return -1;
+	}
+}
+
 static int
 local_worker_create_allocated_mailbox(struct local_dsync_worker *worker,
 				      struct mailbox *box,
@@ -1141,15 +1168,19 @@
 
 	local_worker_copy_mailbox_update(dsync_box, &update);
 
-	if (mailbox_create(box, &update, dsync_box->uid_validity == 0) < 0) {
+	if (dsync_mailbox_is_noselect(dsync_box)) {
+		if (local_worker_create_dir(box, dsync_box) < 0) {
+			dsync_worker_set_failure(&worker->worker);
+			return -1;
+		}
+		return 1;
+	}
+
+	if (mailbox_create(box, &update, FALSE) < 0) {
 		errstr = mail_storage_get_last_error(mailbox_get_storage(box),
 						     &error);
 		if (error == MAIL_ERROR_EXISTS) {
 			/* mailbox already exists */
-			if (dsync_box->uid_validity == 0) {
-				/* just a directory - no one cares */
-				return 1;
-			}
 			return 0;
 		}