[dovecot-cvs] dovecot/src/lib-index mail-transaction-log-append.c, 1.17.2.6, 1.17.2.7 mail-transaction-log.c, 1.111.2.14, 1.111.2.15

tss at dovecot.org tss at dovecot.org
Sun Mar 11 19:43:09 EET 2007


Update of /var/lib/cvs/dovecot/src/lib-index
In directory talvi:/tmp/cvs-serv8395

Modified Files:
      Tag: branch_1_0
	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.17.2.6
retrieving revision 1.17.2.7
diff -u -d -r1.17.2.6 -r1.17.2.7
--- mail-transaction-log-append.c	11 Mar 2007 16:40:54 -0000	1.17.2.6
+++ mail-transaction-log-append.c	11 Mar 2007 17:43:06 -0000	1.17.2.7
@@ -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.111.2.14
retrieving revision 1.111.2.15
diff -u -d -r1.111.2.14 -r1.111.2.15
--- mail-transaction-log.c	8 Mar 2007 20:02:33 -0000	1.111.2.14
+++ mail-transaction-log.c	11 Mar 2007 17:43:07 -0000	1.111.2.15
@@ -1143,8 +1143,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;
 		}
 	}
@@ -1207,6 +1212,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;
 
@@ -1271,6 +1278,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