Skip to content

Commit

Permalink
lib-storage: mail_storage_lock_create() - add support for dotlocks
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen authored and villesavolainen committed Feb 9, 2018
1 parent 6501e89 commit ee37361
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/lib-storage/mail-storage-private.h
Expand Up @@ -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(). */
Expand Down
34 changes: 33 additions & 1 deletion src/lib-storage/mail-storage.c
Expand Up @@ -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"
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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);
}
2 changes: 1 addition & 1 deletion src/lib-storage/mail-user.c
Expand Up @@ -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)
Expand Down

0 comments on commit ee37361

Please sign in to comment.