Mercurial > dovecot > core-2.2
changeset 22819:698dedb5a026
lib-storage: mail_storage_lock_create() - add support for dotlocks
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Tue, 06 Feb 2018 18:01:04 +0200 |
parents | c4c14db5c639 |
children | 85a8901c8ad6 |
files | src/lib-storage/mail-storage-private.h src/lib-storage/mail-storage.c src/lib-storage/mail-user.c |
diffstat | 3 files changed, 35 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/mail-storage-private.h Tue Feb 06 17:49:15 2018 +0200 +++ b/src/lib-storage/mail-storage-private.h Tue Feb 06 18:01:04 2018 +0200 @@ -827,6 +827,7 @@ -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(). */
--- a/src/lib-storage/mail-storage.c Tue Feb 06 17:49:15 2018 +0200 +++ b/src/lib-storage/mail-storage.c Tue Feb 06 18:01:04 2018 +0200 @@ -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 @@ 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 @@ 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); }
--- a/src/lib-storage/mail-user.c Tue Feb 06 17:49:15 2018 +0200 +++ b/src/lib-storage/mail-user.c Tue Feb 06 18:01:04 2018 +0200 @@ -533,7 +533,7 @@ 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)