[evolution] Bug 762759 - Crash on start when ~/.cache is not accessible
- From: Milan Crha <mcrha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution] Bug 762759 - Crash on start when ~/.cache is not accessible
- Date: Thu, 3 Mar 2016 18:03:42 +0000 (UTC)
commit 78ab9b1133088518d871f26b80172536cac903a5
Author: Milan Crha <mcrha redhat com>
Date: Thu Mar 3 19:03:08 2016 +0100
Bug 762759 - Crash on start when ~/.cache is not accessible
e-util/e-html-editor-view.c | 15 +++++---
mail/e-http-request.c | 73 +++++++++++++++++++++++-------------------
mail/e-mail-display.c | 26 ++++++++++-----
3 files changed, 67 insertions(+), 47 deletions(-)
---
diff --git a/e-util/e-html-editor-view.c b/e-util/e-html-editor-view.c
index 447d324..4245f12 100644
--- a/e-util/e-html-editor-view.c
+++ b/e-util/e-html-editor-view.c
@@ -6171,7 +6171,8 @@ html_editor_view_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 (
@@ -11620,11 +11621,13 @@ e_html_editor_view_init (EHTMLEditorView *view)
user_cache_dir = e_get_user_cache_dir ();
emd_global_http_cache = camel_data_cache_new (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);
+ }
}
}
diff --git a/mail/e-http-request.c b/mail/e-http-request.c
index 7be9f55..488732a 100644
--- a/mail/e-http-request.c
+++ b/mail/e-http-request.c
@@ -246,11 +246,16 @@ handle_http_request (GSimpleAsyncResult *res,
/* 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;
@@ -413,38 +418,40 @@ handle_http_request (GSimpleAsyncResult *res,
/* Write the response body to cache */
error = NULL;
- 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);
-
- 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 (cache) {
+ cache_stream = camel_data_cache_add (
+ cache, "http", uri_md5, &error);
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_warning (
+ "Failed to create cache file for '%s': %s",
+ uri, error->message);
g_clear_error (&error);
- g_object_unref (message);
- g_object_unref (temp_session);
- g_main_context_unref (context);
- goto cleanup;
+ } else {
+ GOutputStream *output_stream;
+
+ output_stream =
+ g_io_stream_get_output_stream (cache_stream);
+
+ 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 (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;
+ }
}
}
diff --git a/mail/e-mail-display.c b/mail/e-mail-display.c
index fd47533..03b7885 100644
--- a/mail/e-mail-display.c
+++ b/mail/e-mail-display.c
@@ -266,7 +266,8 @@ mail_display_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 (
@@ -2039,14 +2040,23 @@ e_mail_display_init (EMailDisplay *display)
E_WEB_VIEW (display), E_TYPE_STOCK_REQUEST);
if (emd_global_http_cache == NULL) {
- user_cache_dir = e_get_user_cache_dir ();
- emd_global_http_cache = camel_data_cache_new (user_cache_dir, NULL);
+ GError *error = 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);
+ user_cache_dir = e_get_user_cache_dir ();
+ emd_global_http_cache = camel_data_cache_new (user_cache_dir, &error);
+
+ 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);
+ } else {
+ e_alert_submit (
+ E_ALERT_SINK (display), "mail:folder-open",
+ error ? error->message : _("Unknown error"), NULL);
+ g_clear_error (&error);
+ }
}
g_mutex_init (&display->priv->remote_content_lock);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]