Mercurial > dovecot > core-2.2
changeset 22278:799536d825cf
lib-storage: mailbox_autoexpunge_lock() - small cleanup
No functional changes - just reorganizing code and adding comments.
author | Timo Sirainen <timo.sirainen@dovecot.fi> |
---|---|
date | Thu, 22 Jun 2017 02:32:10 +0300 |
parents | 55bf504485e8 |
children | 53f8039b2aa0 |
files | src/lib-storage/mail-autoexpunge.c |
diffstat | 1 files changed, 25 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/lib-storage/mail-autoexpunge.c Thu Jun 22 02:24:08 2017 +0300 +++ b/src/lib-storage/mail-autoexpunge.c Thu Jun 22 02:32:10 2017 +0300 @@ -30,25 +30,33 @@ so that multiple processes won't do the same work unnecessarily, and 2) it helps to avoid duplicate mails being added with lazy_expunge. */ - if ((ret = mail_user_get_home(user, &home)) > 0) { - const struct mail_storage_settings *mail_set = - mail_user_set_get_storage_set(user); - i_zero(&lock_set); - lock_set.lock_method = mail_set->parsed_lock_method, - path = t_strdup_printf("%s/"AUTOEXPUNGE_LOCK_FNAME, home); - if (file_create_locked(path, &lock_set, lock, - &created, &error) == -1) { - if (errno == EAGAIN) - return FALSE; - if (errno != ENOENT) - i_error("autoexpunge: Couldn't lock %s: %s", path, error); - return TRUE; + if ((ret = mail_user_get_home(user, &home)) < 0) { + /* home lookup failed - shouldn't really happen */ + return TRUE; + } + if (ret == 0) { + i_warning("autoexpunge: User has no home directory, can't lock"); + return TRUE; + } + + const struct mail_storage_settings *mail_set = + mail_user_set_get_storage_set(user); + i_zero(&lock_set); + lock_set.lock_method = mail_set->parsed_lock_method; + path = t_strdup_printf("%s/"AUTOEXPUNGE_LOCK_FNAME, home); + if (file_create_locked(path, &lock_set, lock, &created, &error) == -1) { + if (errno == EAGAIN) { + /* another process is autoexpunging, so we don't + need to. */ + return FALSE; } - file_lock_set_unlink_on_free(*lock, TRUE); - file_lock_set_close_on_free(*lock, TRUE); - } else if (ret == 0) { - i_warning("autoexpunge: User has no home directory, can't lock"); + if (errno == ENOENT) + i_error("autoexpunge: Couldn't lock %s: %s", path, error); + /* do autoexpunging anyway */ + return TRUE; } + file_lock_set_unlink_on_free(*lock, TRUE); + file_lock_set_close_on_free(*lock, TRUE); return TRUE; }