mail-index-write.c revision 57dd2621d4230bc2e06c69a4b9f8cf8f0ff2bc93
bcb4e51a409d94ae670de96afb8483a4f7855294Stephan Bosch/* Copyright (c) 2003-2016 Dovecot authors, see the included COPYING file */
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen/* if we're updating >= count-n messages, recreate the index */
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen#define MAIL_INDEX_MAX_OVERWRITE_NEG_SEQ_COUNT 10
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainenstatic int mail_index_create_backup(struct mail_index *index)
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen /* we very much want to avoid creating a backup file that
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen hasn't been written to disk yet */
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen mail_index_set_error(index, "fdatasync(%s) failed: %m",
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen backup_path = t_strconcat(index->filepath, ".backup", NULL);
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen tmp_backup_path = t_strconcat(backup_path, ".tmp", NULL);
d47bd663deb1846980e6759c87297741a5459890Timo Sirainen if (unlink(tmp_backup_path) < 0 && errno != ENOENT) {
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen mail_index_set_error(index, "unlink(%s) failed: %m",
d47bd663deb1846980e6759c87297741a5459890Timo Sirainen /* no dovecot.index file, ignore */
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen mail_index_set_error(index, "link(%s, %s) failed: %m",
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen if (rename(tmp_backup_path, backup_path) < 0) {
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainen mail_index_set_error(index, "rename(%s, %s) failed: %m",
f5982bb5b0a704e88fa2b44b0b74e365d13103b9Timo Sirainenstatic int mail_index_recreate(struct mail_index *index)
unsigned int base_size;
const char *path;
if (ret < 0)
return ret;
if (want_rotate &&