changeset 12533:67257180c7ea

lib-storage: Moved box->private_flags_mask to mailbox_get_private_flags_mask() This allows getting it lazily only when it's actually needed.
author Timo Sirainen <tss@iki.fi>
date Mon, 06 Dec 2010 01:11:07 +0000
parents 565351636cd7
children 059277ba8a75
files src/lib-storage/index/cydir/cydir-storage.c src/lib-storage/index/dbox-multi/mdbox-storage.c src/lib-storage/index/dbox-single/sdbox-storage.c src/lib-storage/index/index-storage.c src/lib-storage/index/maildir/maildir-storage.c src/lib-storage/index/maildir/maildir-storage.h src/lib-storage/index/maildir/maildir-sync-index.c src/lib-storage/index/mbox/mbox-storage.c src/lib-storage/index/raw/raw-storage.c src/lib-storage/mail-storage-private.h src/lib-storage/mail-storage.c src/lib-storage/mail-storage.h src/lib-storage/test-mailbox.c src/plugins/acl/acl-mailbox.c src/plugins/virtual/virtual-storage.c
diffstat 15 files changed, 51 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/cydir/cydir-storage.c	Mon Dec 06 00:52:42 2010 +0000
+++ b/src/lib-storage/index/cydir/cydir-storage.c	Mon Dec 06 01:11:07 2010 +0000
@@ -167,6 +167,7 @@
 		NULL,
 		NULL,
 		NULL,
+		NULL,
 		index_mail_alloc,
 		index_header_lookup_init,
 		index_header_lookup_deinit,
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.c	Mon Dec 06 00:52:42 2010 +0000
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c	Mon Dec 06 01:11:07 2010 +0000
@@ -426,6 +426,7 @@
 		NULL,
 		NULL,
 		NULL,
+		NULL,
 		dbox_mail_alloc,
 		index_header_lookup_init,
 		index_header_lookup_deinit,
--- a/src/lib-storage/index/dbox-single/sdbox-storage.c	Mon Dec 06 00:52:42 2010 +0000
+++ b/src/lib-storage/index/dbox-single/sdbox-storage.c	Mon Dec 06 01:11:07 2010 +0000
@@ -393,6 +393,7 @@
 		NULL,
 		NULL,
 		NULL,
+		NULL,
 		dbox_mail_alloc,
 		index_header_lookup_init,
 		index_header_lookup_deinit,
--- a/src/lib-storage/index/index-storage.c	Mon Dec 06 00:52:42 2010 +0000
+++ b/src/lib-storage/index/index-storage.c	Mon Dec 06 01:11:07 2010 +0000
@@ -482,7 +482,7 @@
 	if (box->backend_readonly) {
 		/* return read-only only if there are no private flags
 		   (that are stored in index files) */
-		if (box->private_flags_mask == 0)
+		if (mailbox_get_private_flags_mask(box) == 0)
 			return TRUE;
 	}
 	return FALSE;
--- a/src/lib-storage/index/maildir/maildir-storage.c	Mon Dec 06 00:52:42 2010 +0000
+++ b/src/lib-storage/index/maildir/maildir-storage.c	Mon Dec 06 01:11:07 2010 +0000
@@ -292,16 +292,11 @@
 static int maildir_mailbox_open_existing(struct mailbox *box)
 {
 	struct maildir_mailbox *mbox = (struct maildir_mailbox *)box;
-	const char *shared_path, *box_path = mailbox_get_path(box);
-	struct stat st;
+	const char *box_path = mailbox_get_path(box);
 
 	mbox->uidlist = maildir_uidlist_init(mbox);
 	mbox->keywords = maildir_keywords_init(mbox);
 
-	shared_path = t_strconcat(box_path, "/dovecot-shared", NULL);
-	if (stat(shared_path, &st) == 0)
-		box->private_flags_mask = MAIL_SEEN;
-
 	if ((box->flags & MAILBOX_FLAG_KEEP_LOCKED) != 0) {
 		if (maildir_uidlist_lock(mbox->uidlist) <= 0)
 			return -1;
@@ -578,6 +573,22 @@
 	return mailbox_uidvalidity_next(list, path);
 }
 
+static enum mail_flags maildir_get_private_flags_mask(struct mailbox *box)
+{
+	struct maildir_mailbox *mbox = (struct maildir_mailbox *)box;
+	const char *path;
+	struct stat st;
+
+	if (!mbox->private_flags_mask_set) {
+		path = t_strconcat(mailbox_get_path(box), "/dovecot-shared", NULL);
+		if (stat(path, &st) < 0)
+			mbox->_private_flags_mask = 0;
+		else
+			mbox->_private_flags_mask = MAIL_SEEN;
+	}
+	return mbox->_private_flags_mask;
+}
+
 struct mail_storage maildir_storage = {
 	.name = MAILDIR_STORAGE_NAME,
 	.class_flags = 0,
@@ -631,6 +642,7 @@
 		NULL,
 		NULL,
 		NULL,
+		maildir_get_private_flags_mask,
 		index_mail_alloc,
 		index_header_lookup_init,
 		index_header_lookup_deinit,
--- a/src/lib-storage/index/maildir/maildir-storage.h	Mon Dec 06 00:52:42 2010 +0000
+++ b/src/lib-storage/index/maildir/maildir-storage.h	Mon Dec 06 01:11:07 2010 +0000
@@ -78,6 +78,9 @@
 
 	struct timeout *keep_lock_to;
 
+	/* Filled lazily by mailbox_get_private_flags_mask() */
+	enum mail_flags _private_flags_mask;
+
 	/* maildir sync: */
 	struct maildir_uidlist *uidlist;
 	struct maildir_keywords *keywords;
@@ -87,6 +90,7 @@
 
 	unsigned int synced:1;
 	unsigned int syncing_commit:1;
+	unsigned int private_flags_mask_set:1;
 };
 
 extern struct mail_vfuncs maildir_mail_vfuncs;
--- a/src/lib-storage/index/maildir/maildir-sync-index.c	Mon Dec 06 00:52:42 2010 +0000
+++ b/src/lib-storage/index/maildir/maildir-sync-index.c	Mon Dec 06 01:11:07 2010 +0000
@@ -467,6 +467,7 @@
 	int ret = 0;
 	time_t time_before_sync;
 	uint8_t expunged_guid_128[MAIL_GUID_128_SIZE];
+	enum mail_flags private_flags_mask;
 	bool expunged, full_rescan = FALSE;
 
 	i_assert(!mbox->syncing_commit);
@@ -492,6 +493,7 @@
 	}
 	hdr_next_uid = hdr->next_uid;
 
+	private_flags_mask = mailbox_get_private_flags_mask(&mbox->box);
 	time_before_sync = time(NULL);
 	mbox->syncing_commit = TRUE;
 	seq = prev_uid = 0; first_recent_uid = I_MAX(hdr->first_recent_uid, 1);
@@ -507,7 +509,7 @@
 
 		/* the private flags are kept only in indexes. don't use them
 		   at all even for newly seen mails */
-		ctx->flags &= ~mbox->box.private_flags_mask;
+		ctx->flags &= ~private_flags_mask;
 
 	again:
 		seq++;
@@ -582,7 +584,7 @@
 		}
 
 		/* the private flags are stored only in indexes, keep them */
-		ctx->flags |= rec->flags & mbox->box.private_flags_mask;
+		ctx->flags |= rec->flags & private_flags_mask;
 
 		if (index_sync_changes_have(ctx->sync_changes)) {
 			/* apply flag changes to maildir */
--- a/src/lib-storage/index/mbox/mbox-storage.c	Mon Dec 06 00:52:42 2010 +0000
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Mon Dec 06 01:11:07 2010 +0000
@@ -750,6 +750,7 @@
 		NULL,
 		NULL,
 		NULL,
+		NULL,
 		index_mail_alloc,
 		index_header_lookup_init,
 		index_header_lookup_deinit,
--- a/src/lib-storage/index/raw/raw-storage.c	Mon Dec 06 00:52:42 2010 +0000
+++ b/src/lib-storage/index/raw/raw-storage.c	Mon Dec 06 01:11:07 2010 +0000
@@ -167,6 +167,7 @@
 		NULL,
 		NULL,
 		NULL,
+		NULL,
 		index_mail_alloc,
 		index_header_lookup_init,
 		index_header_lookup_deinit,
--- a/src/lib-storage/mail-storage-private.h	Mon Dec 06 00:52:42 2010 +0000
+++ b/src/lib-storage/mail-storage-private.h	Mon Dec 06 01:11:07 2010 +0000
@@ -184,6 +184,7 @@
 	void (*get_virtual_box_patterns)(struct mailbox *box,
 				ARRAY_TYPE(mailbox_virtual_patterns) *includes,
 				ARRAY_TYPE(mailbox_virtual_patterns) *excludes);
+	enum mail_flags (*get_private_flags_mask)(struct mailbox *box);
 
 	struct mail *
 		(*mail_alloc)(struct mailbox_transaction_context *t,
@@ -263,9 +264,6 @@
 	unsigned int transaction_count;
 	enum mailbox_feature enabled_features;
 
-	/* User's private flags if this is a shared mailbox */
-	enum mail_flags private_flags_mask;
-
 	/* Mailbox notification settings: */
 	unsigned int notify_min_interval;
 	mailbox_notify_callback_t *notify_callback;
--- a/src/lib-storage/mail-storage.c	Mon Dec 06 00:52:42 2010 +0000
+++ b/src/lib-storage/mail-storage.c	Mon Dec 06 01:11:07 2010 +0000
@@ -930,6 +930,14 @@
 	return 0;
 }
 
+enum mail_flags mailbox_get_private_flags_mask(struct mailbox *box)
+{
+	if (box->v.get_private_flags_mask == NULL)
+		return 0;
+	else
+		return box->v.get_private_flags_mask(box);
+}
+
 struct mailbox_sync_context *
 mailbox_sync_init(struct mailbox *box, enum mailbox_sync_flags flags)
 {
--- a/src/lib-storage/mail-storage.h	Mon Dec 06 00:52:42 2010 +0000
+++ b/src/lib-storage/mail-storage.h	Mon Dec 06 01:11:07 2010 +0000
@@ -398,6 +398,9 @@
 			struct mailbox_status *status_r);
 /* Get mailbox GUID, creating it if necessary. */
 int mailbox_get_guid(struct mailbox *box, uint8_t guid[MAIL_GUID_128_SIZE]);
+/* Returns a mask of flags that are private to user in this mailbox
+   (as opposed to flags shared between users). */
+enum mail_flags mailbox_get_private_flags_mask(struct mailbox *box);
 
 /* Synchronize the mailbox. */
 struct mailbox_sync_context *
--- a/src/lib-storage/test-mailbox.c	Mon Dec 06 00:52:42 2010 +0000
+++ b/src/lib-storage/test-mailbox.c	Mon Dec 06 01:11:07 2010 +0000
@@ -351,6 +351,7 @@
 		NULL,
 		NULL,
 		NULL,
+		NULL,
 		test_mailbox_mail_alloc,
 		test_mailbox_header_lookup_init,
 		test_mailbox_header_lookup_deinit,
--- a/src/plugins/acl/acl-mailbox.c	Mon Dec 06 00:52:42 2010 +0000
+++ b/src/plugins/acl/acl-mailbox.c	Mon Dec 06 01:11:07 2010 +0000
@@ -64,6 +64,7 @@
 {
 	struct acl_mailbox *abox = ACL_CONTEXT(box);
 	enum acl_storage_rights save_right;
+	enum mail_flags private_flags_mask;
 
 	if (abox->module_ctx.super.is_readonly(box))
 		return TRUE;
@@ -78,10 +79,12 @@
 	/* Next up is the "shared flag rights" */
 	if (acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE) > 0)
 		return FALSE;
-	if ((box->private_flags_mask & MAIL_DELETED) == 0 &&
+
+	private_flags_mask = mailbox_get_private_flags_mask(box);
+	if ((private_flags_mask & MAIL_DELETED) == 0 &&
 	    acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE_DELETED) > 0)
 		return FALSE;
-	if ((box->private_flags_mask & MAIL_SEEN) == 0 &&
+	if ((private_flags_mask & MAIL_SEEN) == 0 &&
 	    acl_mailbox_right_lookup(box, ACL_STORAGE_RIGHT_WRITE_SEEN) > 0)
 		return FALSE;
 
--- a/src/plugins/virtual/virtual-storage.c	Mon Dec 06 00:52:42 2010 +0000
+++ b/src/plugins/virtual/virtual-storage.c	Mon Dec 06 01:11:07 2010 +0000
@@ -538,6 +538,7 @@
 		virtual_get_virtual_uid,
 		virtual_get_virtual_backend_boxes,
 		virtual_get_virtual_box_patterns,
+		NULL,
 		virtual_mail_alloc,
 		index_header_lookup_init,
 		index_header_lookup_deinit,