dovecot-2.0: lib-index: mail_index_alloc_cache_get() now allows ...

dovecot at dovecot.org dovecot at dovecot.org
Mon Apr 5 04:50:27 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/6a65c0e043e2
changeset: 11059:6a65c0e043e2
user:      Timo Sirainen <tss at iki.fi>
date:      Mon Apr 05 04:49:10 2010 +0300
description:
lib-index: mail_index_alloc_cache_get() now allows mailbox_path=NULL.
Also did a small code cleanup with this change.

diffstat:

 src/lib-index/mail-index-alloc-cache.c |  100 ++++++++++++++++++---------------
 1 files changed, 55 insertions(+), 45 deletions(-)

diffs (121 lines):

diff -r 5e3e00d11ca5 -r 6a65c0e043e2 src/lib-index/mail-index-alloc-cache.c
--- a/src/lib-index/mail-index-alloc-cache.c	Mon Apr 05 04:03:05 2010 +0300
+++ b/src/lib-index/mail-index-alloc-cache.c	Mon Apr 05 04:49:10 2010 +0300
@@ -65,13 +65,64 @@
 	i_free(list);
 }
 
+static struct mail_index_alloc_cache_list *
+mail_index_alloc_cache_find(const char *mailbox_path, const char *index_dir,
+			    const struct stat *index_st)
+{
+	struct mail_index_alloc_cache_list **indexp, *rec, *match;
+	unsigned int destroy_count;
+	struct stat st;
+
+	destroy_count = 0; match = NULL;
+	for (indexp = &indexes; *indexp != NULL;) {
+		rec = *indexp;
+
+		if (match != NULL) {
+			/* already found the index. we're just going through
+			   the rest of them to drop 0 refcounts */
+		} else if (rec->refcount == 0 && rec->index->open_count == 0) {
+			/* index is already closed. don't even try to
+			   reuse it. */
+		} else if (index_dir != NULL && rec->index_dir_ino != 0) {
+			if (index_st->st_ino == rec->index_dir_ino &&
+			    CMP_DEV_T(index_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, &st) < 0 ||
+				    st.st_ino != index_st->st_ino ||
+				    !CMP_DEV_T(st.st_dev, index_st->st_dev))
+					rec->destroy_time = 0;
+				else
+					match = rec;
+			}
+		} else if (mailbox_path != NULL && rec->mailbox_path != NULL) {
+			if (strcmp(mailbox_path, rec->mailbox_path) == 0)
+				match = rec;
+		}
+
+		if (rec->refcount == 0 && rec != match) {
+			if (rec->destroy_time <= ioloop_time ||
+			    destroy_count >= INDEX_CACHE_MAX) {
+				*indexp = rec->next;
+				mail_index_alloc_cache_list_free(rec);
+				continue;
+			} else {
+				destroy_count++;
+			}
+		}
+
+                indexp = &(*indexp)->next;
+	}
+	return match;
+}
+
 struct mail_index *
 mail_index_alloc_cache_get(const char *mailbox_path,
 			   const char *index_dir, const char *prefix)
 {
-	struct mail_index_alloc_cache_list **indexp, *rec, *match;
-	struct stat st, st2;
-	unsigned int destroy_count;
+	struct mail_index_alloc_cache_list *match;
+	struct stat st;
 
 	/* compare index_dir inodes so we don't break even with symlinks.
 	   if index_dir doesn't exist yet or if using in-memory indexes, just
@@ -89,48 +140,7 @@
 		}
 	}
 
-	destroy_count = 0; match = NULL;
-	for (indexp = &indexes; *indexp != NULL;) {
-		rec = *indexp;
-
-		if (match != NULL) {
-			/* already found the index. we're just going through
-			   the rest of them to drop 0 refcounts */
-		} else if (rec->refcount == 0 && rec->index->open_count == 0) {
-			/* index is already closed. don't even try to
-			   reuse it. */
-		} else if (index_dir != NULL && rec->index_dir_ino != 0) {
-			if (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
-					match = rec;
-			}
-		} else {
-			if (strcmp(mailbox_path, rec->mailbox_path) == 0)
-				match = rec;
-		}
-
-		if (rec->refcount == 0 && rec != match) {
-			if (rec->destroy_time <= ioloop_time ||
-			    destroy_count >= INDEX_CACHE_MAX) {
-				*indexp = rec->next;
-				mail_index_alloc_cache_list_free(rec);
-				continue;
-			} else {
-				destroy_count++;
-			}
-		}
-
-                indexp = &(*indexp)->next;
-	}
-
+	match = mail_index_alloc_cache_find(mailbox_path, index_dir, &st);
 	if (match == NULL) {
 		struct mail_index *index = mail_index_alloc(index_dir, prefix);
 		match = mail_index_alloc_cache_add(index, mailbox_path, &st);


More information about the dovecot-cvs mailing list