# HG changeset patch # User Timo Sirainen # Date 1031620663 -10800 # Node ID 9f78db959fdc687a6f2c85f782c3f0ef5de08e9a # Parent 0bb7bf7266abcc7a1e7b46996775e51cdbe9529a Broke saving new mail diff -r 0bb7bf7266ab -r 9f78db959fdc src/lib-index/mail-index.c --- a/src/lib-index/mail-index.c Tue Sep 10 01:49:34 2002 +0300 +++ b/src/lib-index/mail-index.c Tue Sep 10 04:17:43 2002 +0300 @@ -1381,8 +1381,7 @@ rec->uid, external_change); } -int mail_index_append(MailIndex *index, MailIndexRecord **rec, - unsigned int *uid) +int mail_index_append_begin(MailIndex *index, MailIndexRecord **rec) { off_t pos; @@ -1405,9 +1404,6 @@ index->header->messages_count++; mail_index_mark_flag_changes(index, *rec, 0, (*rec)->msg_flags); - if (index->hash != NULL) - mail_hash_update(index->hash, (*rec)->uid, (uoff_t)pos); - /* file size changed, let others know about it too by changing sync_id in header. */ index->header->sync_id++; @@ -1423,7 +1419,25 @@ return FALSE; *rec = (MailIndexRecord *) ((char *) index->mmap_base + pos); - *uid = index->header->next_uid++; + return TRUE; +} + +int mail_index_append_end(MailIndex *index, MailIndexRecord *rec) +{ + /* make sure everything is written before setting it's UID + to mark it as non-deleted. */ + if (!mail_index_data_sync_file(index->data)) + return FALSE; + if (!mail_index_fmsync(index, index->mmap_length)) + return FALSE; + + rec->uid = index->header->next_uid++; + + if (index->hash != NULL) { + mail_hash_update(index->hash, rec->uid, + INDEX_FILE_POSITION(index, rec)); + } + return TRUE; } diff -r 0bb7bf7266ab -r 9f78db959fdc src/lib-index/mail-index.h --- a/src/lib-index/mail-index.h Tue Sep 10 01:49:34 2002 +0300 +++ b/src/lib-index/mail-index.h Tue Sep 10 04:17:43 2002 +0300 @@ -259,10 +259,10 @@ /* Append a new record to index. The index must be exclusively locked before calling this function. The record pointer is - updated to the mmap()ed record. *uid is set to the UID which - should be set to rec->uid once the update is fully done. */ - int (*append)(MailIndex *index, MailIndexRecord **rec, - unsigned int *uid); + updated to the mmap()ed record. rec->uid is updated in + append_end(). */ + int (*append_begin)(MailIndex *index, MailIndexRecord **rec); + int (*append_end)(MailIndex *index, MailIndexRecord *rec); /* Updating fields happens by calling update_begin(), one or more update_field()s and finally update_end() which does the actual @@ -367,8 +367,8 @@ int mail_index_update_flags(MailIndex *index, MailIndexRecord *rec, unsigned int seq, MailFlags flags, int external_change); -int mail_index_append(MailIndex *index, MailIndexRecord **rec, - unsigned int *uid); +int mail_index_append_begin(MailIndex *index, MailIndexRecord **rec); +int mail_index_append_end(MailIndex *index, MailIndexRecord *rec); MailIndexUpdate *mail_index_update_begin(MailIndex *index, MailIndexRecord *rec); int mail_index_update_end(MailIndexUpdate *update); diff -r 0bb7bf7266ab -r 9f78db959fdc src/lib-index/maildir/maildir-build.c --- a/src/lib-index/maildir/maildir-build.c Tue Sep 10 01:49:34 2002 +0300 +++ b/src/lib-index/maildir/maildir-build.c Tue Sep 10 04:17:43 2002 +0300 @@ -11,9 +11,8 @@ #include #include -static MailIndexRecord * -mail_index_record_append(MailIndex *index, time_t internal_date, - unsigned int *uid) +static MailIndexRecord *mail_index_record_append_begin(MailIndex *index, + time_t internal_date) { MailIndexRecord trec, *rec; @@ -21,7 +20,7 @@ trec.internal_date = internal_date; rec = &trec; - if (!index->append(index, &rec, uid)) + if (!index->append_begin(index, &rec)) return NULL; return rec; @@ -33,7 +32,6 @@ MailIndexRecord *rec; MailIndexUpdate *update; struct stat st; - unsigned int uid; int failed; i_assert(path != NULL); @@ -57,7 +55,7 @@ return FALSE; /* append the file into index */ - rec = mail_index_record_append(index, st.st_mtime, &uid); + rec = mail_index_record_append_begin(index, st.st_mtime); if (rec == NULL) return FALSE; @@ -77,13 +75,7 @@ if (!index->update_end(update) || failed) return FALSE; - /* make sure everything is written before setting it's UID - to mark it as non-deleted. */ - if (!mail_index_fmsync(index, index->mmap_length)) - return FALSE; - rec->uid = uid; - - return TRUE; + return index->append_end(index, rec); } int maildir_index_append_file(MailIndex *index, const char *dir, diff -r 0bb7bf7266ab -r 9f78db959fdc src/lib-index/maildir/maildir-index.c --- a/src/lib-index/maildir/maildir-index.c Tue Sep 10 01:49:34 2002 +0300 +++ b/src/lib-index/maildir/maildir-index.c Tue Sep 10 04:17:43 2002 +0300 @@ -217,7 +217,8 @@ maildir_open_mail, mail_index_expunge, maildir_index_update_flags, - mail_index_append, + mail_index_append_begin, + mail_index_append_end, mail_index_update_begin, mail_index_update_end, mail_index_update_field, diff -r 0bb7bf7266ab -r 9f78db959fdc src/lib-index/mbox/mbox-append.c --- a/src/lib-index/mbox/mbox-append.c Tue Sep 10 01:49:34 2002 +0300 +++ b/src/lib-index/mbox/mbox-append.c Tue Sep 10 04:17:43 2002 +0300 @@ -8,9 +8,8 @@ #include "mbox-index.h" #include "mail-index-util.h" -static MailIndexRecord *mail_index_record_append(MailIndex *index, - time_t internal_date, - unsigned int *uid) +static MailIndexRecord *mail_index_record_append_begin(MailIndex *index, + time_t internal_date) { MailIndexRecord trec, *rec; @@ -18,7 +17,7 @@ trec.internal_date = internal_date; rec = &trec; - if (!index->append(index, &rec, uid)) + if (!index->append_begin(index, &rec)) return NULL; return rec; @@ -84,7 +83,6 @@ time_t internal_date; uoff_t abs_start_offset, stop_offset, old_size; unsigned char *data, md5_digest[16]; - unsigned int uid; size_t size, pos; int failed; @@ -123,7 +121,7 @@ stop_offset = inbuf->offset; /* add message to index */ - rec = mail_index_record_append(index, internal_date, &uid); + rec = mail_index_record_append_begin(index, internal_date); if (rec == NULL) return FALSE; @@ -161,11 +159,8 @@ mail_index_mark_flag_changes(index, rec, 0, rec->msg_flags); failed = FALSE; - /* make sure everything is written before setting it's UID - to mark it as non-deleted. */ - if (!mail_index_fmsync(index, index->mmap_length)) - return FALSE; - rec->uid = uid; + if (!index->append_end(index, rec)) + failed = TRUE; } mbox_header_free_context(&ctx); diff -r 0bb7bf7266ab -r 9f78db959fdc src/lib-index/mbox/mbox-index.c --- a/src/lib-index/mbox/mbox-index.c Tue Sep 10 01:49:34 2002 +0300 +++ b/src/lib-index/mbox/mbox-index.c Tue Sep 10 04:17:43 2002 +0300 @@ -377,7 +377,8 @@ mbox_open_mail, mail_index_expunge, mbox_index_update_flags, - mail_index_append, + mail_index_append_begin, + mail_index_append_end, mail_index_update_begin, mail_index_update_end, mail_index_update_field,