dovecot-2.0: dbox: Split dbox_file_seek() from dbox_file_get_mai...

dovecot at dovecot.org dovecot at dovecot.org
Thu Jul 15 18:59:16 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/7520b31ea95b
changeset: 11826:7520b31ea95b
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Jul 15 16:59:11 2010 +0100
description:
dbox: Split dbox_file_seek() from dbox_file_get_mail_stream()

diffstat:

 src/lib-storage/index/dbox-common/dbox-file.c            |  21 ++++++++++++++-------
 src/lib-storage/index/dbox-common/dbox-file.h            |   6 ++++--
 src/lib-storage/index/dbox-common/dbox-mail.c            |   2 +-
 src/lib-storage/index/dbox-multi/mdbox-purge.c           |   2 +-
 src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c |   5 ++---
 src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c   |   4 ++--
 6 files changed, 24 insertions(+), 16 deletions(-)

diffs (124 lines):

diff -r b6693d570960 -r 7520b31ea95b src/lib-storage/index/dbox-common/dbox-file.c
--- a/src/lib-storage/index/dbox-common/dbox-file.c	Thu Jul 15 16:39:51 2010 +0100
+++ b/src/lib-storage/index/dbox-common/dbox-file.c	Thu Jul 15 16:59:11 2010 +0100
@@ -367,8 +367,7 @@
 	return 1;
 }
 
-int dbox_file_get_mail_stream(struct dbox_file *file, uoff_t offset,
-			      struct istream **stream_r)
+int dbox_file_seek(struct dbox_file *file, uoff_t offset)
 {
 	uoff_t size;
 	int ret;
@@ -387,10 +386,18 @@
 		file->cur_physical_size = size;
 	}
 	i_stream_seek(file->input, offset + file->msg_header_size);
-	if (stream_r != NULL) {
-		*stream_r = i_stream_create_limit(file->input,
-						  file->cur_physical_size);
-	}
+	return 1;
+}
+
+int dbox_file_get_mail_stream(struct dbox_file *file, uoff_t offset,
+			      struct istream **stream_r)
+{
+	int ret;
+
+	if ((ret = dbox_file_seek(file, offset)) <= 0)
+		return ret;
+
+	*stream_r = i_stream_create_limit(file->input, file->cur_physical_size);
 	return 1;
 }
 
@@ -447,7 +454,7 @@
 	}
 	*last_r = FALSE;
 
-	ret = dbox_file_get_mail_stream(file, offset, NULL);
+	ret = dbox_file_seek(file, offset);
 	if (*offset_r == 0)
 		*offset_r = file->file_header_size;
 	return ret;
diff -r b6693d570960 -r 7520b31ea95b src/lib-storage/index/dbox-common/dbox-file.h
--- a/src/lib-storage/index/dbox-common/dbox-file.h	Thu Jul 15 16:39:51 2010 +0100
+++ b/src/lib-storage/index/dbox-common/dbox-file.h	Thu Jul 15 16:59:11 2010 +0100
@@ -153,8 +153,10 @@
 int dbox_file_try_lock(struct dbox_file *file);
 void dbox_file_unlock(struct dbox_file *file);
 
-/* Seek to given offset in file and return the message's input stream.
-   Returns 1 if ok/expunged, 0 if file/offset is corrupted, -1 if I/O error. */
+/* Seek to given offset in file. Returns 1 if ok/expunged, 0 if file/offset is
+   corrupted, -1 if I/O error. */
+int dbox_file_seek(struct dbox_file *file, uoff_t offset);
+/* Same as dbox_file_seek(), but return also input stream for message. */
 int dbox_file_get_mail_stream(struct dbox_file *file, uoff_t offset,
 			      struct istream **input_r);
 /* Start seeking at the beginning of the file. */
diff -r b6693d570960 -r 7520b31ea95b src/lib-storage/index/dbox-common/dbox-mail.c
--- a/src/lib-storage/index/dbox-common/dbox-mail.c	Thu Jul 15 16:39:51 2010 +0100
+++ b/src/lib-storage/index/dbox-common/dbox-mail.c	Thu Jul 15 16:59:11 2010 +0100
@@ -45,7 +45,7 @@
 	if (storage->v.mail_open(mail, &offset, file_r) < 0)
 		return -1;
 
-	if (dbox_file_get_mail_stream(*file_r, offset, NULL) <= 0)
+	if (dbox_file_seek(*file_r, offset) <= 0)
 		return -1;
 	if (dbox_file_metadata_read(*file_r) <= 0)
 		return -1;
diff -r b6693d570960 -r 7520b31ea95b src/lib-storage/index/dbox-multi/mdbox-purge.c
--- a/src/lib-storage/index/dbox-multi/mdbox-purge.c	Thu Jul 15 16:39:51 2010 +0100
+++ b/src/lib-storage/index/dbox-multi/mdbox-purge.c	Thu Jul 15 16:59:11 2010 +0100
@@ -229,7 +229,7 @@
 	i_array_init(&expunged_map_uids, I_MIN(count, 1));
 	offset = file->file_header_size;
 	for (i = 0; i < count; i++) {
-		if ((ret = dbox_file_get_mail_stream(file, offset, NULL)) <= 0)
+		if ((ret = dbox_file_seek(file, offset)) <= 0)
 			break;
 
 		if (msgs[i].offset != offset) {
diff -r b6693d570960 -r 7520b31ea95b src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c
--- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c	Thu Jul 15 16:39:51 2010 +0100
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c	Thu Jul 15 16:59:11 2010 +0100
@@ -175,8 +175,7 @@
 			fixed = TRUE;
 			if (!first) {
 				/* seek to the offset where we last left off */
-				ret = dbox_file_get_mail_stream(file,
-					prev_offset, NULL);
+				ret = dbox_file_seek(file, prev_offset);
 				if (ret <= 0)
 					break;
 			}
@@ -613,7 +612,7 @@
 	file = mdbox_file_init(ctx->storage, msg->file_id);
 	ret = dbox_file_open(file, &deleted);
 	if (ret > 0 && !deleted)
-		ret = dbox_file_get_mail_stream(file, msg->offset, NULL);
+		ret = dbox_file_seek(file, msg->offset);
 	if (ret > 0 && !deleted && dbox_file_metadata_read(file) > 0) {
 		mailbox = dbox_file_metadata_get(file,
 						 DBOX_METADATA_ORIG_MAILBOX);
diff -r b6693d570960 -r 7520b31ea95b src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c
--- a/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c	Thu Jul 15 16:39:51 2010 +0100
+++ b/src/lib-storage/index/dbox-single/sdbox-sync-rebuild.c	Thu Jul 15 16:59:11 2010 +0100
@@ -34,11 +34,11 @@
 	if ((ret = dbox_file_open(file, &deleted)) > 0) {
 		if (deleted)
 			return 0;
-		ret = dbox_file_get_mail_stream(file, 0, NULL);
+		ret = dbox_file_seek(file, 0);
 	}
 	if (ret == 0) {
 		if ((ret = dbox_file_fix(file, 0)) == 0)
-			ret = dbox_file_get_mail_stream(file, 0, NULL);
+			ret = dbox_file_seek(file, 0);
 	}
 
 	if (ret <= 0) {


More information about the dovecot-cvs mailing list