[evolution/wip/webkit2] Bug 762759 - Crash on start when ~/.cache is not accessible



commit 0fd2a46d214945fd3032277cc355661c85226379
Author: Milan Crha <mcrha redhat com>
Date:   Mon May 30 16:03:18 2016 +0200

    Bug 762759 - Crash on start when ~/.cache is not accessible

 mail/e-http-request.c                              |   91 ++++++++++++--------
 .../web-extension/e-html-editor-web-extension.c    |   15 ++--
 2 files changed, 65 insertions(+), 41 deletions(-)
---
diff --git a/mail/e-http-request.c b/mail/e-http-request.c
index e0d50a2..cda9556 100644
--- a/mail/e-http-request.c
+++ b/mail/e-http-request.c
@@ -269,11 +269,14 @@ e_http_request_process_sync (EContentRequest *request,
        /* Open Evolution's cache */
        user_cache_dir = e_get_user_cache_dir ();
        cache = camel_data_cache_new (user_cache_dir, NULL);
-       camel_data_cache_set_expire_age (cache, 24 * 60 * 60);
-       camel_data_cache_set_expire_access (cache, 2 * 60 * 60);
+       if (cache) {
+               camel_data_cache_set_expire_age (cache, 24 * 60 * 60);
+               camel_data_cache_set_expire_access (cache, 2 * 60 * 60);
+
+               cache_stream = camel_data_cache_get (cache, "http", uri_md5, NULL);
+       } else
+               cache_stream = NULL;
 
-       /* Found item in cache! */
-       cache_stream = camel_data_cache_get (cache, "http", uri_md5, NULL);
        if (cache_stream != NULL) {
                gssize len;
 
@@ -433,38 +436,56 @@ e_http_request_process_sync (EContentRequest *request,
                        goto cleanup;
                }
 
-               /* Write the response body to cache */
-               cache_stream = camel_data_cache_add (
-                       cache, "http", uri_md5, error);
-               if (cache_stream) {
-                       GOutputStream *output_stream;
-
-                       output_stream =
-                               g_io_stream_get_output_stream (cache_stream);
-
-                       success = g_output_stream_write_all (
-                               output_stream,
-                               message->response_body->data,
-                               message->response_body->length,
-                               NULL, cancellable, error);
-
-                       g_io_stream_close (cache_stream, NULL, NULL);
-                       g_object_unref (cache_stream);
-
-                       if (success) {
-                               /* Send the response body to WebKit */
-                               stream = g_memory_input_stream_new_from_data (
-                                       g_memdup (
-                                               message->response_body->data,
-                                               message->response_body->length),
+               if (cache) {
+                       cache_stream = camel_data_cache_add (
+                               cache, "http", uri_md5, error);
+                       if (error != NULL) {
+                               g_warning (
+                                       "Failed to create cache file for '%s': %s",
+                                       uri, (*error)->message);
+                               g_clear_error (error);
+                       } else {
+                               GOutputStream *output_stream;
+
+                               output_stream =
+                                       g_io_stream_get_output_stream (cache_stream);
+
+                               success = g_output_stream_write_all (
+                                       output_stream,
+                                       message->response_body->data,
                                        message->response_body->length,
-                                       (GDestroyNotify) g_free);
-
-                               *out_stream = stream;
-                               *out_stream_length = message->response_body->length;
-                               *out_mime_type = g_strdup (
-                                       soup_message_headers_get_content_type (
-                                               message->response_headers, NULL));
+                                       NULL, cancellable, error);
+
+                               g_io_stream_close (cache_stream, NULL, NULL);
+                               g_object_unref (cache_stream);
+
+                               if (error != NULL) {
+                                       if (!g_error_matches (*error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+                                               g_warning (
+                                                       "Failed to write data to cache stream: %s",
+                                                       (*error)->message);
+                                       g_clear_error (error);
+                                       g_object_unref (message);
+                                       g_object_unref (temp_session);
+                                       g_main_context_unref (context);
+                                       goto cleanup;
+                               }
+
+                               if (success) {
+                                       /* Send the response body to WebKit */
+                                       stream = g_memory_input_stream_new_from_data (
+                                               g_memdup (
+                                                       message->response_body->data,
+                                                       message->response_body->length),
+                                               message->response_body->length,
+                                               (GDestroyNotify) g_free);
+
+                                       *out_stream = stream;
+                                       *out_stream_length = message->response_body->length;
+                                       *out_mime_type = g_strdup (
+                                               soup_message_headers_get_content_type (
+                                                       message->response_headers, NULL));
+                               }
                        }
                }
 
diff --git a/modules/webkit-content-editor/web-extension/e-html-editor-web-extension.c 
b/modules/webkit-content-editor/web-extension/e-html-editor-web-extension.c
index 1e07f8a..e0d65da 100644
--- a/modules/webkit-content-editor/web-extension/e-html-editor-web-extension.c
+++ b/modules/webkit-content-editor/web-extension/e-html-editor-web-extension.c
@@ -2634,7 +2634,8 @@ image_exists_in_cache (const gchar *image_uri)
        gchar *hash;
        gboolean exists = FALSE;
 
-       g_return_val_if_fail (emd_global_http_cache != NULL, FALSE);
+       if (!emd_global_http_cache)
+               return FALSE;
 
        hash = g_compute_checksum_for_string (G_CHECKSUM_MD5, image_uri, -1);
        filename = camel_data_cache_get_filename (
@@ -2912,11 +2913,13 @@ e_html_editor_web_extension_initialize (EHTMLEditorWebExtension *extension,
                emd_global_http_cache = camel_data_cache_new (
                        e_get_user_cache_dir (), NULL);
 
-               /* cache expiry - 2 hour access, 1 day max */
-               camel_data_cache_set_expire_age (
-                       emd_global_http_cache, 24 * 60 * 60);
-               camel_data_cache_set_expire_access (
-                       emd_global_http_cache, 2 * 60 * 60);
+               if (emd_global_http_cache) {
+                       /* cache expiry - 2 hour access, 1 day max */
+                       camel_data_cache_set_expire_age (
+                               emd_global_http_cache, 24 * 60 * 60);
+                       camel_data_cache_set_expire_access (
+                               emd_global_http_cache, 2 * 60 * 60);
+               }
        }
 
        g_signal_connect (


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]