changeset 3524:67179bfce30f HEAD

Don't try to use cached index if it doesn't exist anymore.
author Timo Sirainen <tss@iki.fi>
date Sun, 07 Aug 2005 16:29:33 +0300
parents d1ed3b3548db
children 8ac16ccc3c73
files src/lib-storage/index/index-storage.c
diffstat 1 files changed, 23 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-storage/index/index-storage.c	Sun Aug 07 16:06:56 2005 +0300
+++ b/src/lib-storage/index/index-storage.c	Sun Aug 07 16:29:33 2005 +0300
@@ -4,7 +4,7 @@
 #include "array.h"
 #include "buffer.h"
 #include "ioloop.h"
-#include "mail-index.h"
+#include "mail-index-private.h"
 #include "index-storage.h"
 #include "index-mail.h"
 
@@ -92,7 +92,7 @@
 {
 	struct index_list **list, *rec;
 	struct mail_index *index;
-	struct stat st;
+	struct stat st, st2;
 	int destroy_count;
 
 	if (index_dir == NULL || stat(index_dir, &st) < 0)
@@ -104,12 +104,27 @@
 	for (list = &indexes; *list != NULL;) {
 		rec = *list;
 
-		if ((index_dir != NULL && st.st_ino == rec->index_dir_ino &&
-		     CMP_DEV_T(st.st_dev, rec->index_dir_dev)) ||
-		    (index_dir == NULL && st.st_ino == 0 &&
-		     strcmp(mailbox_path, rec->mailbox_path) == 0)) {
-			rec->refcount++;
-			index = rec->index;
+		if (index_dir != NULL) {
+			if (index == NULL && st.st_ino == rec->index_dir_ino &&
+			    CMP_DEV_T(st.st_dev, rec->index_dir_dev)) {
+				/* make sure the directory still exists.
+				   it might have been renamed and we're trying
+				   to access it via its new path now. */
+				if (stat(rec->index->dir, &st2) < 0 ||
+				    st2.st_ino != st.st_ino ||
+				    !CMP_DEV_T(st2.st_dev, st.st_dev))
+					rec->destroy_time = 0;
+				else {
+					rec->refcount++;
+					index = rec->index;
+				}
+			}
+		} else {
+			if (index == NULL && st.st_ino == 0 &&
+			    strcmp(mailbox_path, rec->mailbox_path) == 0) {
+				rec->refcount++;
+				index = rec->index;
+			}
 		}
 
 		if (rec->refcount == 0) {