static struct mail_transaction_log_file *
mail_transaction_log_file_open_or_create(struct mail_transaction_log *log,
const char *path);
-static int mail_transaction_log_rotate(struct mail_transaction_log *log);
+static int mail_transaction_log_rotate(struct mail_transaction_log *log,
+ int lock_type);
static int
mail_transaction_log_file_lock(struct mail_transaction_log_file *file,
ret = -1;
else if (INDEX_HAS_MISSING_LOGS(index, file)) {
/* broken - fix it by creating a new log file */
- ret = mail_transaction_log_rotate(log);
+ ret = mail_transaction_log_rotate(log, F_UNLCK);
}
}
log->head = NULL;
}
-static int mail_transaction_log_rotate(struct mail_transaction_log *log)
+static int mail_transaction_log_rotate(struct mail_transaction_log *log,
+ int lock_type)
{
struct mail_transaction_log_file *file;
struct stat st;
- int fd, lock_type;
+ int fd;
if (fstat(log->head->fd, &st) < 0) {
mail_index_file_set_syscall_error(log->index,
if (file == NULL)
return -1;
- lock_type = log->head->lock_type;
if (lock_type != F_UNLCK) {
if (mail_transaction_log_file_lock(file, lock_type) < 0) {
file->refcount--;
return -1;
}
}
+ i_assert(file->lock_type == lock_type);
if (--log->head->refcount == 0)
mail_transaction_logs_clean(log);
if (mail_index_lock_shared(log->index, TRUE, &lock_id) < 0)
return -1;
- ret = mail_transaction_log_rotate(log);
+ ret = mail_transaction_log_rotate(log, F_UNLCK);
mail_index_unlock(log->index, lock_id);
return ret;
}
break;
}
+ i_assert(log->head->lock_type == F_UNLCK);
if (file != NULL) {
if (mail_transaction_log_file_lock(file, F_UNLCK) < 0)
return -1;
log->head->last_mtime <
ioloop_time - MAIL_TRANSACTION_LOG_ROTATE_MIN_TIME) {
/* everything synced in index, we can rotate. */
- if (mail_transaction_log_rotate(log) < 0) {
+ if (mail_transaction_log_rotate(log, F_WRLCK) < 0) {
if (!log->index->log_locked) {
(void)mail_transaction_log_file_lock(log->head,
F_UNLCK);