[evolution-data-server] CamelGpgContext: Use g_file_new_tmp() in swrite().
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] CamelGpgContext: Use g_file_new_tmp() in swrite().
- Date: Tue, 1 Oct 2013 22:14:26 +0000 (UTC)
commit 91e35ae2d673cd54e897831545cac7da8499a32c
Author: Matthew Barnes <mbarnes redhat com>
Date: Tue Oct 1 17:59:12 2013 -0400
CamelGpgContext: Use g_file_new_tmp() in swrite().
g_file_new_tmp() creates a GFileIOStream, which we then wrap in a
CamelStream for use with CamelDataWrapper.
camel/camel-gpg-context.c | 46 ++++++++++++++++++++++++++------------------
1 files changed, 27 insertions(+), 19 deletions(-)
---
diff --git a/camel/camel-gpg-context.c b/camel/camel-gpg-context.c
index 33453e1..bb48a32 100644
--- a/camel/camel-gpg-context.c
+++ b/camel/camel-gpg-context.c
@@ -1475,39 +1475,47 @@ swrite (CamelMimePart *sigpart,
GCancellable *cancellable,
GError **error)
{
- CamelStream *ostream;
+ GFile *file;
+ GFileIOStream *base_stream = NULL;
+ CamelStream *stream = NULL;
CamelDataWrapper *wrapper;
- gchar *template;
- gint fd, ret;
+ gchar *path = NULL;
+ gint ret;
- template = g_build_filename (g_get_tmp_dir (), "evolution-pgp.XXXXXX", NULL);
- if ((fd = g_mkstemp (template)) == -1) {
- g_free (template);
- return NULL;
+ file = g_file_new_tmp ("evolution-pgp.XXXXXX", &base_stream, error);
+
+ /* Sanity check. */
+ g_return_val_if_fail (
+ ((file != NULL) && (base_stream != NULL)) ||
+ ((file == NULL) && (base_stream == NULL)), NULL);
+
+ if (base_stream != NULL) {
+ stream = camel_stream_new (G_IO_STREAM (base_stream));
+ g_object_unref (base_stream);
}
- ostream = camel_stream_fs_new_with_fd (fd);
+ if (stream == NULL)
+ return NULL;
+
wrapper = camel_medium_get_content (CAMEL_MEDIUM (sigpart));
- if (!wrapper)
+ if (wrapper == NULL)
wrapper = CAMEL_DATA_WRAPPER (sigpart);
ret = camel_data_wrapper_decode_to_stream_sync (
- wrapper, ostream, cancellable, error);
+ wrapper, stream, cancellable, error);
if (ret != -1) {
- ret = camel_stream_flush (ostream, cancellable, error);
+ ret = camel_stream_flush (stream, cancellable, error);
if (ret != -1)
- ret = camel_stream_close (ostream, cancellable, error);
+ ret = camel_stream_close (stream, cancellable, error);
}
- g_object_unref (ostream);
+ if (ret != -1)
+ path = g_file_get_path (file);
- if (ret == -1) {
- g_unlink (template);
- g_free (template);
- return NULL;
- }
+ g_object_unref (file);
+ g_object_unref (stream);
- return template;
+ return path;
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]