[dovecot-cvs] dovecot/src/lib-storage/index/cydir cydir-storage.c, 1.12, 1.13 cydir-sync.c, 1.2, 1.3 cydir-sync.h, 1.1, 1.2

tss at dovecot.org tss at dovecot.org
Tue Apr 17 15:41:29 EEST 2007


Update of /var/lib/cvs/dovecot/src/lib-storage/index/cydir
In directory talvi:/tmp/cvs-serv21471/index/cydir

Modified Files:
	cydir-storage.c cydir-sync.c cydir-sync.h 
Log Message:
Added sync_notify() callback to struct mail_storage. It's now called for
expunges and flag/keyword changes (except with cydir).



Index: cydir-storage.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/cydir/cydir-storage.c,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -d -r1.12 -r1.13
--- cydir-storage.c	11 Apr 2007 10:55:35 -0000	1.12
+++ cydir-storage.c	17 Apr 2007 12:41:27 -0000	1.13
@@ -453,6 +453,7 @@
 		cydir_storage_sync_init,
 		index_mailbox_sync_next,
 		index_mailbox_sync_deinit,
+		NULL,
 		cydir_notify_changes,
 		index_transaction_begin,
 		index_transaction_commit,

Index: cydir-sync.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/cydir/cydir-sync.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -d -r1.2 -r1.3
--- cydir-sync.c	30 Mar 2007 12:44:02 -0000	1.2
+++ cydir-sync.c	17 Apr 2007 12:41:27 -0000	1.3
@@ -27,7 +27,7 @@
 
 static string_t *cydir_get_path_prefix(struct cydir_mailbox *mbox)
 {
-	string_t *path = t_str_new(256);
+	string_t *path = str_new(default_pool, 256);
 	const char *dir;
 
 	dir = mailbox_list_get_path(mbox->storage->storage.list,
@@ -38,13 +38,44 @@
 	return path;
 }
 
+static int
+cydir_sync_expunge(struct cydir_sync_context *ctx, uint32_t seq1, uint32_t seq2)
+{
+	struct mailbox *box = &ctx->mbox->ibox.box;
+	uint32_t uid;
+
+	if (ctx->path == NULL) {
+		ctx->path = cydir_get_path_prefix(ctx->mbox);
+		ctx->path_dir_prefix_len = str_len(ctx->path);
+	}
+
+	for (; seq1 <= seq2; seq1++) {
+		if (mail_index_lookup_uid(ctx->sync_view, seq1, &uid) < 0) {
+			mail_storage_set_index_error(&ctx->mbox->ibox);
+			return -1;
+		}
+
+		str_truncate(ctx->path, ctx->path_dir_prefix_len);
+		str_printfa(ctx->path, "%u.", uid);
+		if (unlink(str_c(ctx->path)) == 0) {
+			if (box->v.sync_notify != NULL) {
+				box->v.sync_notify(box, uid,
+						   MAILBOX_SYNC_TYPE_EXPUNGE);
+			}
+		} else if (errno != ENOENT) {
+			mail_storage_set_critical(&ctx->mbox->storage->storage,
+				"unlink(%s) failed: %m", str_c(ctx->path));
+			/* continue anyway */
+		}
+	}
+	return 0;
+}
+
 static int cydir_sync_index(struct cydir_sync_context *ctx)
 {
 	const struct mail_index_header *hdr;
 	struct mail_index_sync_rec sync_rec;
-	string_t *path = NULL;
-	unsigned int prefix_len = 0;
-	uint32_t seq1, seq2, uid;
+	uint32_t seq1, seq2;
 	int ret;
 
 	hdr = mail_index_get_header(ctx->sync_view);
@@ -53,12 +84,8 @@
 			return -1;
 	}
 
-	/* unlink expunged messages */
 	while ((ret = mail_index_sync_next(ctx->index_sync_ctx,
 					   &sync_rec)) > 0) {
-		if (sync_rec.type != MAIL_INDEX_SYNC_TYPE_EXPUNGE)
-			continue;
-
 		if (mail_index_lookup_uid_range(ctx->sync_view,
 						sync_rec.uid1, sync_rec.uid2,
 						&seq1, &seq2) < 0) {
@@ -66,30 +93,24 @@
 			return -1;
 		}
 		if (seq1 == 0) {
-			/* already expunged everything. nothing to do. */
+			/* already expunged, nothing to do. */
 			continue;
 		}
 
-		if (path == NULL) {
-			path = cydir_get_path_prefix(ctx->mbox);
-			prefix_len = str_len(path);
-		}
-
-		for (; seq1 <= seq2; seq1++) {
-			if (mail_index_lookup_uid(ctx->sync_view, seq1,
-						  &uid) < 0) {
-				mail_storage_set_index_error(&ctx->mbox->ibox);
+		switch (sync_rec.type) {
+		case MAIL_INDEX_SYNC_TYPE_APPEND:
+			/* don't care */
+			break;
+		case MAIL_INDEX_SYNC_TYPE_EXPUNGE:
+			if (cydir_sync_expunge(ctx, seq1, seq2) < 0)
 				return -1;
-			}
-
-			str_truncate(path, prefix_len);
-			str_printfa(path, "%u.", uid);
-			if (unlink(str_c(path)) < 0 && errno != ENOENT) {
-				mail_storage_set_critical(
-					&ctx->mbox->storage->storage,
-					"unlink(%s) failed: %m", str_c(path));
-				/* continue anyway */
-			}
+			break;
+		case MAIL_INDEX_SYNC_TYPE_FLAGS:
+		case MAIL_INDEX_SYNC_TYPE_KEYWORD_ADD:
+		case MAIL_INDEX_SYNC_TYPE_KEYWORD_REMOVE:
+		case MAIL_INDEX_SYNC_TYPE_KEYWORD_RESET:
+			/* FIXME: should be bother calling sync_notify()? */
+			break;
 		}
 	}
 	return 0;
@@ -137,6 +158,8 @@
 	} else {
 		mail_index_sync_rollback(&ctx->index_sync_ctx);
 	}
+	if (ctx->path != NULL)
+		str_free(&ctx->path);
 	i_free(ctx);
 	return 0;
 }

Index: cydir-sync.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-storage/index/cydir/cydir-sync.h,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -d -r1.1 -r1.2
--- cydir-sync.h	30 Mar 2007 12:09:00 -0000	1.1
+++ cydir-sync.h	17 Apr 2007 12:41:27 -0000	1.2
@@ -8,6 +8,9 @@
 	struct cydir_mailbox *mbox;
         struct mail_index_sync_ctx *index_sync_ctx;
 	struct mail_index_view *sync_view;
+
+	string_t *path;
+	unsigned int path_dir_prefix_len;
 };
 
 int cydir_sync_begin(struct cydir_mailbox *mbox,



More information about the dovecot-cvs mailing list