[dovecot-cvs] dovecot/src/lib-index mail-index.c,1.84,1.85 mail-index.h,1.68,1.69

cras at procontrol.fi cras at procontrol.fi
Wed Mar 5 03:41:39 EET 2003


Update of /home/cvs/dovecot/src/lib-index
In directory danu:/tmp/cvs-serv16213

Modified Files:
	mail-index.c mail-index.h 
Log Message:
Added index->append_abort() to abort append cleanly.



Index: mail-index.c
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.c,v
retrieving revision 1.84
retrieving revision 1.85
diff -u -d -r1.84 -r1.85
--- mail-index.c	23 Feb 2003 21:06:57 -0000	1.84
+++ mail-index.c	5 Mar 2003 01:41:36 -0000	1.85
@@ -817,31 +817,12 @@
 	return TRUE;
 }
 
-#define INDEX_NEED_COMPRESS(records, hdr) \
-	((records) > INDEX_MIN_RECORDS_COUNT && \
-	 (records) * (100-INDEX_COMPRESS_PERCENTAGE) / 100 > \
-	 	(hdr)->messages_count)
-
-int mail_index_expunge(struct mail_index *index, struct mail_index_record *rec,
-		       unsigned int seq, int external_change)
+static void update_first_hole(struct mail_index *index,
+			      struct mail_index_record *rec)
 {
-	struct mail_index_header *hdr;
-	unsigned int records, uid, idx;
-
-	i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
-	i_assert(seq != 0);
-	i_assert(rec->uid != 0);
-
-	if (!mail_index_verify_hole_range(index))
-		return FALSE;
-
-	hdr = index->header;
-
-	/* setting UID to 0 is enough for deleting the mail from index */
-	uid = rec->uid;
-	rec->uid = 0;
+	struct mail_index_header *hdr = index->header;
+	unsigned int idx;
 
-	/* update first hole */
 	idx = INDEX_RECORD_INDEX(index, rec);
 	if (hdr->first_hole_records == 0) {
 		/* first deleted message in index */
@@ -863,6 +844,33 @@
 			hdr->first_hole_records = 1;
 		}
 	}
+}
+
+#define INDEX_NEED_COMPRESS(records, hdr) \
+	((records) > INDEX_MIN_RECORDS_COUNT && \
+	 (records) * (100-INDEX_COMPRESS_PERCENTAGE) / 100 > \
+	 	(hdr)->messages_count)
+
+int mail_index_expunge(struct mail_index *index, struct mail_index_record *rec,
+		       unsigned int seq, int external_change)
+{
+	struct mail_index_header *hdr;
+	unsigned int records, uid;
+
+	i_assert(index->lock_type == MAIL_LOCK_EXCLUSIVE);
+	i_assert(seq != 0);
+	i_assert(rec->uid != 0);
+
+	if (!mail_index_verify_hole_range(index))
+		return FALSE;
+
+	hdr = index->header;
+
+	/* setting UID to 0 is enough for deleting the mail from index */
+	uid = rec->uid;
+	rec->uid = 0;
+
+	update_first_hole(index, rec);
 
 	/* update message counts */
 	if (hdr->messages_count == 0) {
@@ -1010,6 +1018,22 @@
 	}
 
 	return TRUE;
+}
+
+void mail_index_append_abort(struct mail_index *index,
+			     struct mail_index_record *rec)
+{
+	i_assert(rec->uid == 0);
+
+	if (INDEX_FILE_POSITION(index, rec) ==
+	    index->header->used_file_size - sizeof(*rec)) {
+		/* we can just rollback */
+		index->header->used_file_size -= sizeof(*rec);
+		index->mmap_used_length += sizeof(*rec);
+	} else {
+		/* mark it deleted */
+		update_first_hole(index, rec);
+	}
 }
 
 enum mail_index_error mail_index_get_last_error(struct mail_index *index)

Index: mail-index.h
===================================================================
RCS file: /home/cvs/dovecot/src/lib-index/mail-index.h,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -d -r1.68 -r1.69
--- mail-index.h	23 Feb 2003 21:06:57 -0000	1.68
+++ mail-index.h	5 Mar 2003 01:41:36 -0000	1.69
@@ -323,6 +323,8 @@
 	struct mail_index_record *(*append_begin)(struct mail_index *index);
 	int (*append_end)(struct mail_index *index,
 			  struct mail_index_record *rec);
+	void (*append_abort)(struct mail_index *index,
+			     struct mail_index_record *rec);
 
 	/* Updating fields happens by calling update_begin(), one or more
 	   update_field()s and finally update_end() which does the actual
@@ -473,6 +475,8 @@
 struct mail_index_record *mail_index_append_begin(struct mail_index *index);
 int mail_index_append_end(struct mail_index *index,
 			  struct mail_index_record *rec);
+void mail_index_append_abort(struct mail_index *index,
+			     struct mail_index_record *rec);
 struct mail_index_update *
 mail_index_update_begin(struct mail_index *index,
 			struct mail_index_record *rec);




More information about the dovecot-cvs mailing list