diff src/lib-index/mail-index.c @ 1943:e473d2df21be HEAD

missing index file fixes
author Timo Sirainen <tss@iki.fi>
date Sat, 01 May 2004 19:22:54 +0300
parents 2b114aa7eeec
children 268a4096e8be
line wrap: on
line diff
--- a/src/lib-index/mail-index.c	Sat May 01 19:08:15 2004 +0300
+++ b/src/lib-index/mail-index.c	Sat May 01 19:22:54 2004 +0300
@@ -655,6 +655,34 @@
 	index->indexid = 0;
 }
 
+int mail_index_mark_corrupted(struct mail_index *index)
+{
+	struct mail_index_header hdr;
+
+	if (index->readonly)
+		return 0;
+
+	/* make sure we can write the header */
+	if (!MAIL_INDEX_MAP_IS_IN_MEMORY(index->map)) {
+		if (mprotect(index->map->mmap_base, sizeof(hdr),
+			     PROT_READ | PROT_WRITE) < 0) {
+			mail_index_set_syscall_error(index, "mprotect()");
+			return -1;
+		}
+	}
+
+	hdr = *index->hdr;
+	hdr.flags |= MAIL_INDEX_HDR_FLAG_CORRUPTED;
+	if (mail_index_write_header(index, &hdr) < 0)
+		return -1;
+
+	if (fsync(index->fd) < 0)
+		return mail_index_set_syscall_error(index, "fsync()");
+
+	mail_index_set_inconsistent(index);
+	return 0;
+}
+
 int mail_index_set_syscall_error(struct mail_index *index,
 				 const char *function)
 {