#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"
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);
}
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;
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;
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);
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)
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;
}