return ret;
}
-int mail_transaction_log_file_open(struct mail_transaction_log_file *file)
+int mail_transaction_log_file_open(struct mail_transaction_log_file *file,
+ const char **reason_r)
{
struct mail_index *index = file->log->index;
unsigned int i;
index->readonly = TRUE;
}
if (file->fd == -1) {
- if (errno == ENOENT)
+ if (errno == ENOENT) {
+ *reason_r = "File doesn't exist";
return 0;
+ }
log_file_set_syscall_error(file, "open()");
+ *reason_r = t_strdup_printf("open() failed: %m");
return -1;
}
renamed to .log.2 and we're trying to reopen it.
also possible that hit a race condition where .log
and .log.2 are linked. */
+ *reason_r = "File is already open";
return 0;
} else {
ret = mail_transaction_log_file_read_hdr(file,
} else {
i_unlink_if_exists(file->filepath);
}
+ *reason_r = "File is corrupted";
return 0;
}
if (errno != ESTALE ||
i == MAIL_INDEX_ESTALE_RETRY_COUNT) {
/* syscall error */
+ *reason_r = t_strdup_printf("fstat() failed: %m");
return -1;
}
const char *path);
void mail_transaction_log_file_free(struct mail_transaction_log_file **file);
-int mail_transaction_log_file_open(struct mail_transaction_log_file *file);
+/* Returns 1 if log was opened, 0 if it didn't exist or was already open,
+ -1 if error. */
+int mail_transaction_log_file_open(struct mail_transaction_log_file *file,
+ const char **reason_r);
int mail_transaction_log_file_create(struct mail_transaction_log_file *file,
bool reset);
int mail_transaction_log_file_lock(struct mail_transaction_log_file *file);
int mail_transaction_log_open(struct mail_transaction_log *log)
{
struct mail_transaction_log_file *file;
+ const char *reason;
int ret;
i_free(log->filepath);
return 0;
file = mail_transaction_log_file_alloc(log, log->filepath);
- if ((ret = mail_transaction_log_file_open(file)) <= 0) {
+ if ((ret = mail_transaction_log_file_open(file, &reason)) <= 0) {
/* leave the file for _create() */
log->open_file = file;
return ret;
{
struct mail_transaction_log_file *file;
struct stat st;
+ const char *reason;
i_assert(log->head != NULL);
}
file = mail_transaction_log_file_alloc(log, log->filepath);
- if (mail_transaction_log_file_open(file) <= 0) {
+ if (mail_transaction_log_file_open(file, &reason) <= 0) {
mail_transaction_log_file_free(&file);
return -1;
}
/* see if we have it in log.2 file */
file = mail_transaction_log_file_alloc(log, log->filepath2);
- if ((ret = mail_transaction_log_file_open(file)) <= 0) {
+ if ((ret = mail_transaction_log_file_open(file, reason_r)) <= 0) {
mail_transaction_log_file_free(&file);
- if (ret < 0)
- *reason_r = "Failed to open .log.2";
- else
- *reason_r = ".log.2 doesn't exist";
return ret;
}