# HG changeset patch # User Timo Sirainen # Date 1140219398 -7200 # Node ID 20c335412d7d44581ccd479b286dfe5c9fd6b840 # Parent d4c02d132a32e5602500c28b7f5a2ca7b43d6855 Added some locking related asserts, comments and when replacing index file, open it immediately into memory (seemed to work before too, though). diff -r d4c02d132a32 -r 20c335412d7d src/lib-index/mail-index-lock.c --- a/src/lib-index/mail-index-lock.c Fri Feb 17 16:20:08 2006 +0200 +++ b/src/lib-index/mail-index-lock.c Sat Feb 18 01:36:38 2006 +0200 @@ -153,10 +153,12 @@ } if (update_index && index->excl_lock_count == 0) { + /* we wish to have the latest available index file. */ i_assert(index->lock_type != F_WRLCK); if ((ret2 = mail_index_reopen_if_needed(index)) < 0) return -1; if (ret > 0 && ret2 == 0) { + /* no new file and the old file is already locked */ i_assert(lock_type == F_RDLCK); i_assert(index->lock_type == F_RDLCK); return 1; @@ -164,8 +166,10 @@ ret = 0; } - if (ret > 0) + if (ret > 0) { + /* file is already locked */ return 1; + } if (index->lock_method == MAIL_INDEX_LOCK_DOTLOCK && !MAIL_INDEX_IS_IN_MEMORY(index)) { @@ -299,7 +303,6 @@ old_lock_type = index->lock_type; index->lock_type = F_WRLCK; - index->excl_lock_count++; if (mail_index_reopen(index, fd) < 0) { i_assert(index->excl_lock_count == 1); @@ -317,6 +320,7 @@ return -1; } + index->excl_lock_count++; return 0; } @@ -419,10 +423,11 @@ if (!MAIL_INDEX_IS_IN_MEMORY(index)) { fd = mail_index_copy(index); - if (fd == -1) + if (fd == -1 || mail_index_reopen(index, fd) < 0) { + if (fd != -1) + (void)close(fd); mail_index_set_inconsistent(index); - else - (void)close(fd); + } } } else { /* write the modified parts. header is small enough to be diff -r d4c02d132a32 -r 20c335412d7d src/lib-index/mail-index-sync-update.c --- a/src/lib-index/mail-index-sync-update.c Fri Feb 17 16:20:08 2006 +0200 +++ b/src/lib-index/mail-index-sync-update.c Sat Feb 18 01:36:38 2006 +0200 @@ -31,6 +31,8 @@ map->write_to_disk = TRUE; map->write_atomic = TRUE; } + + i_assert(view->hdr.messages_count == map->hdr.messages_count); } static void @@ -548,6 +550,8 @@ i_assert(ctx->view->map->records_count == ctx->view->map->hdr.messages_count); + i_assert(ctx->view->hdr.messages_count == + ctx->view->map->hdr.messages_count); return ret; } @@ -629,6 +633,8 @@ view->map = map; view->map->refcount++; + i_assert(view->hdr.messages_count == map->hdr.messages_count); + had_dirty = (map->hdr.flags & MAIL_INDEX_HDR_FLAG_HAVE_DIRTY) != 0; if (had_dirty) map->hdr.flags &= ~MAIL_INDEX_HDR_FLAG_HAVE_DIRTY; diff -r d4c02d132a32 -r 20c335412d7d src/lib-index/mail-index.c --- a/src/lib-index/mail-index.c Fri Feb 17 16:20:08 2006 +0200 +++ b/src/lib-index/mail-index.c Sat Feb 18 01:36:38 2006 +0200 @@ -1576,6 +1576,7 @@ int ret, old_fd, old_lock_type; i_assert(!MAIL_INDEX_IS_IN_MEMORY(index)); + i_assert(index->copy_lock_path == NULL || index->excl_lock_count == 0); old_map = index->map; old_fd = index->fd; @@ -1643,6 +1644,8 @@ { struct stat st1, st2; + i_assert(index->copy_lock_path == NULL); + if (MAIL_INDEX_IS_IN_MEMORY(index)) return 0;