[evolution-data-server] Treat empty cache files as nonexistent.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-data-server] Treat empty cache files as nonexistent.
- Date: Wed, 19 Jan 2011 02:34:19 +0000 (UTC)
commit 5fa3acb33c342cfc4f096d053d2bd5bbdae87fa1
Author: Matthew Barnes <mbarnes redhat com>
Date: Tue Jan 18 21:27:37 2011 -0500
Treat empty cache files as nonexistent.
For some reason, cached mail message files are sometimes winding up as
zero-length files. Still need to figure out how this is happening, but
in the meantime teach Camel to disregard zero-length cache files.
camel/camel-data-cache.c | 9 +++++-
camel/providers/imapx/camel-imapx-server.c | 39 +++++++++++----------------
2 files changed, 23 insertions(+), 25 deletions(-)
---
diff --git a/camel/camel-data-cache.c b/camel/camel-data-cache.c
index b288db6..ed663d9 100644
--- a/camel/camel-data-cache.c
+++ b/camel/camel-data-cache.c
@@ -420,8 +420,13 @@ camel_data_cache_get (CamelDataCache *cdc,
real = data_cache_path (cdc, FALSE, path, key);
stream = camel_object_bag_reserve (cdc->priv->busy_bag, real);
if (!stream) {
- stream = camel_stream_fs_new_with_name (
- real, O_RDWR, 0600, error);
+ struct stat st;
+
+ /* Return NULL if the file is empty. */
+ if (g_stat (real, &st) == 0 && st.st_size > 0)
+ stream = camel_stream_fs_new_with_name (
+ real, O_RDWR, 0600, error);
+
if (stream)
camel_object_bag_add (cdc->priv->busy_bag, real, stream);
else
diff --git a/camel/providers/imapx/camel-imapx-server.c b/camel/providers/imapx/camel-imapx-server.c
index 029e8ee..dda55ee 100644
--- a/camel/providers/imapx/camel-imapx-server.c
+++ b/camel/providers/imapx/camel-imapx-server.c
@@ -5180,19 +5180,11 @@ imapx_server_get_message (CamelIMAPXServer *is,
CamelStream *stream = NULL, *tmp_stream;
CamelIMAPXFolder *ifolder = (CamelIMAPXFolder *) folder;
CamelIMAPXJob *job;
- gchar *cache_file = NULL;
CamelMessageInfo *mi;
gboolean registered;
EFlag *flag = NULL;
gboolean success;
- cache_file = camel_data_cache_get_filename (ifolder->cache, "cur", uid, NULL);
- if (g_file_test (cache_file, G_FILE_TEST_EXISTS)) {
- g_free (cache_file);
- return NULL;
- }
- g_free (cache_file);
-
QUEUE_LOCK (is);
if ((job = imapx_is_job_in_queue (is, folder, IMAPX_JOB_GET_MESSAGE, uid))) {
@@ -5205,11 +5197,11 @@ imapx_server_get_message (CamelIMAPXServer *is,
e_flag_wait (flag);
- stream = camel_data_cache_get (ifolder->cache, "cur", uid, NULL);
- if (!stream)
- g_set_error (
- error, CAMEL_IMAPX_ERROR, 1,
- "Could not retrieve the message");
+ stream = camel_data_cache_get (
+ ifolder->cache, "cur", uid, error);
+ if (stream == NULL)
+ g_prefix_error (
+ error, "Could not retrieve the message: ");
return stream;
}
@@ -5291,12 +5283,17 @@ camel_imapx_server_sync_message (CamelIMAPXServer *is,
gchar *cache_file = NULL;
CamelIMAPXFolder *ifolder = (CamelIMAPXFolder *) folder;
CamelStream *stream;
+ gboolean is_cached;
+ struct stat st;
+
+ /* Check if the cache file already exists and is non-empty. */
+ cache_file = camel_data_cache_get_filename (
+ ifolder->cache, "cur", uid, NULL);
+ is_cached = (g_stat (cache_file, &st) == 0 && st.st_size > 0);
+ g_free (cache_file);
- cache_file = camel_data_cache_get_filename (ifolder->cache, "cur", uid, NULL);
- if (g_file_test (cache_file, G_FILE_TEST_EXISTS)) {
- g_free (cache_file);
+ if (is_cached)
return TRUE;
- }
stream = imapx_server_get_message (
is, folder, uid,
@@ -5361,13 +5358,9 @@ camel_imapx_server_append_message (CamelIMAPXServer *is,
/* chen cleanup this later */
uid = imapx_get_temp_uid ();
- stream = camel_data_cache_add (ifolder->cache, "new", uid, NULL);
+ stream = camel_data_cache_add (ifolder->cache, "new", uid, error);
if (stream == NULL) {
- g_set_error (
- error, G_IO_ERROR,
- g_io_error_from_errno (errno),
- _("Cannot create spool file: %s"),
- g_strerror (errno));
+ g_prefix_error (error, _("Cannot create spool file: "));
g_free (uid);
return FALSE;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]