dovecot-2.1: lib-index: Fixed reopening index file that was mark...
dovecot at dovecot.org
dovecot at dovecot.org
Sun Sep 4 12:38:34 EEST 2011
details: http://hg.dovecot.org/dovecot-2.1/rev/33dc66d4286d
changeset: 13384:33dc66d4286d
user: Timo Sirainen <tss at iki.fi>
date: Sun Sep 04 12:38:24 2011 +0300
description:
lib-index: Fixed reopening index file that was marked as corrupted.
diffstat:
src/lib-index/mail-index.c | 41 ++++++++++++++++++++++++++++++++++++-----
1 files changed, 36 insertions(+), 5 deletions(-)
diffs (65 lines):
diff -r e404a1bef6bc -r 33dc66d4286d src/lib-index/mail-index.c
--- a/src/lib-index/mail-index.c Sun Sep 04 12:37:51 2011 +0300
+++ b/src/lib-index/mail-index.c Sun Sep 04 12:38:24 2011 +0300
@@ -504,8 +504,33 @@
return -1;
}
- index->cache = created ? mail_cache_create(index) :
- mail_cache_open_or_create(index);
+ if (index->cache == NULL) {
+ index->cache = created ? mail_cache_create(index) :
+ mail_cache_open_or_create(index);
+ }
+ return 1;
+}
+
+static int
+mail_index_open_opened(struct mail_index *index,
+ enum mail_index_open_flags flags)
+{
+ int ret;
+
+ i_assert(index->map != NULL);
+
+ if ((index->map->hdr.flags & MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0) {
+ /* index was marked corrupted. we'll probably need to
+ recreate the files. */
+ if (index->map != NULL)
+ mail_index_unmap(&index->map);
+ mail_index_close_file(index);
+ mail_transaction_log_close(index->log);
+ if ((ret = mail_index_open_files(index, flags)) <= 0)
+ return ret;
+ }
+
+ index->open_count++;
return 1;
}
@@ -514,9 +539,12 @@
int ret;
if (index->open_count > 0) {
- i_assert(index->map != NULL);
- index->open_count++;
- return 1;
+ if ((ret = mail_index_open_opened(index, flags)) <= 0) {
+ /* doesn't exist and create flag not used */
+ index->open_count++;
+ mail_index_close(index);
+ }
+ return ret;
}
index->filepath = MAIL_INDEX_IS_IN_MEMORY(index) ?
@@ -542,6 +570,9 @@
(flags & MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE) == 0)
i_fatal("nfs flush requires mmap_disable=yes");
+ /* NOTE: increase open_count only after mail_index_open_files().
+ it's used elsewhere to check if we're doing an initial opening
+ of the index files */
if ((ret = mail_index_open_files(index, flags)) <= 0) {
/* doesn't exist and create flag not used */
index->open_count++;
More information about the dovecot-cvs
mailing list