]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
lib-index: Add mail_index_set_cache_dir() to change .cache's directory
authorTimo Sirainen <timo.sirainen@dovecot.fi>
Sat, 18 Nov 2017 16:12:10 +0000 (18:12 +0200)
committerTimo Sirainen <timo.sirainen@dovecot.fi>
Mon, 20 Nov 2017 11:09:07 +0000 (13:09 +0200)
src/lib-index/mail-index-private.h
src/lib-index/mail-index.c
src/lib-index/mail-index.h

index eeb2260631f880dbe779d653bd4f436be4a07b70..63ed2a8e35ec29be707840e25280f88b3a76abf4 100644 (file)
@@ -154,6 +154,7 @@ union mail_index_module_context {
 
 struct mail_index {
        char *dir, *prefix;
+       char *cache_dir;
 
        struct mail_cache *cache;
        struct mail_transaction_log *log;
index a9b77d7a072807c0f9c2e3de4737e2a1ccde70b7..468f7087f1fec415e11642a9a84401a0ac8d38b3 100644 (file)
@@ -101,6 +101,7 @@ void mail_index_free(struct mail_index **_index)
        array_free(&index->keywords);
        array_free(&index->module_contexts);
 
+       i_free(index->cache_dir);
        i_free(index->ext_hdr_init_data);
        i_free(index->gid_origin);
        i_free(index->error);
@@ -109,6 +110,12 @@ void mail_index_free(struct mail_index **_index)
        i_free(index);
 }
 
+void mail_index_set_cache_dir(struct mail_index *index, const char *dir)
+{
+       i_free(index->cache_dir);
+       index->cache_dir = i_strdup(dir);
+}
+
 void mail_index_set_fsync_mode(struct mail_index *index,
                               enum fsync_mode mode,
                               enum mail_index_fsync_mask mask)
@@ -581,6 +588,20 @@ int mail_index_create_tmp_file(struct mail_index *index,
        return fd;
 }
 
+static const char *mail_index_get_cache_path(struct mail_index *index)
+{
+       const char *dir;
+
+       if (index->cache_dir != NULL)
+               dir = index->cache_dir;
+       else if (index->dir != NULL)
+               dir = index->dir;
+       else
+               return NULL;
+       return t_strconcat(dir, "/", index->prefix,
+                          MAIL_CACHE_FILE_SUFFIX, NULL);
+}
+
 static int mail_index_open_files(struct mail_index *index,
                                 enum mail_index_open_flags flags)
 {
@@ -634,8 +655,10 @@ static int mail_index_open_files(struct mail_index *index,
                        return -1;
        }
 
-       if (index->cache == NULL)
-               index->cache = mail_cache_open_or_create(index);
+       if (index->cache == NULL) {
+               const char *path = mail_index_get_cache_path(index);
+               index->cache = mail_cache_open_or_create_path(index, path);
+       }
        return 1;
 }
 
index 9c4c2b3741bc88200aad57d153f6074c30ce15eb..e8348b0197ef3ea0d881447d022e55efd286bceb 100644 (file)
@@ -291,6 +291,8 @@ struct mail_index_view_sync_ctx;
 struct mail_index *mail_index_alloc(const char *dir, const char *prefix);
 void mail_index_free(struct mail_index **index);
 
+/* Change .cache file's directory. */
+void mail_index_set_cache_dir(struct mail_index *index, const char *dir);
 /* Specify how often to do fsyncs. If mode is FSYNC_MODE_OPTIMIZED, the mask
    can be used to specify which transaction types to fsync. */
 void mail_index_set_fsync_mode(struct mail_index *index, enum fsync_mode mode,