]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Add mail_cache_open_or_create_path()
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sat, 18 Nov 2017 16:03:55 +0000 (18:03 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 20 Nov 2017 11:09:07 +0000 (13:09 +0200)
This allows moving cache file to another directory.

src/lib-index/mail-cache.c
src/lib-index/mail-cache.h

index 9468bc3df93f9bcb089f3752861ada5790347cf2..ad0a3c8bc49a6b23b7f2f06d7385f94f4c28e1ec 100644 (file)
@@ -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)
index 2d9f4cad6bfb46a6f1fe465bb43edd3d1de31c9e..e41acff4e17b50aedeb7fa8162c7067ed1f9da0c 100644 (file)
@@ -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.