** Fix for bug #545081
authorSrinivasa Ragavan <sragavan@novell.com>
Thu, 31 Jul 2008 10:31:51 +0000 (10:31 +0000)
committerSrinivasa Ragavan <sragavan@src.gnome.org>
Thu, 31 Jul 2008 10:31:51 +0000 (10:31 +0000)
2008-07-31  Srinivasa Ragavan  <sragavan@novell.com>

** Fix for bug #545081

* camel/providers/imap/camel-imap-message-cache.c: Add a new simple
delete cache function.
* camel/providers/imap/camel-imap-message-cache.h:
* camel/providers/imap/camel-imap-store.c: Now forget the folder from
DB.

svn path=/trunk/; revision=9237

camel/providers/imap/ChangeLog
camel/providers/imap/camel-imap-message-cache.c
camel/providers/imap/camel-imap-message-cache.h
camel/providers/imap/camel-imap-store.c

index ae158cf..31028c4 100644 (file)
@@ -1,5 +1,15 @@
 2008-07-31  Srinivasa Ragavan  <sragavan@novell.com>
 
+       ** Fix for bug #545081
+
+       * camel/providers/imap/camel-imap-message-cache.c: Add a new simple
+       delete cache function.
+       * camel/providers/imap/camel-imap-message-cache.h:
+       * camel/providers/imap/camel-imap-store.c: Now forget the folder from
+       DB.
+
+2008-07-31  Srinivasa Ragavan  <sragavan@novell.com>
+
        * camel/providers/imap/camel-imap-message-cache.c: Fix delete cache
        code, when the summary is deleted.
 
index d3607f5..18ad89c 100644 (file)
@@ -197,6 +197,48 @@ camel_imap_message_cache_new (const char *path, CamelFolderSummary *summary,
        return cache;
 }
 
+
+/**
+ * camel_imap_message_cache_delete:
+ * @path: directory to use for storage
+ * @ex: a CamelException
+ *
+ * All the files under this directory would be deleted
+ **/
+
+gboolean
+camel_imap_message_cache_delete (const char *path, CamelException *ex)
+{
+       GDir *dir;
+       const char *dname;
+       GError *error = NULL;
+       GPtrArray *deletes;
+       
+       dir = g_dir_open (path, 0, &error);
+       if (!dir) {
+               camel_exception_setv (ex, CAMEL_EXCEPTION_SYSTEM,
+                                     _("Could not open cache directory: %s"),
+                                     error->message);
+               g_error_free (error);
+               return FALSE;
+       }
+
+       deletes = g_ptr_array_new ();
+       while ((dname = g_dir_read_name (dir)))
+               g_ptr_array_add (deletes, g_strdup_printf ("%s/%s", path, dname)); 
+       
+       g_dir_close (dir);
+
+       while (deletes->len) {
+               g_unlink (deletes->pdata[0]);
+               g_free (deletes->pdata[0]);
+               g_ptr_array_remove_index_fast (deletes, 0);
+       }
+       g_ptr_array_free (deletes, TRUE);
+
+       return TRUE;
+}
+
 /**
  * camel_imap_message_cache_max_uid:
  * @cache: the cache
index a7b325b..49ca33c 100644 (file)
@@ -96,6 +96,8 @@ void         camel_imap_message_cache_copy   (CamelImapMessageCache *source,
                                              CamelImapMessageCache *dest,
                                              const char *dest_uid,
                                              CamelException *ex);
+gboolean     camel_imap_message_cache_delete (const char *path, 
+                                             CamelException *ex);
 
 /* Standard Camel function */
 CamelType camel_imap_message_cache_get_type (void);
index 7353dff..95d67b6 100644 (file)
@@ -1127,9 +1127,7 @@ imap_folder_effectively_unsubscribed(CamelImapStore *imap_store,
 static void
 imap_forget_folder (CamelImapStore *imap_store, const char *folder_name, CamelException *ex)
 {
-       CamelFolderSummary *summary;
-       CamelImapMessageCache *cache;
-       char *summary_file, *state_file;
+       char *state_file;
        char *journal_file;
        char *folder_dir, *storage_path;
        CamelFolderInfo *fi;
@@ -1148,37 +1146,8 @@ imap_forget_folder (CamelImapStore *imap_store, const char *folder_name, CamelEx
                g_free (folder_dir);
                goto event;
        }
-       
-       summary_file = g_strdup_printf ("%s/summary", folder_dir);
-       summary = camel_imap_summary_new (NULL, summary_file);
-       if (!summary) {
-               g_free (summary_file);
-               g_free (folder_dir);
-               goto event;
-       }
-       camel_object_unref (summary);
 
-       g_unlink (summary_file);
-       g_free (summary_file);
-
-       summary_file = g_strdup_printf ("%s/summary-meta", folder_dir);
-       summary = camel_imap_summary_new (NULL, summary_file);
-       if (!summary) {
-               g_free (summary_file);
-               g_free (folder_dir);
-               goto event;
-       }
-       
-       cache = camel_imap_message_cache_new (folder_dir, summary, ex);
-       if (cache)
-               camel_imap_message_cache_clear (cache);
-       
-       camel_object_unref (cache);
-       camel_object_unref (summary);
-       
-       g_unlink (summary_file);
-       g_free (summary_file);
-       
+       /* Delete summary and all the data */
        journal_file = g_strdup_printf ("%s/journal", folder_dir);
        g_unlink (journal_file);
        g_free (journal_file);
@@ -1186,6 +1155,9 @@ imap_forget_folder (CamelImapStore *imap_store, const char *folder_name, CamelEx
        state_file = g_strdup_printf ("%s/cmeta", folder_dir);
        g_unlink (state_file);
        g_free (state_file);
+       
+       camel_db_delete_folder (((CamelStore *)imap_store)->cdb, folder_name, ex);
+       camel_imap_message_cache_delete (folder_dir, ex);
 
        state_file = g_strdup_printf("%s/subfolders", folder_dir);
        g_rmdir(state_file);