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 */
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) {
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)
{
if (index->inconsistent)
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
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);