[evolution-data-server] Bug 787341 - [IMAPx] Report message download progress
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Bug 787341 - [IMAPx] Report message download progress
- Date: Mon, 11 Sep 2017 14:12:26 +0000 (UTC)
commit 279953b58dc93b2c5997a5aca8d1908776b9a080
Author: Milan Crha <mcrha redhat com>
Date: Mon Sep 11 16:12:50 2017 +0200
Bug 787341 - [IMAPx] Report message download progress
.../providers/imapx/camel-imapx-input-stream.c | 17 +++--
src/camel/providers/imapx/camel-imapx-server.c | 57 +------------------
src/camel/providers/imapx/camel-imapx-utils.c | 60 ++++++++++++++++++++
src/camel/providers/imapx/camel-imapx-utils.h | 6 ++
4 files changed, 77 insertions(+), 63 deletions(-)
---
diff --git a/src/camel/providers/imapx/camel-imapx-input-stream.c
b/src/camel/providers/imapx/camel-imapx-input-stream.c
index b71bd74..4ebf37c 100644
--- a/src/camel/providers/imapx/camel-imapx-input-stream.c
+++ b/src/camel/providers/imapx/camel-imapx-input-stream.c
@@ -570,13 +570,16 @@ camel_imapx_input_stream_nstring_bytes (CamelIMAPXInputStream *is,
/* If len is big, we could
* automatically use a file backing. */
camel_imapx_input_stream_set_literal (is, len);
- output_stream =
- g_memory_output_stream_new_resizable ();
- bytes_written = g_output_stream_splice (
- output_stream,
- G_INPUT_STREAM (is),
- G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET,
- cancellable, error);
+ output_stream = g_memory_output_stream_new_resizable ();
+ if (len > 1024) {
+ bytes_written = imapx_splice_with_progress (output_stream, G_INPUT_STREAM
(is),
+ len, cancellable, error);
+ if (!g_output_stream_close (output_stream, cancellable, error))
+ bytes_written = -1;
+ } else {
+ bytes_written = g_output_stream_splice (output_stream, G_INPUT_STREAM (is),
+ G_OUTPUT_STREAM_SPLICE_CLOSE_TARGET, cancellable, error);
+ }
success = (bytes_written >= 0);
if (success) {
*out_bytes =
diff --git a/src/camel/providers/imapx/camel-imapx-server.c b/src/camel/providers/imapx/camel-imapx-server.c
index 8af042b..adcbc01 100644
--- a/src/camel/providers/imapx/camel-imapx-server.c
+++ b/src/camel/providers/imapx/camel-imapx-server.c
@@ -2017,61 +2017,6 @@ exit:
return success;
}
-static gssize
-imapx_server_write_file_with_progress (GOutputStream *output_stream,
- GInputStream *input_stream,
- goffset file_size,
- GCancellable *cancellable,
- GError **error)
-{
- gssize n_read;
- gsize bytes_copied, n_written;
- gchar buffer[8192];
- goffset file_offset;
- gboolean res;
-
- g_return_val_if_fail (G_IS_OUTPUT_STREAM (output_stream), -1);
- g_return_val_if_fail (G_IS_INPUT_STREAM (input_stream), -1);
-
- if (g_cancellable_set_error_if_cancelled (cancellable, error))
- return FALSE;
-
- file_offset = 0;
- bytes_copied = 0;
- res = TRUE;
- do {
- n_read = g_input_stream_read (input_stream, buffer, sizeof (buffer), cancellable, error);
- if (n_read == -1) {
- res = FALSE;
- break;
- }
-
- if (n_read == 0)
- break;
-
- if (!g_output_stream_write_all (output_stream, buffer, n_read, &n_written, cancellable,
error) || n_written == -1) {
- res = FALSE;
- break;
- }
-
- file_offset += n_read;
-
- if (file_size > 0) {
- gdouble divd = (gdouble) file_offset / (gdouble) file_size;
- camel_operation_progress (cancellable, (gint) (100 * divd));
- }
-
- bytes_copied += n_written;
- if (bytes_copied > G_MAXSSIZE)
- bytes_copied = G_MAXSSIZE;
- } while (res);
-
- if (res)
- return bytes_copied;
-
- return -1;
-}
-
/* handle any continuation requests
* either data continuations, or auth continuation */
static gboolean
@@ -2198,7 +2143,7 @@ imapx_continuation (CamelIMAPXServer *is,
g_mutex_lock (&is->priv->stream_lock);
- n_bytes_written = imapx_server_write_file_with_progress (
+ n_bytes_written = imapx_splice_with_progress (
output_stream, G_INPUT_STREAM (file_input_stream),
file_size, cancellable, error);
diff --git a/src/camel/providers/imapx/camel-imapx-utils.c b/src/camel/providers/imapx/camel-imapx-utils.c
index 962336d..ae5b7cf 100644
--- a/src/camel/providers/imapx/camel-imapx-utils.c
+++ b/src/camel/providers/imapx/camel-imapx-utils.c
@@ -3329,3 +3329,63 @@ imapx_util_all_is_ascii (const gchar *str)
return all_ascii;
}
+
+gssize
+imapx_splice_with_progress (GOutputStream *output_stream,
+ GInputStream *input_stream,
+ goffset file_size,
+ GCancellable *cancellable,
+ GError **error)
+{
+ gssize n_read;
+ gsize bytes_copied, n_written;
+ gchar buffer[8192];
+ goffset file_offset;
+ gboolean res;
+
+ g_return_val_if_fail (G_IS_OUTPUT_STREAM (output_stream), -1);
+ g_return_val_if_fail (G_IS_INPUT_STREAM (input_stream), -1);
+
+ if (g_cancellable_set_error_if_cancelled (cancellable, error))
+ return FALSE;
+
+ file_offset = 0;
+ bytes_copied = 0;
+ res = TRUE;
+ do {
+ n_read = g_input_stream_read (input_stream, buffer, sizeof (buffer), cancellable, error);
+ if (n_read == -1) {
+ res = FALSE;
+ break;
+ }
+
+ if (n_read == 0)
+ break;
+
+ if (!g_output_stream_write_all (output_stream, buffer, n_read, &n_written, cancellable,
error) || n_written == -1) {
+ res = FALSE;
+ break;
+ }
+
+ file_offset += n_read;
+
+ if (file_size > 0) {
+ gdouble divd = (gdouble) file_offset / (gdouble) file_size;
+ if (divd > 1.0)
+ divd = 1.0;
+ camel_operation_progress (cancellable, (gint) (100 * divd));
+ }
+
+ bytes_copied += n_written;
+ if (bytes_copied > G_MAXSSIZE)
+ bytes_copied = G_MAXSSIZE;
+ } while (res);
+
+ if (file_size > 0)
+ camel_operation_progress (cancellable, -1);
+
+ if (res)
+ return bytes_copied;
+
+ return -1;
+}
diff --git a/src/camel/providers/imapx/camel-imapx-utils.h b/src/camel/providers/imapx/camel-imapx-utils.h
index 75f4808..04c73cb 100644
--- a/src/camel/providers/imapx/camel-imapx-utils.h
+++ b/src/camel/providers/imapx/camel-imapx-utils.h
@@ -397,6 +397,12 @@ gchar * imapx_get_temp_uid (void);
gboolean imapx_util_all_is_ascii (const gchar *str);
+gssize imapx_splice_with_progress (GOutputStream *output_stream,
+ GInputStream *input_stream,
+ goffset file_size,
+ GCancellable *cancellable,
+ GError **error);
+
G_END_DECLS
#endif /* CAMEL_IMAPX_UTILS_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]