diff src/lib-index/mail-index.c @ 2200:97bb7b127617 HEAD

Beginnings of getting cache file working again. Easy to break currently, but basics seem to work.
author Timo Sirainen <tss@iki.fi>
date Sun, 20 Jun 2004 11:05:41 +0300
parents 1019b7694a11
children 2a9c84ed988c
line wrap: on
line diff
--- a/src/lib-index/mail-index.c	Sun Jun 20 09:33:08 2004 +0300
+++ b/src/lib-index/mail-index.c	Sun Jun 20 11:05:41 2004 +0300
@@ -8,6 +8,7 @@
 #include "write-full.h"
 #include "mail-index-private.h"
 #include "mail-transaction-log.h"
+#include "mail-cache.h"
 
 #include <stdio.h>
 #include <stddef.h>
@@ -553,7 +554,7 @@
 	ret = mail_index_try_open(index, NULL);
 	if (ret != 0) {
 		mail_transaction_log_sync_unlock(index->log);
-		return ret;
+		return ret < 0 ? -1 : 0;
 	}
 
 	/* create it fully in index.tmp first */
@@ -618,6 +619,7 @@
 	hdr->next_uid = 1;
 }
 
+/* returns -1 = error, 0 = won't create, 1 = ok */
 static int mail_index_open_files(struct mail_index *index,
 				 enum mail_index_open_flags flags)
 {
@@ -643,9 +645,27 @@
 	if (index->log == NULL)
 		return -1;
 
-	if (lock_id != 0)
-		mail_index_unlock(index, lock_id);
-	return index->fd != -1 ? 1 : mail_index_create(index, &hdr);
+	if (index->fd == -1) {
+		if (lock_id != 0) {
+			mail_index_unlock(index, lock_id);
+			lock_id = 0;
+		}
+		if (mail_index_create(index, &hdr) < 0)
+			return -1;
+	}
+
+	if (lock_id == 0) {
+		if (mail_index_lock_shared(index, FALSE, &lock_id) < 0)
+			return -1;
+
+	}
+
+	index->cache = mail_cache_open_or_create(index);
+	if (index->cache == NULL)
+		return -1;
+
+	mail_index_unlock(index, lock_id);
+	return 1;
 }
 
 int mail_index_open(struct mail_index *index, enum mail_index_open_flags flags)
@@ -711,6 +731,11 @@
 		index->map = NULL;
 	}
 
+	if (index->cache != NULL) {
+		mail_cache_free(index->cache);
+		index->cache = NULL;
+	}
+
 	if (index->fd != -1) {
 		if (close(index->fd) < 0)
 			mail_index_set_syscall_error(index, "close()");