dovecot-2.2: lib: Added iostream_temp_create_named()

dovecot at dovecot.org dovecot at dovecot.org
Fri Nov 14 00:16:53 UTC 2014


details:   http://hg.dovecot.org/dovecot-2.2/rev/4e10ca59e907
changeset: 18084:4e10ca59e907
user:      Timo Sirainen <tss at iki.fi>
date:      Fri Nov 14 01:19:37 2014 +0200
description:
lib: Added iostream_temp_create_named()

diffstat:

 src/lib/iostream-temp.c |  36 +++++++++++++++++++++++++++++-------
 src/lib/iostream-temp.h |   3 +++
 2 files changed, 32 insertions(+), 7 deletions(-)

diffs (107 lines):

diff -r 8565c72f73ec -r 4e10ca59e907 src/lib/iostream-temp.c
--- a/src/lib/iostream-temp.c	Thu Nov 13 11:29:41 2014 +0200
+++ b/src/lib/iostream-temp.c	Fri Nov 14 01:19:37 2014 +0200
@@ -21,6 +21,7 @@
 
 	struct istream *dupstream;
 	uoff_t dupstream_offset, dupstream_start_offset;
+	char *name;
 
 	buffer_t *buf;
 	int fd;
@@ -39,6 +40,7 @@
 	if (tstream->buf != NULL)
 		buffer_free(&tstream->buf);
 	i_free(tstream->temp_path_prefix);
+	i_free(tstream->name);
 }
 
 static int o_stream_temp_move_to_fd(struct temp_ostream *tstream)
@@ -214,6 +216,13 @@
 struct ostream *iostream_temp_create(const char *temp_path_prefix,
 				     enum iostream_temp_flags flags)
 {
+	return iostream_temp_create_named(temp_path_prefix, flags, "");
+}
+
+struct ostream *iostream_temp_create_named(const char *temp_path_prefix,
+					   enum iostream_temp_flags flags,
+					   const char *name)
+{
 	struct temp_ostream *tstream;
 	struct ostream *output;
 
@@ -228,7 +237,14 @@
 	tstream->fd = -1;
 
 	output = o_stream_create(&tstream->ostream, NULL, -1);
-	o_stream_set_name(output, "(temp iostream)");
+	tstream->name = i_strdup(name);
+	if (name[0] == '\0') {
+		o_stream_set_name(output, t_strdup_printf(
+			"(temp iostream in %s)", temp_path_prefix));
+	} else {
+		o_stream_set_name(output, t_strdup_printf(
+			"(temp iostream in %s for %s)", temp_path_prefix, name));
+	}
 	return output;
 }
 
@@ -244,8 +260,14 @@
 		(struct temp_ostream *)(*output)->real_stream;
 	struct istream *input, *input2;
 	uoff_t abs_offset, size;
+	const char *for_path;
 	int fd;
 
+	if (tstream->name[0] == '\0')
+		for_path = "";
+	else
+		for_path = t_strdup_printf(" for %s", tstream->name);
+
 	if (tstream->dupstream != NULL && !tstream->dupstream->closed) {
 		abs_offset = tstream->dupstream->real_stream->abs_start_offset +
 			tstream->dupstream_start_offset;
@@ -261,8 +283,8 @@
 			i_stream_unref(&input2);
 		}
 		i_stream_set_name(input, t_strdup_printf(
-			"(Temp file in %s, from %s)", tstream->temp_path_prefix,
-			i_stream_get_name(tstream->dupstream)));
+			"(Temp file in %s%s, from %s)", tstream->temp_path_prefix,
+			for_path, i_stream_get_name(tstream->dupstream)));
 		i_stream_unref(&tstream->dupstream);
 	} else if (tstream->dupstream != NULL) {
 		/* return the original failed stream. */
@@ -271,14 +293,14 @@
 		int fd = tstream->fd;
 		input = i_stream_create_fd_autoclose(&tstream->fd, max_buffer_size);
 		i_stream_set_name(input, t_strdup_printf(
-			"(Temp file fd %d in %s, %"PRIuUOFF_T" bytes)",
-			fd, tstream->temp_path_prefix, tstream->fd_size));
+			"(Temp file fd %d in %s%s, %"PRIuUOFF_T" bytes)",
+			fd, tstream->temp_path_prefix, for_path, tstream->fd_size));
 	} else {
 		input = i_stream_create_from_data(tstream->buf->data,
 						  tstream->buf->used);
 		i_stream_set_name(input, t_strdup_printf(
-			"(Temp buffer in %s, %"PRIuSIZE_T" bytes)",
-			tstream->temp_path_prefix, tstream->buf->used));
+			"(Temp buffer in %s%s, %"PRIuSIZE_T" bytes)",
+			tstream->temp_path_prefix, for_path, tstream->buf->used));
 		i_stream_add_destroy_callback(input, iostream_temp_buf_destroyed,
 					      tstream->buf);
 		tstream->buf = NULL;
diff -r 8565c72f73ec -r 4e10ca59e907 src/lib/iostream-temp.h
--- a/src/lib/iostream-temp.h	Thu Nov 13 11:29:41 2014 +0200
+++ b/src/lib/iostream-temp.h	Fri Nov 14 01:19:37 2014 +0200
@@ -12,6 +12,9 @@
    memory, and later to a temporary file that is immediately unlinked. */
 struct ostream *iostream_temp_create(const char *temp_path_prefix,
 				     enum iostream_temp_flags flags);
+struct ostream *iostream_temp_create_named(const char *temp_path_prefix,
+					   enum iostream_temp_flags flags,
+					   const char *name);
 /* Finished writing to stream. Return input stream for it and free the
    output stream. */
 struct istream *iostream_temp_finish(struct ostream **output,


More information about the dovecot-cvs mailing list