From: Timo Sirainen Date: Sat, 1 May 2004 18:30:35 +0000 (+0300) Subject: syncing fix X-Git-Tag: 1.1.alpha1~4160 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=19593623a2278039be23fc93e3404c012920b664;p=thirdparty%2Fdovecot%2Fcore.git syncing fix --HG-- branch : HEAD --- diff --git a/src/lib-index/mail-index.c b/src/lib-index/mail-index.c index a25e9d4059..ace197d38e 100644 --- a/src/lib-index/mail-index.c +++ b/src/lib-index/mail-index.c @@ -261,19 +261,25 @@ static int mail_index_read_map_with_retry(struct mail_index *index, int mail_index_map(struct mail_index *index, int force) { + const struct mail_index_header *hdr; struct mail_index_map *map; + size_t used_size; int ret; - if (index->map != NULL) { - map = index->map; - if (map != NULL && !force) + map = index->map; + if (map != NULL && MAIL_INDEX_MAP_IS_IN_MEMORY(map)) { + /* FIXME: we need to re-read header */ + } else if (map != NULL) { + /* see if re-mmaping is needed (file has grown) */ + hdr = map->mmap_base; + used_size = hdr->header_size + + hdr->messages_count * sizeof(struct mail_index_record); + if (map->mmap_size >= used_size && !force) return 1; - if (map->mmap_base != NULL) { - if (munmap(map->mmap_base, map->mmap_size) < 0) - mail_index_set_syscall_error(index, "munmap()"); - map->mmap_base = NULL; - } + if (munmap(map->mmap_base, map->mmap_size) < 0) + mail_index_set_syscall_error(index, "munmap()"); + map->mmap_base = NULL; } else { map = i_new(struct mail_index_map, 1); map->refcount = 1;