changeset 6002:16f91815c7ed HEAD

Code cleanup
author Timo Sirainen <tss@iki.fi>
date Sun, 15 Jul 2007 01:21:53 +0300
parents 2d81847eb3e6
children 6f66ce9491ad
files src/lib-index/mail-transaction-log-file.c
diffstat 1 files changed, 35 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-transaction-log-file.c	Sun Jul 15 01:04:56 2007 +0300
+++ b/src/lib-index/mail-transaction-log-file.c	Sun Jul 15 01:21:53 2007 +0300
@@ -854,35 +854,13 @@
 }
 
 static int
-mail_transaction_log_file_read(struct mail_transaction_log_file *file,
-			       uoff_t start_offset)
+mail_transaction_log_file_read_more(struct mail_transaction_log_file *file)
 {
 	void *data;
 	size_t size;
 	uint32_t read_offset;
-	int ret;
-
-	i_assert(file->mmap_base == NULL);
-
-	if (file->log->index->nfs_flush) {
-		/* Make sure we know the latest file size */
-		nfs_flush_attr_cache_fd(file->filepath, file->fd);
-	}
+	ssize_t ret;
 
-	if (file->buffer != NULL && file->buffer_offset > start_offset) {
-		/* we have to insert missing data to beginning of buffer */
-		ret = mail_transaction_log_file_insert_read(file, start_offset);
-		if (ret <= 0)
-			return ret;
-	}
-
-	if (file->buffer == NULL) {
-		file->buffer =
-			buffer_create_dynamic(default_pool, LOG_PREFETCH);
-		file->buffer_offset = start_offset;
-	}
-
-	/* read all records */
 	read_offset = file->buffer_offset + buffer_get_used_size(file->buffer);
 
 	do {
@@ -907,10 +885,41 @@
 						  file->filepath, "pread()");
 		return -1;
 	}
+	return 1;
+}
+
+static int
+mail_transaction_log_file_read(struct mail_transaction_log_file *file,
+			       uoff_t start_offset)
+{
+	int ret;
+
+	i_assert(file->mmap_base == NULL);
+
+	if (file->log->index->nfs_flush) {
+		/* Make sure we know the latest file size */
+		nfs_flush_attr_cache_fd(file->filepath, file->fd);
+	}
+
+	if (file->buffer != NULL && file->buffer_offset > start_offset) {
+		/* we have to insert missing data to beginning of buffer */
+		ret = mail_transaction_log_file_insert_read(file, start_offset);
+		if (ret <= 0)
+			return ret;
+	}
+
+	if (file->buffer == NULL) {
+		file->buffer =
+			buffer_create_dynamic(default_pool, LOG_PREFETCH);
+		file->buffer_offset = start_offset;
+	}
+
+	if ((ret = mail_transaction_log_file_read_more(file)) <= 0)
+		return ret;
 
 	if ((ret = mail_transaction_log_file_sync(file)) <= 0) {
-		i_assert(ret != 0);
-		return 0;
+		i_assert(ret != 0); /* happens only with mmap */
+		return -1;
 	}
 
 	i_assert(file->sync_offset >= file->buffer_offset);