Mercurial > dovecot > original-hg > dovecot-1.2
changeset 1276:3607a2b4f011 HEAD
Added index->append_abort() to abort append cleanly.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Wed, 05 Mar 2003 03:41:36 +0200 |
parents | af685269ead0 |
children | c5c17b45cceb |
files | src/lib-index/mail-index.c src/lib-index/mail-index.h src/lib-index/maildir/maildir-build.c src/lib-index/maildir/maildir-index.c src/lib-index/mbox/mbox-append.c src/lib-index/mbox/mbox-index.c |
diffstat | 6 files changed, 59 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-index.c Wed Mar 05 00:38:07 2003 +0200 +++ b/src/lib-index/mail-index.c Wed Mar 05 03:41:36 2003 +0200 @@ -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; + struct mail_index_header *hdr = index->header; + unsigned int 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; - - /* 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) { @@ -1012,6 +1020,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) { if (index->inconsistent)
--- a/src/lib-index/mail-index.h Wed Mar 05 00:38:07 2003 +0200 +++ b/src/lib-index/mail-index.h Wed Mar 05 03:41:36 2003 +0200 @@ -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);
--- a/src/lib-index/maildir/maildir-build.c Wed Mar 05 00:38:07 2003 +0200 +++ b/src/lib-index/maildir/maildir-build.c Wed Mar 05 03:41:36 2003 +0200 @@ -66,8 +66,10 @@ /* parse the header and update record's fields */ failed = fd == -1 ? FALSE : !maildir_record_update(index, update, fd); - if (!index->update_end(update) || failed) + if (!index->update_end(update) || failed) { + index->append_abort(index, rec); return FALSE; + } return index->append_end(index, rec); }
--- a/src/lib-index/maildir/maildir-index.c Wed Mar 05 00:38:07 2003 +0200 +++ b/src/lib-index/maildir/maildir-index.c Wed Mar 05 03:41:36 2003 +0200 @@ -263,6 +263,7 @@ maildir_index_update_flags, mail_index_append_begin, mail_index_append_end, + mail_index_append_abort, mail_index_update_begin, mail_index_update_end, mail_index_update_field,
--- a/src/lib-index/mbox/mbox-append.c Wed Mar 05 00:38:07 2003 +0200 +++ b/src/lib-index/mbox/mbox-append.c Wed Mar 05 03:41:36 2003 +0200 @@ -94,9 +94,10 @@ index->update_field_raw(update, DATA_FIELD_MD5, md5_digest, sizeof(md5_digest)); - if (!index->update_end(update)) + if (!index->update_end(update)) { + index->append_abort(index, rec); failed = TRUE; - else { + } else { /* save message flags */ rec->msg_flags = ctx.flags; mail_index_mark_flag_changes(index, rec, 0, rec->msg_flags);
--- a/src/lib-index/mbox/mbox-index.c Wed Mar 05 00:38:07 2003 +0200 +++ b/src/lib-index/mbox/mbox-index.c Wed Mar 05 03:41:36 2003 +0200 @@ -821,6 +821,7 @@ mbox_index_update_flags, mail_index_append_begin, mail_index_append_end, + mail_index_append_abort, mail_index_update_begin, mail_index_update_end, mail_index_update_field,