dovecot-2.2: i_stream_stat() API changed.

dovecot at dovecot.org dovecot at dovecot.org
Tue Aug 28 22:41:19 EEST 2012


details:   http://hg.dovecot.org/dovecot-2.2/rev/6d2be8d8891c
changeset: 14964:6d2be8d8891c
user:      Timo Sirainen <tss at iki.fi>
date:      Tue Aug 28 22:40:57 2012 +0300
description:
i_stream_stat() API changed.
This fixes also one missing error check.

diffstat:

 src/lib-compression/istream-bzlib.c           |  18 +++++++---------
 src/lib-compression/istream-zlib.c            |  18 +++++++---------
 src/lib-fs/fs-sis.c                           |   3 +-
 src/lib-mail/istream-header-filter.c          |  14 +++++++-----
 src/lib-storage/index/maildir/maildir-mail.c  |   3 +-
 src/lib-storage/index/mbox/istream-raw-mbox.c |   9 +++----
 src/lib-storage/index/mbox/mbox-sync.c        |  12 +++-------
 src/lib-storage/index/raw/raw-mail.c          |   3 +-
 src/lib-storage/list/subscription-file.c      |   2 +-
 src/lib/istream-chain.c                       |   8 -------
 src/lib/istream-concat.c                      |  10 ++++----
 src/lib/istream-file.c                        |   9 +++----
 src/lib/istream-limit.c                       |  12 ++++------
 src/lib/istream-mmap.c                        |   7 +----
 src/lib/istream-private.h                     |   2 +-
 src/lib/istream-seekable.c                    |  11 ++++++---
 src/lib/istream-sized.c                       |   9 +++----
 src/lib/istream-tee.c                         |   8 +++++-
 src/lib/istream.c                             |  29 +++++++++++++++-----------
 src/lib/istream.h                             |   4 +-
 20 files changed, 90 insertions(+), 101 deletions(-)

diffs (truncated from 624 to 300 lines):

diff -r 3cba27563159 -r 6d2be8d8891c src/lib-compression/istream-bzlib.c
--- a/src/lib-compression/istream-bzlib.c	Tue Aug 28 22:20:17 2012 +0300
+++ b/src/lib-compression/istream-bzlib.c	Tue Aug 28 22:40:57 2012 +0300
@@ -264,25 +264,24 @@
 		zstream->marked = TRUE;
 }
 
-static const struct stat *
+static int
 i_stream_bzlib_stat(struct istream_private *stream, bool exact)
 {
 	struct bzlib_istream *zstream = (struct bzlib_istream *) stream;
 	const struct stat *st;
 	size_t size;
 
-	st = i_stream_stat(stream->parent, exact);
-	if (st == NULL)
-		return NULL;
+	if (i_stream_stat(stream->parent, exact, &st) < 0)
+		return -1;
+	stream->statbuf = *st;
 
 	/* when exact=FALSE always return the parent stat's size, even if we
 	   know the exact value. this is necessary because otherwise e.g. mbox
 	   code can see two different values and think that a compressed mbox
 	   file keeps changing. */
 	if (!exact)
-		return st;
+		return 0;
 
-	stream->statbuf = *st;
 	if (zstream->stream_size == (uoff_t)-1) {
 		uoff_t old_offset = stream->istream.v_offset;
 
@@ -293,10 +292,10 @@
 
 		i_stream_seek(&stream->istream, old_offset);
 		if (zstream->stream_size == (uoff_t)-1)
-			return NULL;
+			return -1;
 	}
 	stream->statbuf.st_size = zstream->stream_size;
-	return &stream->statbuf;
+	return 0;
 }
 
 static void i_stream_bzlib_sync(struct istream_private *stream)
@@ -304,8 +303,7 @@
 	struct bzlib_istream *zstream = (struct bzlib_istream *) stream;
 	const struct stat *st;
 
-	st = i_stream_stat(stream->parent, FALSE);
-	if (st != NULL) {
+	if (i_stream_stat(stream->parent, FALSE, &st) < 0) {
 		if (memcmp(&zstream->last_parent_statbuf,
 			   st, sizeof(*st)) == 0) {
 			/* a compressed file doesn't change unexpectedly,
diff -r 3cba27563159 -r 6d2be8d8891c src/lib-compression/istream-zlib.c
--- a/src/lib-compression/istream-zlib.c	Tue Aug 28 22:20:17 2012 +0300
+++ b/src/lib-compression/istream-zlib.c	Tue Aug 28 22:40:57 2012 +0300
@@ -423,25 +423,24 @@
 		zstream->marked = TRUE;
 }
 
-static const struct stat *
+static int
 i_stream_zlib_stat(struct istream_private *stream, bool exact)
 {
 	struct zlib_istream *zstream = (struct zlib_istream *) stream;
 	const struct stat *st;
 	size_t size;
 
-	st = i_stream_stat(stream->parent, exact);
-	if (st == NULL)
-		return NULL;
+	if (i_stream_stat(stream->parent, exact, &st) < 0)
+		return -1;
+	stream->statbuf = *st;
 
 	/* when exact=FALSE always return the parent stat's size, even if we
 	   know the exact value. this is necessary because otherwise e.g. mbox
 	   code can see two different values and think that a compressed mbox
 	   file keeps changing. */
 	if (!exact)
-		return st;
+		return 0;
 
-	stream->statbuf = *st;
 	if (zstream->stream_size == (uoff_t)-1) {
 		uoff_t old_offset = stream->istream.v_offset;
 
@@ -452,10 +451,10 @@
 
 		i_stream_seek(&stream->istream, old_offset);
 		if (zstream->stream_size == (uoff_t)-1)
-			return NULL;
+			return -1;
 	}
 	stream->statbuf.st_size = zstream->stream_size;
-	return &stream->statbuf;
+	return 0;
 }
 
 static void i_stream_zlib_sync(struct istream_private *stream)
@@ -463,8 +462,7 @@
 	struct zlib_istream *zstream = (struct zlib_istream *) stream;
 	const struct stat *st;
 
-	st = i_stream_stat(stream->parent, FALSE);
-	if (st != NULL) {
+	if (i_stream_stat(stream->parent, FALSE, &st) < 0) {
 		if (memcmp(&zstream->last_parent_statbuf,
 			   st, sizeof(*st)) == 0) {
 			/* a compressed file doesn't change unexpectedly,
diff -r 3cba27563159 -r 6d2be8d8891c src/lib-fs/fs-sis.c
--- a/src/lib-fs/fs-sis.c	Tue Aug 28 22:20:17 2012 +0300
+++ b/src/lib-fs/fs-sis.c	Tue Aug 28 22:40:57 2012 +0300
@@ -158,7 +158,8 @@
 	const struct stat *st;
 	struct stat st2;
 
-	st = i_stream_stat(file->hash_input, FALSE);
+	if (i_stream_stat(file->hash_input, FALSE, &st) < 0)
+		return FALSE;
 
 	/* we can use the existing file */
 	if (fs_link(file->super->fs, file->hash_path, path) < 0) {
diff -r 3cba27563159 -r 6d2be8d8891c src/lib-mail/istream-header-filter.c
--- a/src/lib-mail/istream-header-filter.c	Tue Aug 28 22:20:17 2012 +0300
+++ b/src/lib-mail/istream-header-filter.c	Tue Aug 28 22:40:57 2012 +0300
@@ -492,7 +492,7 @@
 	i_panic("istream-header-filter sync() not implemented");
 }
 
-static const struct stat *
+static int
 i_stream_header_filter_stat(struct istream_private *stream, bool exact)
 {
 	struct header_filter_istream *mstream =
@@ -500,19 +500,21 @@
 	const struct stat *st;
 	uoff_t old_offset;
 
-	st = i_stream_stat(stream->parent, exact);
-	if (st == NULL || st->st_size == -1 || !exact)
-		return st;
+	if (i_stream_stat(stream->parent, exact, &st) < 0)
+		return -1;
+	stream->statbuf = *st;
+	if (stream->statbuf.st_size == -1 || !exact)
+		return 0;
 
+	/* fix the filtered header size */
 	old_offset = stream->istream.v_offset;
 	skip_header(mstream);
 
-	stream->statbuf = *st;
 	stream->statbuf.st_size -=
 		(off_t)mstream->header_size.physical_size -
 		(off_t)mstream->header_size.virtual_size;
 	i_stream_seek(&stream->istream, old_offset);
-	return &stream->statbuf;
+	return 0;
 }
 
 #undef i_stream_create_header_filter
diff -r 3cba27563159 -r 6d2be8d8891c src/lib-storage/index/maildir/maildir-mail.c
--- a/src/lib-storage/index/maildir/maildir-mail.c	Tue Aug 28 22:20:17 2012 +0300
+++ b/src/lib-storage/index/maildir/maildir-mail.c	Tue Aug 28 22:40:57 2012 +0300
@@ -125,8 +125,7 @@
 
 	if (imail->data.stream != NULL) {
 		mail->transaction->stats.fstat_lookup_count++;
-		stp = i_stream_stat(imail->data.stream, FALSE);
-		if (stp == NULL)
+		if (i_stream_stat(imail->data.stream, FALSE, &stp) < 0)
 			return -1;
 		*st_r = *stp;
 	} else if (!mail->saving) {
diff -r 3cba27563159 -r 6d2be8d8891c src/lib-storage/index/mbox/istream-raw-mbox.c
--- a/src/lib-storage/index/mbox/istream-raw-mbox.c	Tue Aug 28 22:20:17 2012 +0300
+++ b/src/lib-storage/index/mbox/istream-raw-mbox.c	Tue Aug 28 22:40:57 2012 +0300
@@ -406,21 +406,20 @@
 	rstream->input_peak_offset = 0;
 }
 
-static const struct stat *
+static int
 i_stream_raw_mbox_stat(struct istream_private *stream, bool exact)
 {
 	const struct stat *st;
 	struct raw_mbox_istream *rstream = (struct raw_mbox_istream *)stream;
 
-	st = i_stream_stat(stream->parent, exact);
-	if (st == NULL)
-		return NULL;
+	if (i_stream_stat(stream->parent, exact, &st) < 0)
+		return -1;
 
 	stream->statbuf = *st;
 	stream->statbuf.st_size =
 		!exact && rstream->seeked && rstream->mail_size != (uoff_t)-1 ?
 		(off_t)rstream->mail_size : -1;
-	return &stream->statbuf;
+	return 0;
 }
 
 struct istream *i_stream_create_raw_mbox(struct istream *input)
diff -r 3cba27563159 -r 6d2be8d8891c src/lib-storage/index/mbox/mbox-sync.c
--- a/src/lib-storage/index/mbox/mbox-sync.c	Tue Aug 28 22:20:17 2012 +0300
+++ b/src/lib-storage/index/mbox/mbox-sync.c	Tue Aug 28 22:40:57 2012 +0300
@@ -1427,8 +1427,7 @@
 	const struct stat *st;
 	uint32_t first_recent_uid, seq, seq2;
 
-	st = i_stream_stat(sync_ctx->file_input, FALSE);
-	if (st == NULL) {
+	if (i_stream_stat(sync_ctx->file_input, FALSE, &st) < 0) {
 		mbox_set_syscall_error(sync_ctx->mbox, "i_stream_stat()");
 		return -1;
 	}
@@ -1456,8 +1455,7 @@
 				return -1;
 			}
 
-			st = i_stream_stat(sync_ctx->file_input, FALSE);
-			if (st == NULL) {
+			if (i_stream_stat(sync_ctx->file_input, FALSE, &st) < 0) {
 				mbox_set_syscall_error(sync_ctx->mbox,
 						       "i_stream_stat()");
 				return -1;
@@ -1562,8 +1560,7 @@
 	unsigned int i;
 	int ret, partial;
 
-	st = i_stream_stat(sync_ctx->file_input, FALSE);
-	if (st == NULL) {
+	if (i_stream_stat(sync_ctx->file_input, FALSE, &st) < 0) {
 		mbox_set_syscall_error(sync_ctx->mbox, "i_stream_stat()");
 		return -1;
 	}
@@ -1706,8 +1703,7 @@
 
 	if (mbox->mbox_file_stream != NULL && mbox->mbox_fd == -1) {
 		/* read-only stream */
-		st = i_stream_stat(mbox->mbox_file_stream, FALSE);
-		if (st == NULL) {
+		if (i_stream_stat(mbox->mbox_file_stream, FALSE, &st) < 0) {
 			if (errno == ENOENT) {
 				mailbox_set_deleted(&mbox->box);
 				return 0;
diff -r 3cba27563159 -r 6d2be8d8891c src/lib-storage/index/raw/raw-mail.c
--- a/src/lib-storage/index/raw/raw-mail.c	Tue Aug 28 22:20:17 2012 +0300
+++ b/src/lib-storage/index/raw/raw-mail.c	Tue Aug 28 22:40:57 2012 +0300
@@ -20,8 +20,7 @@
 	}
 
 	mail->transaction->stats.fstat_lookup_count++;
-	st = i_stream_stat(mail->box->input, TRUE);
-	if (st == NULL) {
+	if (i_stream_stat(mail->box->input, TRUE, &st) < 0) {
 		mail_storage_set_critical(mail->box->storage,
 					  "stat(%s) failed: %m",
 					  i_stream_get_name(mail->box->input));
diff -r 3cba27563159 -r 6d2be8d8891c src/lib-storage/list/subscription-file.c
--- a/src/lib-storage/list/subscription-file.c	Tue Aug 28 22:20:17 2012 +0300
+++ b/src/lib-storage/list/subscription-file.c	Tue Aug 28 22:40:57 2012 +0300
@@ -244,7 +244,7 @@
 	if (ctx->failed)
 		return -1;
 
-	if ((st = i_stream_stat(ctx->input, FALSE)) == NULL) {
+	if (i_stream_stat(ctx->input, FALSE, &st) < 0) {
 		ctx->failed = TRUE;
 		return -1;
 	}
diff -r 3cba27563159 -r 6d2be8d8891c src/lib/istream-chain.c
--- a/src/lib/istream-chain.c	Tue Aug 28 22:20:17 2012 +0300
+++ b/src/lib/istream-chain.c	Tue Aug 28 22:40:57 2012 +0300
@@ -235,13 +235,6 @@
 	return ret;
 }
 
-static const struct stat *
-i_stream_chain_stat(struct istream_private *stream ATTR_UNUSED,
-	bool exact ATTR_UNUSED)
-{
-	return NULL;
-}
-
 struct istream *i_stream_create_chain(struct istream_chain **chain_r)
 {
 	struct chain_istream *cstream;
@@ -255,7 +248,6 @@
 		i_stream_chain_set_max_buffer_size;
 
 	cstream->istream.read = i_stream_chain_read;
-	cstream->istream.stat = i_stream_chain_stat;
 
 	cstream->istream.istream.readable_fd = FALSE;


More information about the dovecot-cvs mailing list