[tpop3d-discuss] [PATCH] Lots of 'Index exists, but has some stale or corrupt data' messages

Martin Blapp mb at imp.ch
Thu, 10 Feb 2005 12:10:36 +0100 (CET)


Hi all,

This is just a followup to my previous mail. I found a solution for this
problem described here:

> Feb  8 10:21:24 mx2 tpop3d[28118]:
> mailspool_load_index(/mailspool/390/016390.tpop3d-index): index
> exists, but has some stale or corrupt data
>
> The mailbox itself is empty.
>
> cat /mailspool/390/016390.tpop3d-index
> # This is a mailspool index file, generated by tpop3d, version 1.5.3.
> # Its purpose is to speed up the parsing of mailspool files by the POP3
> # server. If you delete this file, it will be automatically recreated by
> # tpop3d. So don't do that.
> 00000000 00000039 00003736 202859a4696c44b693aa13de2aabfb44

The solutution to this problem is to clean up the index too even
if all messages have been deleted.

--- mailspool.c Wed Feb  9 19:53:57 2005
+++ mailspool.c Thu Feb 10 10:29:50 2005
@@ -453,7 +453,13 @@
         if (ftruncate(M->fd, M->index->offset) == -1) {
             log_print(LOG_ERR, "mailspool_apply_changes(%s): ftruncate: %m",
M->name);
             return 0;
-        } else return 1;
+        } else {
+#ifdef MBOX_BSD_SAVE_INDICES
+           if (mailspool_save_indices && !mailspool_save_index(M))
+               log_print(LOG_WARNING, _("mailspool_apply_changes(%s): unable to
save mailspool index"), M->name);
+#endif /* MBOX_BSD_SAVE_INDICES */
+               return 1;
+       }
     }

     /* We need to do something more complicated, so map the mailspool. */
@@ -698,7 +699,7 @@
 int mailspool_load_index(mailbox m) {
     char *indexfile = NULL;
     FILE *fp = NULL;
-    struct stat st;
+    struct stat st, sb;
     int offset, length, msglength;
     char hexdigest[33] = {0};
     char sigbuf[sizeof(index_signature)];
@@ -712,6 +713,10 @@

     indexfile = mailspool_find_index(m);
     if (!indexfile) goto fail;
+
+    /* Check for empty mail boxes and kill a stale indexfile */
+    if ((stat(m->name, &sb) == 0) && (sb.st_size == 0))
+       truncate(indexfile,sizeof(index_signature));

     fp = fopen(indexfile, "rt");
     if (!fp) {