Mercurial > dovecot > original-hg > dovecot-1.2
changeset 3129:1ea614abead3 HEAD
Don't complain about cache indexid changing when recreating index.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 31 Jan 2005 20:03:43 +0200 |
parents | ff8cb5728395 |
children | d14b7e7943c3 |
files | src/lib-index/mail-cache.c src/lib-index/mail-cache.h src/lib-index/mail-index.c |
diffstat | 3 files changed, 33 insertions(+), 16 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-index/mail-cache.c Sun Jan 30 15:03:06 2005 +0200 +++ b/src/lib-index/mail-cache.c Mon Jan 31 20:03:43 2005 +0200 @@ -222,12 +222,6 @@ static int mail_cache_open_and_verify(struct mail_cache *cache) { - cache->filepath = i_strconcat(cache->index->filepath, - MAIL_CACHE_FILE_PREFIX, NULL); - - if (cache->index->mmap_disable || cache->index->mmap_no_write) - cache->file_cache = file_cache_new(-1); - cache->fd = open(cache->filepath, O_RDWR); if (cache->fd == -1) { if (errno == ENOENT) { @@ -248,13 +242,15 @@ return mail_cache_header_fields_read(cache); } -struct mail_cache *mail_cache_open_or_create(struct mail_index *index) +static struct mail_cache *mail_cache_alloc(struct mail_index *index) { struct mail_cache *cache; cache = i_new(struct mail_cache, 1); cache->index = index; cache->fd = -1; + cache->filepath = + i_strconcat(index->filepath, MAIL_CACHE_FILE_PREFIX, NULL); cache->field_pool = pool_alloconly_create("Cache fields", 1024); cache->field_name_hash = hash_create(default_pool, cache->field_pool, 0, @@ -265,11 +261,8 @@ cache->dotlock_settings.immediate_stale_timeout = MAIL_CACHE_LOCK_IMMEDIATE_TIMEOUT; - if (mail_cache_open_and_verify(cache) < 0) { - /* failed for some reason - doesn't really matter, - it's disabled for now. */ - mail_cache_file_close(cache); - } + if (index->mmap_disable || index->mmap_no_write) + cache->file_cache = file_cache_new(-1); cache->ext_id = mail_index_ext_register(index, "cache", 0, @@ -281,6 +274,7 @@ MAIL_INDEX_SYNC_HANDLER_INDEX | (cache->file_cache == NULL ? 0 : MAIL_INDEX_SYNC_HANDLER_VIEW)); + if (cache->file_cache != NULL) { mail_index_register_sync_lost_handler(index, mail_cache_sync_lost_handler); @@ -288,6 +282,28 @@ return cache; } +struct mail_cache *mail_cache_open_or_create(struct mail_index *index) +{ + struct mail_cache *cache; + + cache = mail_cache_alloc(index); + if (mail_cache_open_and_verify(cache) < 0) { + /* failed for some reason - doesn't really matter, + it's disabled for now. */ + mail_cache_file_close(cache); + } + return cache; +} + +struct mail_cache *mail_cache_create(struct mail_index *index) +{ + struct mail_cache *cache; + + cache = mail_cache_alloc(index); + cache->need_compress = TRUE; + return cache; +} + void mail_cache_free(struct mail_cache *cache) { if (cache->file_cache != NULL) {
--- a/src/lib-index/mail-cache.h Sun Jan 30 15:03:06 2005 +0200 +++ b/src/lib-index/mail-cache.h Mon Jan 31 20:03:43 2005 +0200 @@ -39,6 +39,7 @@ }; struct mail_cache *mail_cache_open_or_create(struct mail_index *index); +struct mail_cache *mail_cache_create(struct mail_index *index); void mail_cache_free(struct mail_cache *cache); /* Register fields. fields[].idx is updated to contain field index. */
--- a/src/lib-index/mail-index.c Sun Jan 30 15:03:06 2005 +0200 +++ b/src/lib-index/mail-index.c Mon Jan 31 20:03:43 2005 +0200 @@ -1189,7 +1189,7 @@ { struct mail_index_header hdr; unsigned int lock_id = 0; - int ret; + int ret, created = FALSE; ret = mail_index_try_open(index, &lock_id); if (ret > 0) @@ -1216,6 +1216,7 @@ } if (mail_index_create(index, &hdr) < 0) return -1; + created = TRUE; } if (lock_id == 0) { @@ -1224,9 +1225,8 @@ } - index->cache = mail_cache_open_or_create(index); - if (index->cache == NULL) - return -1; + index->cache = created ? mail_cache_create(index) : + mail_cache_open_or_create(index); mail_index_unlock(index, lock_id); return 1;