dovecot-2.0: mailbox_update(): Update index also.

dovecot at dovecot.org dovecot at dovecot.org
Thu Aug 6 03:30:50 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/dd4c5e43c55a
changeset: 9726:dd4c5e43c55a
user:      Timo Sirainen <tss at iki.fi>
date:      Wed Aug 05 20:09:24 2009 -0400
description:
mailbox_update(): Update index also.

diffstat:

5 files changed, 62 insertions(+), 25 deletions(-)
src/lib-storage/index/cydir/cydir-storage.c     |   25 -----------
src/lib-storage/index/dbox/dbox-storage.c       |    7 +++
src/lib-storage/index/index-storage.c           |   49 +++++++++++++++++++++++
src/lib-storage/index/index-storage.h           |    2 
src/lib-storage/index/maildir/maildir-storage.c |    4 -

diffs (159 lines):

diff -r 1411f157ffdd -r dd4c5e43c55a src/lib-storage/index/cydir/cydir-storage.c
--- a/src/lib-storage/index/cydir/cydir-storage.c	Wed Aug 05 20:01:34 2009 -0400
+++ b/src/lib-storage/index/cydir/cydir-storage.c	Wed Aug 05 20:09:24 2009 -0400
@@ -133,27 +133,6 @@ static int cydir_mailbox_open(struct mai
 }
 
 static int
-cydir_mailbox_update(struct mailbox *box, const struct mailbox_update *update)
-{
-	struct cydir_mailbox *mbox = (struct cydir_mailbox *)box;
-	struct mail_index_transaction *trans;
-
-	trans = mail_index_transaction_begin(mbox->ibox.view, 0);
-	if (update->uid_validity != 0) {
-		mail_index_update_header(trans,
-			offsetof(struct mail_index_header, uid_validity),
-			&update->uid_validity, sizeof(update->uid_validity),
-			TRUE);
-	}
-	/* FIXME: update next_uid, highestmodseq. guid is also missing.. */
-	if (mail_index_transaction_commit(&trans) < 0) {
-		mail_storage_set_internal_error(box->storage);
-		return -1;
-	}
-	return 0;
-}
-
-static int
 cydir_mailbox_create(struct mailbox *box, const struct mailbox_update *update,
 		     bool directory)
 {
@@ -172,7 +151,7 @@ cydir_mailbox_create(struct mailbox *box
 		return -1;
 
 	return directory || update == NULL ? 0 :
-		cydir_mailbox_update(box, update);
+		index_storage_mailbox_update(box, update);
 }
 
 static int
@@ -379,7 +358,7 @@ struct mailbox cydir_mailbox = {
 		cydir_mailbox_open,
 		index_storage_mailbox_close,
 		cydir_mailbox_create,
-		cydir_mailbox_update,
+		index_storage_mailbox_update,
 		index_storage_get_status,
 		NULL,
 		NULL,
diff -r 1411f157ffdd -r dd4c5e43c55a src/lib-storage/index/dbox/dbox-storage.c
--- a/src/lib-storage/index/dbox/dbox-storage.c	Wed Aug 05 20:01:34 2009 -0400
+++ b/src/lib-storage/index/dbox/dbox-storage.c	Wed Aug 05 20:09:24 2009 -0400
@@ -11,6 +11,7 @@
 #include "unlink-old-files.h"
 #include "index-mail.h"
 #include "mail-copy.h"
+#include "mail-index-modseq.h"
 #include "mailbox-uidvalidity.h"
 #include "maildir/maildir-uidlist.h"
 #include "dbox-map.h"
@@ -274,6 +275,12 @@ static int dbox_write_index_header(struc
 		mail_index_update_header(trans,
 			offsetof(struct mail_index_header, next_uid),
 			&uid_next, sizeof(uid_next), TRUE);
+	}
+	if (update != NULL && update->min_highest_modseq != 0 &&
+	    mail_index_modseq_get_highest(mbox->ibox.view) <
+	    					update->min_highest_modseq) {
+		mail_index_update_highest_modseq(trans,
+						 update->min_highest_modseq);
 	}
 
 	if (mail_index_transaction_commit(&trans) < 0) {
diff -r 1411f157ffdd -r dd4c5e43c55a src/lib-storage/index/index-storage.c
--- a/src/lib-storage/index/index-storage.c	Wed Aug 05 20:01:34 2009 -0400
+++ b/src/lib-storage/index/index-storage.c	Wed Aug 05 20:09:24 2009 -0400
@@ -536,6 +536,55 @@ void index_storage_mailbox_close(struct 
 	pool_unref(&box->pool);
 }
 
+int index_storage_mailbox_update(struct mailbox *box,
+				 const struct mailbox_update *update)
+{
+	struct index_mailbox *ibox = (struct index_mailbox *)box;
+	const struct mail_index_header *hdr;
+	struct mail_index_view *view;
+	struct mail_index_transaction *trans;
+	int ret;
+
+	if (!box->opened) {
+		if (mailbox_open(box) < 0)
+			return -1;
+	}
+
+	/* make sure we get the latest index info */
+	(void)mail_index_refresh(ibox->index);
+	view = mail_index_view_open(ibox->index);
+	hdr = mail_index_get_header(view);
+
+	trans = mail_index_transaction_begin(view,
+					MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL);
+	if (update->uid_validity != 0 &&
+	    hdr->uid_validity != update->uid_validity) {
+		uint32_t uid_validity = update->uid_validity;
+
+		mail_index_update_header(trans,
+			offsetof(struct mail_index_header, uid_validity),
+			&uid_validity, sizeof(uid_validity), TRUE);
+	}
+	if (update->min_next_uid != 0 &&
+	    hdr->next_uid < update->min_next_uid) {
+		uint32_t next_uid = update->min_next_uid;
+
+		mail_index_update_header(trans,
+			offsetof(struct mail_index_header, next_uid),
+			&next_uid, sizeof(next_uid), FALSE);
+	}
+	if (update->min_highest_modseq != 0 &&
+	    mail_index_modseq_get_highest(view) < update->min_highest_modseq) {
+		mail_index_update_highest_modseq(trans,
+						 update->min_highest_modseq);
+	}
+
+	if ((ret = mail_index_transaction_commit(&trans)) < 0)
+		mail_storage_set_internal_error(box->storage);
+	mail_index_view_close(&view);
+	return ret;
+}
+
 bool index_storage_is_readonly(struct mailbox *box)
 {
 	struct index_mailbox *ibox = (struct index_mailbox *) box;
diff -r 1411f157ffdd -r dd4c5e43c55a src/lib-storage/index/index-storage.h
--- a/src/lib-storage/index/index-storage.h	Wed Aug 05 20:01:34 2009 -0400
+++ b/src/lib-storage/index/index-storage.h	Wed Aug 05 20:09:24 2009 -0400
@@ -85,6 +85,8 @@ int index_storage_mailbox_enable(struct 
 int index_storage_mailbox_enable(struct mailbox *box,
 				 enum mailbox_feature feature);
 void index_storage_mailbox_close(struct mailbox *box);
+int index_storage_mailbox_update(struct mailbox *box,
+				 const struct mailbox_update *update);
 
 bool index_storage_is_readonly(struct mailbox *box);
 bool index_storage_allow_new_keywords(struct mailbox *box);
diff -r 1411f157ffdd -r dd4c5e43c55a src/lib-storage/index/maildir/maildir-storage.c
--- a/src/lib-storage/index/maildir/maildir-storage.c	Wed Aug 05 20:01:34 2009 -0400
+++ b/src/lib-storage/index/maildir/maildir-storage.c	Wed Aug 05 20:09:24 2009 -0400
@@ -515,9 +515,9 @@ maildir_mailbox_update(struct mailbox *b
 		maildir_uidlist_set_next_uid(uidlist, update->min_next_uid,
 					     FALSE);
 	}
-	/* FIXME: update highestmodseq */
-
 	ret = maildir_uidlist_update(uidlist);
+	if (ret == 0)
+		ret = index_storage_mailbox_update(box, update);
 	maildir_uidlist_unlock(uidlist);
 	return ret;
 }


More information about the dovecot-cvs mailing list