[dovecot-cvs] dovecot/src/lib-index mail-transaction-log-append.c, 1.24, 1.25 mail-transaction-log.c, 1.126, 1.127
tss at dovecot.org
tss at dovecot.org
Sun Mar 11 19:43:13 EET 2007
Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv8393
Modified Files:
mail-transaction-log-append.c mail-transaction-log.c
Log Message:
If write to transaction log fails, we may later need to truncate the file so
that after the write there won't be garbage after it.
Index: mail-transaction-log-append.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log-append.c,v
retrieving revision 1.24
retrieving revision 1.25
diff -u -d -r1.24 -r1.25
--- mail-transaction-log-append.c 11 Mar 2007 16:40:58 -0000 1.24
+++ mail-transaction-log-append.c 11 Mar 2007 17:43:10 -0000 1.25
@@ -426,6 +426,9 @@
file->first_append_size = 0;
append_offset = file->sync_offset;
+ if (file->sync_offset < file->buffer_offset)
+ file->sync_offset = file->buffer_offset;
+
old_hidden_syncs_count = !array_is_created(&view->syncs_hidden) ? 0 :
array_count(&view->syncs_hidden);
@@ -488,6 +491,20 @@
t->external);
}
+ if (ret == 0 && file->sync_offset < file->last_size) {
+ /* there is some garbage at the end of the transaction log
+ (eg. previous write failed). remove it so reader doesn't
+ break because of it. */
+ buffer_set_used_size(file->buffer,
+ file->sync_offset - file->buffer_offset);
+ if (!MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file)) {
+ if (ftruncate(file->fd, file->sync_offset) < 0) {
+ mail_index_file_set_syscall_error(index,
+ file->filepath, "ftruncate()");
+ }
+ }
+ }
+
if (ret == 0 && file->first_append_size != 0) {
if (!MAIL_TRANSACTION_LOG_FILE_IN_MEMORY(file)) {
/* synced - rewrite first record's header */
Index: mail-transaction-log.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/lib-index/mail-transaction-log.c,v
retrieving revision 1.126
retrieving revision 1.127
diff -u -d -r1.126 -r1.127
--- mail-transaction-log.c 8 Mar 2007 20:02:37 -0000 1.126
+++ mail-transaction-log.c 11 Mar 2007 17:43:10 -0000 1.127
@@ -1137,8 +1137,13 @@
memory, it may be just that the memory was updated
after we checked the file size. */
if (file->locked || file->mmap_base == NULL) {
- mail_transaction_log_file_set_corrupted(file,
- "hdr.size too large (%u)", hdr_size);
+ if (hdr_size != 0) {
+ mail_transaction_log_file_set_corrupted(file,
+ "hdr.size too large (%u)", hdr_size);
+ } else {
+ mail_transaction_log_file_set_corrupted(file,
+ "Unexpected garbage at EOF");
+ }
return -1;
}
}
@@ -1201,6 +1206,8 @@
buffer_set_used_size(file->buffer, size);
} while (ret > 0 || (ret < 0 && errno == EINTR));
+ file->last_size = read_offset;
+
if (mail_transaction_log_file_sync(file) < 0)
return -1;
@@ -1265,6 +1272,8 @@
"fstat()");
return -1;
}
+ file->last_size = st.st_size;
+
if (start_offset > (uoff_t)st.st_size) {
mail_transaction_log_file_set_corrupted(file,
"start_offset (%"PRIuUOFF_T") > file size "
More information about the dovecot-cvs
mailing list