return MAIL_INDEX_IS_IN_MEMORY(index);
}
+static void mail_index_set_as_in_memory(struct mail_index *index)
+{
+ i_free_and_null(index->dir);
+
+ i_free(index->filepath);
+ index->filepath = i_strdup("(in-memory index)");
+}
+
int mail_index_move_to_memory(struct mail_index *index)
{
struct mail_index_map *map;
if ((index->flags & MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY) != 0)
return -1;
- /* set the index as being into memory */
- i_free_and_null(index->dir);
-
- i_free(index->filepath);
- index->filepath = i_strdup("(in-memory index)");
-
if (index->map == NULL) {
/* index was never even opened. just mark it as being in
memory and let the caller re-open the index. */
i_assert(index->fd == -1);
+ mail_index_set_as_in_memory(index);
return -1;
}
if (index->log != NULL) {
/* move transaction log to memory */
- mail_transaction_log_move_to_memory(index->log);
+ if (mail_transaction_log_move_to_memory(index->log) < 0)
+ return -1;
}
if (index->fd != -1) {
mail_index_set_syscall_error(index, "close()");
index->fd = -1;
}
+ mail_index_set_as_in_memory(index);
return 0;
}
reason_r) ? 1 : 0;
}
-void mail_transaction_log_file_move_to_memory(struct mail_transaction_log_file
- *file)
+int mail_transaction_log_file_move_to_memory(struct mail_transaction_log_file *file)
{
const char *error;
buffer_t *buf;
+ int ret = 0;
if (MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file))
- return;
+ return 0;
if (file->mmap_base != NULL) {
/* just copy to memory */
file->mmap_base = NULL;
} else if (file->buffer_offset != 0) {
/* we don't have the full log in the memory. read it. */
- (void)mail_transaction_log_file_read(file, 0, FALSE, &error);
+ ret = mail_transaction_log_file_read(file, 0, FALSE, &error);
+ if (ret <= 0) {
+ mail_index_set_error(file->log->index,
+ "%s: Failed to read into memory: %s", file->filepath, error);
+ }
}
file->last_size = 0;
i_free(file->filepath);
file->filepath = i_strdup(file->log->filepath);
+ return ret < 0 ? -1 : 0;
}
int mail_transaction_log_file_map(struct mail_transaction_log_file *file,
uoff_t start_offset, uoff_t end_offset,
const char **reason_r);
-void mail_transaction_log_file_move_to_memory(struct mail_transaction_log_file
- *file);
+int mail_transaction_log_file_move_to_memory(struct mail_transaction_log_file *file);
void mail_transaction_logs_clean(struct mail_transaction_log *log);
i_free(log);
}
-void mail_transaction_log_move_to_memory(struct mail_transaction_log *log)
+int mail_transaction_log_move_to_memory(struct mail_transaction_log *log)
{
struct mail_transaction_log_file *file;
log->filepath2 = i_strconcat(log->filepath, ".2", NULL);
if (log->head != NULL)
- mail_transaction_log_file_move_to_memory(log->head);
+ return mail_transaction_log_file_move_to_memory(log->head);
else {
file = mail_transaction_log_file_alloc_in_memory(log);
mail_transaction_log_set_head(log, file);
+ return 0;
}
}
/* Move currently opened log head file to memory (called by
mail_index_move_to_memory()) */
-void mail_transaction_log_move_to_memory(struct mail_transaction_log *log);
+int mail_transaction_log_move_to_memory(struct mail_transaction_log *log);
/* Returns mtime of the transaction log head file.
If it doesn't exist, mtime_r is set to 0. */
int mail_transaction_log_get_mtime(struct mail_transaction_log *log,