mail-transaction-log.c revision 2454dfa32c93c20a8522c6ed42fe057baaac9f9a
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (c) 2003-2017 Dovecot authors, see the included COPYING file */
4ee00532a265bdfb38539d811fcd12d51210ac35Timo Sirainenmail_transaction_log_set_head(struct mail_transaction_log *log,
3fe44a0df5a0bdd80c495f79cbf0e384441d6fccTimo Sirainen i_assert(log->files->next != NULL || log->files == file);
b8a4aab1f117f6760184ad50b1af41ba810b51f9Timo Sirainenmail_transaction_log_alloc(struct mail_index *index)
2b682d8d3661800f16aceaa45fa4de9b6b140a59Timo Sirainenstatic void mail_transaction_log_2_unlink_old(struct mail_transaction_log *log)
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen if (ioloop_time - st.st_mtime >= (time_t)log->index->log_rotate_log2_stale_secs &&
cb931f84e3ec8e3deda253a1c0ae0409023de096Timo Sirainenint mail_transaction_log_open(struct mail_transaction_log *log)
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen log->filepath = i_strconcat(log->index->filepath,
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen log->filepath2 = i_strconcat(log->filepath, ".2", NULL);
6d6bbe8787354bbb69d0c03187adfe0f497d70b8Timo Sirainen /* these settings aren't available at alloc() time, so we need to
048e40f9364fa68482bc276dd4a5d595a3d742e9Timo Sirainen set them here: */
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen (log->index->flags & MAIL_INDEX_OPEN_FLAG_NFS_FLUSH) != 0;
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen mail_transaction_log_file_free(&log->open_file);
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen file = mail_transaction_log_file_alloc(log, log->filepath);
73583cff4f0ca9ee87204256ca1994adf17cb94cTimo Sirainen if ((ret = mail_transaction_log_file_open(file, &reason)) <= 0) {
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen /* leave the file for _create() */
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainenint mail_transaction_log_create(struct mail_transaction_log *log, bool reset)
ad0fe438255666726723a93f3112df6e103028afTimo Sirainen file = mail_transaction_log_file_alloc_in_memory(log);
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen file = mail_transaction_log_file_alloc(log, log->filepath);
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen /* remember what file we tried to open. if someone else created
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen a new file, use it instead of recreating it */
2521fd0986302cdabc8b0711eef63ac188f32cd6Timo Sirainen file->last_mtime = log->open_file->last_mtime;
d23c747de9d33966483fbdd41f08ad7766da7c5cTimo Sirainen mail_transaction_log_file_free(&log->open_file);
2d8b23805db6f06b8b38174fb6e135386694f429Timo Sirainen if (mail_transaction_log_file_create(file, reset) < 0) {
b1678954f83e1059b981e2def52a70054fa71399Timo Sirainenvoid mail_transaction_log_close(struct mail_transaction_log *log)
b1678954f83e1059b981e2def52a70054fa71399Timo Sirainen mail_transaction_log_file_free(&log->open_file);
d19d3aa4eafa34b48b7d7d311c9db31e1898576aTimo Sirainenvoid mail_transaction_log_free(struct mail_transaction_log **_log)
bc7a4cf2c06702ebaedba9a7c15ce657d5856f63Timo Sirainenvoid mail_transaction_log_move_to_memory(struct mail_transaction_log *log)
bc7a4cf2c06702ebaedba9a7c15ce657d5856f63Timo Sirainen if (!log->index->initial_mapped && log->files != NULL &&
bc7a4cf2c06702ebaedba9a7c15ce657d5856f63Timo Sirainen /* we couldn't read dovecot.index and we don't have the first
b863b7e3fccf75f90f613b875f02fd1781e14e5eTimo Sirainen .log file, so just start from scratch */
6800c6607013d4fdef5a4f764bae407301c6cce8Timo Sirainen log->filepath = i_strconcat(log->index->filepath,
3ccfcf0856958cb9208a9fc51c3bdf13c58ad52aTimo Sirainen log->filepath2 = i_strconcat(log->filepath, ".2", NULL);
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen mail_transaction_log_file_move_to_memory(log->head);
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainen file = mail_transaction_log_file_alloc_in_memory(log);
82995cc154a929f37aa486a72a6485e9f8d34a30Timo Sirainenvoid mail_transaction_log_indexid_changed(struct mail_transaction_log *log)
d761c26f2bbf514e0fc0c6ed9bc52627a4179eabTimo Sirainen for (file = log->files; file != NULL; file = file->next) {
d761c26f2bbf514e0fc0c6ed9bc52627a4179eabTimo Sirainen if (file->hdr.indexid != log->index->indexid) {
2b682d8d3661800f16aceaa45fa4de9b6b140a59Timo Sirainen "indexid changed: %u -> %u",
b863b7e3fccf75f90f613b875f02fd1781e14e5eTimo Sirainen log->head->hdr.indexid != log->index->indexid) {
1795e934ebcd58175d3b5bbdd811b13c7889efa3Timo Sirainen (void)mail_transaction_log_create(log, FALSE);
int ret;
if (reset) {
if (ret == 0) {
const char **reason_r)
const char **reason_r)
const char *reason;
int ret;
return ret;
const char *lock_reason)
const char *reason;
int ret = 0;
if (ret < 0)
return ret;
const char *lock_reason,
const char *lock_reason)
*mtime_r = 0;