[evolution-data-server] camel_data_cache_get: Improve empty file handling.



commit 608d9ccabb9246418dc96cde1c49d12ee2f0e02a
Author: Matthew Barnes <mbarnes redhat com>
Date:   Tue Jun 19 17:03:07 2012 -0400

    camel_data_cache_get: Improve empty file handling.
    
    When an empty cache file is detected, set a GError with a descriptive
    error message in addition to returning NULL.

 camel/camel-data-cache.c |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
---
diff --git a/camel/camel-data-cache.c b/camel/camel-data-cache.c
index 3824356..7e58d9d 100644
--- a/camel/camel-data-cache.c
+++ b/camel/camel-data-cache.c
@@ -430,15 +430,20 @@ 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) {
+	if (stream == NULL) {
 		struct stat st;
 
-		/* Return NULL if the file is empty. */
-		if (g_stat (real, &st) == 0 && st.st_size > 0)
+		/* An empty cache file is useless.  Return an error. */
+		if (g_stat (real, &st) == 0 && st.st_size == 0) {
+			g_set_error (
+				error, CAMEL_ERROR, CAMEL_ERROR_GENERIC,
+				"%s: %s", _("Empty cache file"), real);
+		} else {
 			stream = camel_stream_fs_new_with_name (
 				real, O_RDWR, 0600, error);
+		}
 
-		if (stream)
+		if (stream != NULL)
 			camel_object_bag_add (cdc->priv->busy_bag, real, stream);
 		else
 			camel_object_bag_abort (cdc->priv->busy_bag, real);



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