]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
fts-flatcurve: Support lock files in VOLATILEDIR
authorMichael M Slusarz <michael.slusarz@open-xchange.com>
Thu, 29 Feb 2024 05:14:53 +0000 (22:14 -0700)
committeraki.tuomi <aki.tuomi@open-xchange.com>
Thu, 20 Feb 2025 13:57:08 +0000 (13:57 +0000)
src/plugins/fts-flatcurve/fts-backend-flatcurve-xapian.cc
src/plugins/fts-flatcurve/fts-backend-flatcurve.c
src/plugins/fts-flatcurve/fts-backend-flatcurve.h

index 0873b3515dc234aea88f2e35090c61a5962da499..fb90237d100698a331ea647439d422d55aa64b8f 100644 (file)
@@ -6,10 +6,12 @@ extern "C" {
 #include "array.h"
 #include "file-create-locked.h"
 #include "hash.h"
+#include "hex-binary.h"
 #include "message-header-parser.h"
 #include "path-util.h"
 #include "mail-storage-private.h"
 #include "mail-search.h"
+#include "md5.h"
 #include "sleep.h"
 #include "str.h"
 #include "unichar.h"
@@ -590,20 +592,32 @@ fts_flatcurve_xapian_db_add(struct flatcurve_fts_backend *backend,
 static int fts_flatcurve_xapian_lock(struct flatcurve_fts_backend *backend,
                                     const char **error_r)
 {
+       struct file_create_settings set;
        struct flatcurve_xapian *x = backend->xapian;
 
-       if (x->lock_path == NULL)
-               x->lock_path = p_strdup_printf(
-                       x->pool, "%s" FLATCURVE_XAPIAN_LOCK_FNAME,
-                       str_c(backend->db_path));
-
-       struct file_create_settings set;
        i_zero(&set);
        set.lock_timeout_secs = FLATCURVE_XAPIAN_LOCK_TIMEOUT_SECS;
        set.lock_settings.close_on_free = TRUE;
        set.lock_settings.unlink_on_free = TRUE;
        set.lock_settings.lock_method = backend->parsed_lock_method;
 
+       if (x->lock_path == NULL) {
+               if (backend->volatile_dir != NULL && str_len(backend->volatile_dir) > 0) {
+                       unsigned char db_path_hash[MD5_RESULTLEN];
+                       md5_get_digest(str_c(backend->db_path), str_len(backend->db_path),
+                               db_path_hash);
+                       x->lock_path = p_strdup_printf(
+                               x->pool, "%s/" FLATCURVE_XAPIAN_LOCK_FNAME ".%s",
+                               str_c(backend->volatile_dir),
+                               binary_to_hex(db_path_hash, sizeof(db_path_hash)));
+                       set.mkdir_mode = 0700;
+               } else {
+                       x->lock_path = p_strdup_printf(
+                               x->pool, "%s" FLATCURVE_XAPIAN_LOCK_FNAME,
+                               str_c(backend->db_path));
+               }
+       }
+
        bool created;
        return file_create_locked(x->lock_path, &set, &x->lock, &created, error_r);
 }
@@ -1894,8 +1908,8 @@ fts_flatcurve_xapian_optimize_box_do(struct flatcurve_fts_backend *backend,
 
        int ret = 0;
        while (fts_flatcurve_xapian_db_iter_next(iter)) {
-               if (iter->type != FLATCURVE_XAPIAN_DB_TYPE_OPTIMIZE &&
-                   iter->type != FLATCURVE_XAPIAN_DB_TYPE_LOCK) {
+               if (iter->type == FLATCURVE_XAPIAN_DB_TYPE_INDEX ||
+                   iter->type == FLATCURVE_XAPIAN_DB_TYPE_CURRENT) {
                        if (fts_flatcurve_xapian_delete(
                                backend, iter->path, error_r) < 0) {
                                ret = -1;
index 7e663e5ee5f7fcf37c01496d7faf28913d3808a0..c44707584fe5569922502e021ec235cef08eac29 100644 (file)
@@ -58,6 +58,7 @@ fts_backend_flatcurve_init(struct fts_backend *_backend, const char **error_r)
        backend->boxname = str_new(backend->pool, 128);
        backend->db_path = str_new(backend->pool, 256);
        backend->fuser = fuser;
+       backend->volatile_dir = str_new(backend->pool, 128);
 
        fuser->backend = backend;
 
@@ -77,6 +78,7 @@ fts_backend_flatcurve_close_mailbox(struct flatcurve_fts_backend *backend,
 
                str_truncate(backend->boxname, 0);
                str_truncate(backend->db_path, 0);
+               str_truncate(backend->volatile_dir, 0);
        }
 
        event_set_append_log_prefix(backend->event, FTS_FLATCURVE_DEBUG_PREFIX);
@@ -117,8 +119,9 @@ int
 fts_backend_flatcurve_set_mailbox(struct flatcurve_fts_backend *backend,
                                   struct mailbox *box, const char **error_r)
 {
-       const char *path;
+       const char *path, *volatile_dir;
        struct mail_storage *storage;
+       struct mail_user *user;
 
        if (str_len(backend->boxname) > 0 &&
            strcasecmp(box->vname, str_c(backend->boxname)) == 0)
@@ -144,6 +147,11 @@ fts_backend_flatcurve_set_mailbox(struct flatcurve_fts_backend *backend,
        storage = mailbox_get_storage(box);
        backend->parsed_lock_method = storage->set->parsed_lock_method;
 
+       user = mail_storage_get_user(storage);
+       volatile_dir = mail_user_get_volatile_dir(user);
+       if (volatile_dir != NULL)
+               str_append(backend->volatile_dir, volatile_dir);
+
        fts_flatcurve_xapian_set_mailbox(backend);
        return 0;
 }
index c2e1c6360e0ebcde925e96bfd92cf8e8dc9d0583..68abc4778ce6d90ecba09cd2eaf989bb27ef2878 100644 (file)
@@ -12,7 +12,7 @@
 
 struct flatcurve_fts_backend {
        struct fts_backend backend;
-       string_t *boxname, *db_path;
+       string_t *boxname, *db_path, *volatile_dir;
 
        struct event *event;