changeset 22361:73479718bc0b

lib-index: Mark index deleted if index log file is missing This fixes all kinds of errors caused by mailbox being deleted by another process.
author Aki Tuomi <aki.tuomi@dovecot.fi>
date Tue, 18 Jul 2017 14:37:53 +0300
parents d5c4dca315de
children 5e665ab8487c
files src/lib-index/mail-index.c
diffstat 1 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/lib-index/mail-index.c	Tue Jul 18 12:39:44 2017 +0300
+++ b/src/lib-index/mail-index.c	Tue Jul 18 14:37:53 2017 +0300
@@ -931,6 +931,20 @@
 	i_assert(filepath != NULL);
 	i_assert(function != NULL);
 
+	if (errno == ENOENT) {
+		struct stat st;
+		int old_errno = errno;
+		i_assert(index->log->filepath != NULL);
+		if (nfs_safe_stat(index->log->filepath, &st) < 0 &&
+		    errno == ENOENT) {
+			/* the index log has gone away */
+			index->index_deleted = TRUE;
+			errno = old_errno;
+			return;
+		}
+		errno = old_errno;
+	}
+
 	if (ENOSPACE(errno)) {
 		index->nodiskspace = TRUE;
 		if ((index->flags & MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY) == 0)