diff --git a/src/lib-storage/mail-storage-private.h b/src/lib-storage/mail-storage-private.h index 441b7bc7c6..a6c0ce2aad 100644 --- a/src/lib-storage/mail-storage-private.h +++ b/src/lib-storage/mail-storage-private.h @@ -827,6 +827,7 @@ int mailbox_create_fd(struct mailbox *box, const char *path, int flags, -1 and sets error_r on other errors. */ int mail_storage_lock_create(const char *lock_path, const struct file_create_settings *lock_set, + const struct mail_storage_settings *mail_set, struct file_lock **lock_r, const char **error_r); /* Create a lock file to the mailbox with the given filename. Returns the same as mail_storage_lock_create(). */ diff --git a/src/lib-storage/mail-storage.c b/src/lib-storage/mail-storage.c index 7f3c178325..b450485bbf 100644 --- a/src/lib-storage/mail-storage.c +++ b/src/lib-storage/mail-storage.c @@ -9,6 +9,7 @@ #include "sha1.h" #include "unichar.h" #include "hex-binary.h" +#include "file-dotlock.h" #include "file-create-locked.h" #include "istream.h" #include "eacces-error.h" @@ -2855,12 +2856,42 @@ void mail_set_mail_cache_corrupted(struct mail *mail, const char *fmt, ...) va_end(va); } +static int +mail_storage_dotlock_create(const char *lock_path, + const struct file_create_settings *lock_set, + const struct mail_storage_settings *mail_set, + struct file_lock **lock_r, const char **error_r) +{ + const struct dotlock_settings dotlock_set = { + .timeout = lock_set->lock_timeout_secs, + .stale_timeout = I_MAX(60*5, lock_set->lock_timeout_secs), + .lock_suffix = "", + + .use_excl_lock = mail_set->dotlock_use_excl, + .nfs_flush = mail_set->mail_nfs_storage, + .use_io_notify = TRUE, + }; + struct dotlock *dotlock; + int ret = file_dotlock_create(&dotlock_set, lock_path, 0, &dotlock); + if (ret <= 0) { + *error_r = t_strdup_printf("file_dotlock_create(%s) failed: %m", + lock_path); + return ret; + } + *lock_r = file_lock_from_dotlock(&dotlock); + return 1; +} + int mail_storage_lock_create(const char *lock_path, const struct file_create_settings *lock_set, + const struct mail_storage_settings *mail_set, struct file_lock **lock_r, const char **error_r) { bool created; + if (lock_set->lock_method == FILE_LOCK_METHOD_DOTLOCK) + return mail_storage_dotlock_create(lock_path, lock_set, mail_set, lock_r, error_r); + if (file_create_locked(lock_path, lock_set, lock_r, &created, error_r) == -1) { *error_r = t_strdup_printf("file_create_locked(%s) failed: %s", @@ -2909,5 +2940,6 @@ int mailbox_lock_file_create(struct mailbox *box, const char *lock_fname, set.mkdir_mode = 0700; } - return mail_storage_lock_create(lock_path, &set, lock_r, error_r); + return mail_storage_lock_create(lock_path, &set, + box->storage->set, lock_r, error_r); } diff --git a/src/lib-storage/mail-user.c b/src/lib-storage/mail-user.c index 69be963890..efc0dd6901 100644 --- a/src/lib-storage/mail-user.c +++ b/src/lib-storage/mail-user.c @@ -533,7 +533,7 @@ int mail_user_lock_file_create(struct mail_user *user, const char *lock_fname, lock_fname); lock_set.mkdir_mode = 0700; } - return mail_storage_lock_create(path, &lock_set, lock_r, error_r); + return mail_storage_lock_create(path, &lock_set, mail_set, lock_r, error_r); } const char *mail_user_get_anvil_userip_ident(struct mail_user *user)