From: Timo Sirainen Date: Sat, 18 Nov 2017 16:03:55 +0000 (+0200) Subject: lib-index: Add mail_cache_open_or_create_path() X-Git-Tag: 2.3.0.rc1~430 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=2608ab4495148a9362e75ec5c67dcbdec92dbae2;p=thirdparty%2Fdovecot%2Fcore.git lib-index: Add mail_cache_open_or_create_path() This allows moving cache file to another directory. --- diff --git a/src/lib-index/mail-cache.c b/src/lib-index/mail-cache.c index 9468bc3df9..ad0a3c8bc4 100644 --- a/src/lib-index/mail-cache.c +++ b/src/lib-index/mail-cache.c @@ -535,15 +535,15 @@ int mail_cache_open_and_verify(struct mail_cache *cache) return ret; } -static struct mail_cache *mail_cache_alloc(struct mail_index *index) +struct mail_cache * +mail_cache_open_or_create_path(struct mail_index *index, const char *path) { 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_SUFFIX, NULL); + cache->filepath = i_strdup(path); cache->field_pool = pool_alloconly_create("Cache fields", 2048); hash_table_create(&cache->field_name_hash, cache->field_pool, 0, strcase_hash, strcasecmp); @@ -572,10 +572,9 @@ static struct mail_cache *mail_cache_alloc(struct mail_index *index) struct mail_cache *mail_cache_open_or_create(struct mail_index *index) { - struct mail_cache *cache; - - cache = mail_cache_alloc(index); - return cache; + const char *path = t_strconcat(index->filepath, + MAIL_CACHE_FILE_SUFFIX, NULL); + return mail_cache_open_or_create_path(index, path); } void mail_cache_free(struct mail_cache **_cache) diff --git a/src/lib-index/mail-cache.h b/src/lib-index/mail-cache.h index 2d9f4cad6b..e41acff4e1 100644 --- a/src/lib-index/mail-cache.h +++ b/src/lib-index/mail-cache.h @@ -44,6 +44,8 @@ struct mail_cache_field { }; struct mail_cache *mail_cache_open_or_create(struct mail_index *index); +struct mail_cache * +mail_cache_open_or_create_path(struct mail_index *index, const char *path); void mail_cache_free(struct mail_cache **cache); /* Register fields. fields[].idx is updated to contain field index.