[dovecot-cvs] dovecot/src/lib-index mail-index-transaction-private.h, 1.25, 1.26 mail-index-transaction.c, 1.68, 1.69

cras at dovecot.org cras at dovecot.org
Wed Dec 21 20:41:53 EET 2005


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv30803

Modified Files:
	mail-index-transaction-private.h mail-index-transaction.c 
Log Message:
Allow appending mails in wrong UID order. Sort them internally when
committing.



Index: mail-index-transaction-private.h
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-transaction-private.h,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -d -r1.25 -r1.26
--- mail-index-transaction-private.h	23 Apr 2005 15:18:21 -0000	1.25
+++ mail-index-transaction-private.h	21 Dec 2005 18:41:50 -0000	1.26
@@ -36,6 +36,7 @@
 
 	unsigned int hide_transaction:1;
 	unsigned int no_appends:1;
+	unsigned int appends_nonsorted:1;
 	unsigned int external:1;
 	unsigned int pre_hdr_changed:1;
 	unsigned int post_hdr_changed:1;

Index: mail-index-transaction.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-index-transaction.c,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -d -r1.68 -r1.69
--- mail-index-transaction.c	2 Dec 2005 11:30:45 -0000	1.68
+++ mail-index-transaction.c	21 Dec 2005 18:41:50 -0000	1.69
@@ -186,6 +186,14 @@
 	return 0;
 }
 
+static int mail_index_append_rec_cmp(const void *p1, const void *p2)
+{
+	const struct mail_index_record *rec1 = p1, *rec2 = p2;
+
+	return rec1->uid < rec2->uid ? -1 :
+		rec1->uid > rec2->uid ? 1 : 0;
+}
+
 int mail_index_transaction_commit(struct mail_index_transaction *t,
 				  uint32_t *log_file_seq_r,
 				  uoff_t *log_file_offset_r)
@@ -202,6 +210,14 @@
                 t->cache_trans_ctx = NULL;
 	}
 
+	if (t->appends_nonsorted) {
+		struct mail_index_record *recs;
+		unsigned int count;
+
+		recs = array_get_modifyable(&t->appends, &count);
+		qsort(recs, count, sizeof(*recs), mail_index_append_rec_cmp);
+	}
+
 	if (mail_index_transaction_convert_to_uids(t) < 0)
 		ret = -1;
 	else {
@@ -252,7 +268,17 @@
 		*seq_r = t->last_new_seq = t->first_new_seq;
 
 	rec = array_append_space(&t->appends);
-	rec->uid = uid;
+	if (uid != 0) {
+		rec->uid = uid;
+		if (!t->appends_nonsorted &&
+		    t->last_new_seq != t->first_new_seq) {
+			/* if previous record's UID is larger than this one,
+			   we'll have to sort the appends later */
+			rec = mail_index_transaction_lookup(t, *seq_r - 1);
+			if (rec->uid > uid)
+				t->appends_nonsorted = TRUE;
+		}
+	}
 }
 
 void mail_index_append_assign_uids(struct mail_index_transaction *t,



More information about the dovecot-cvs mailing list