balsa r8064 - in trunk: . libbalsa



Author: PeterB
Date: Sun Jan 25 17:40:46 2009
New Revision: 8064
URL: http://svn.gnome.org/viewvc/balsa?rev=8064&view=rev

Log:
check for stale cache files

Modified:
   trunk/ChangeLog
   trunk/libbalsa/mailbox_local.c
   trunk/libbalsa/mailbox_mbox.c

Modified: trunk/libbalsa/mailbox_local.c
==============================================================================
--- trunk/libbalsa/mailbox_local.c	(original)
+++ trunk/libbalsa/mailbox_local.c	Sun Jan 25 17:40:46 2009
@@ -592,6 +592,7 @@
     LibBalsaMailbox *mailbox = LIBBALSA_MAILBOX(local);
     gchar *filename;
     gchar *name;
+    struct stat st;
     gchar *contents;
     gsize length;
     GError *err = NULL;
@@ -603,7 +604,8 @@
     name = mailbox->name ? g_strdup(mailbox->name) :
         g_path_get_basename(libbalsa_mailbox_local_get_path(local));
 
-    if (!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) {
+    if (stat(filename, &st) < 0
+        || st.st_mtime < libbalsa_mailbox_get_mtime(mailbox)) {
         /* No error, but we return FALSE so the caller can grab all the
          * message info needed to rethread from scratch. */
         if (libbalsa_mailbox_total_messages(mailbox) > 0)

Modified: trunk/libbalsa/mailbox_mbox.c
==============================================================================
--- trunk/libbalsa/mailbox_mbox.c	(original)
+++ trunk/libbalsa/mailbox_mbox.c	Sun Jan 25 17:40:46 2009
@@ -581,20 +581,23 @@
 lbm_mbox_restore(LibBalsaMailboxMbox * mbox)
 {
     gchar *filename;
+    struct stat st;
     gchar *contents;
     gsize length;
-    gboolean tmp;
     off_t end;
     struct message_info *msg_info;
     GMimeStream *mbox_stream;
 
     filename = lbm_mbox_get_cache_filename(mbox);
-    tmp = g_file_get_contents(filename, &contents, &length, NULL);
-    g_free(filename);
-
-    if (!tmp)
-        /* Nonexistent file is no error. */
+    if (stat(filename, &st) < 0 
+        || st.st_mtime < libbalsa_mailbox_get_mtime(LIBBALSA_MAILBOX(mbox))
+        || !g_file_get_contents(filename, &contents, &length, NULL)) {
+        /* No cache file, stale cache, or read error. */
+        g_free(filename);
         return;
+    }
+
+    g_free(filename);
 
     if (length < sizeof(struct message_info)) {
         /* Error: file always contains at least one record. */



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