mail-transaction-log.c revision 437b1d7e0a91ed93ff66a9056d0aac16ae23603c
5e0ce63bb65db34d7f48b34bbb5545fa791781c4Timo Sirainen/* Copyright (C) 2003-2007 Timo Sirainen */
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen/* this lock should never exist for a long time.. */
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenmail_transaction_log_set_head(struct mail_transaction_log *log,
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenmail_transaction_log_alloc(struct mail_index *index)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen log->dotlock_settings.use_excl_lock = index->use_excl_dotlocks;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen log->dotlock_settings.timeout = LOG_DOTLOCK_TIMEOUT;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen log->dotlock_settings.stale_timeout = LOG_DOTLOCK_STALE_TIMEOUT;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen log->new_dotlock_settings = log->dotlock_settings;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen log->new_dotlock_settings.lock_suffix = LOG_NEW_DOTLOCK_SUFFIX;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenint mail_transaction_log_open(struct mail_transaction_log *log)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen mail_transaction_log_file_free(&log->open_file);
03f5c621d06d6b6d77a145196c9633a7aa64dc78Timo Sirainen file = mail_transaction_log_file_alloc(log, path);
03f5c621d06d6b6d77a145196c9633a7aa64dc78Timo Sirainen if ((ret = mail_transaction_log_file_open(file, FALSE)) <= 0) {
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* leave the file for _create() */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenint mail_transaction_log_create(struct mail_transaction_log *log)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen file = mail_transaction_log_file_alloc_in_memory(log);
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen file = mail_transaction_log_file_alloc(log, path);
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen /* remember what file we tried to open. if someone else created
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen a new file, use it instead of recreating it */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen file->last_mtime = log->open_file->last_mtime;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen mail_transaction_log_file_free(&log->open_file);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen if (mail_transaction_log_file_create(file) < 0)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenvoid mail_transaction_log_close(struct mail_transaction_log *log)
b3142c8e513bc78da821fa70f479016148fa95e5Timo Sirainen mail_transaction_log_file_free(&log->open_file);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenvoid mail_transaction_log_free(struct mail_transaction_log **_log)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenvoid mail_transaction_log_move_to_memory(struct mail_transaction_log *log)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen mail_transaction_log_file_move_to_memory(log->head);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenvoid mail_transaction_logs_clean(struct mail_transaction_log *log)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen struct mail_transaction_log_file *file, *next;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen for (file = log->files; file != NULL; file = next) {
b3142c8e513bc78da821fa70f479016148fa95e5Timo Sirainen (((file)->sync_offset > MAIL_TRANSACTION_LOG_ROTATE_MIN_SIZE && \
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen ioloop_time - MAIL_TRANSACTION_LOG_ROTATE_TIME) || \
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen ((file)->sync_offset > MAIL_TRANSACTION_LOG_ROTATE_MAX_SIZE))
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenbool mail_transaction_log_want_rotate(struct mail_transaction_log *log)
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainenint mail_transaction_log_rotate(struct mail_transaction_log *log)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen file = mail_transaction_log_file_alloc_in_memory(log);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen /* we're locked, we shouldn't need to worry about ESTALE
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen problems in here. */
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainen file = mail_transaction_log_file_alloc(log, path);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen if (mail_transaction_log_file_create(file) < 0) {
dd62b77c932d1b518f2a3e4bf80e36542becc256Timo Sirainenstatic int mail_transaction_log_refresh(struct mail_transaction_log *log)
const char *path;
int ret;
return ret;
int ret = 0;
if (ret < 0)
return ret;