diff src/lib-index/mail-index-data.c @ 29:e9375147c0cb HEAD

Added write_full() which is a simple wrapper around write() meant for writing into files. When there's too much deleted data in index files, they're now compressed when the index is being opened.
author Timo Sirainen <tss@iki.fi>
date Mon, 26 Aug 2002 02:46:59 +0300
parents 1b34ec11fff8
children 5e9cf9565353
line wrap: on
line diff
--- a/src/lib-index/mail-index-data.c	Mon Aug 26 02:22:41 2002 +0300
+++ b/src/lib-index/mail-index-data.c	Mon Aug 26 02:46:59 2002 +0300
@@ -2,6 +2,7 @@
 
 #include "lib.h"
 #include "mmap-util.h"
+#include "write-full.h"
 #include "mail-index.h"
 #include "mail-index-data.h"
 #include "mail-index-util.h"
@@ -62,7 +63,7 @@
 	const char *path;
 	int fd;
 
-	path = t_strconcat(index->filepath, ".data", NULL);
+	path = t_strconcat(index->filepath, DATA_FILE_PREFIX, NULL);
 	fd = open(path, O_RDWR);
 	if (fd == -1) {
 		if (errno == ENOENT) {
@@ -109,7 +110,7 @@
 	memset(&hdr, 0, sizeof(hdr));
 	hdr.indexid = index->indexid;
 
-	if (write(fd, &hdr, sizeof(hdr)) != sizeof(hdr)) {
+	if (write_full(fd, &hdr, sizeof(hdr)) < 0) {
 		index_set_error(index, "Error writing to temp index data "
 				"%s: %m", temppath);
 		return NULL;
@@ -117,7 +118,7 @@
 
 	/* move temp file into .data file, deleting old one
 	   if it already exists */
-	realpath = t_strconcat(index->filepath, ".data", NULL);
+	realpath = t_strconcat(index->filepath, DATA_FILE_PREFIX, NULL);
 	if (rename(temppath, realpath) == -1) {
 		index_set_error(index, "rename(%s, %s) failed: %m",
 				temppath, realpath);
@@ -189,7 +190,7 @@
 		return FALSE;
 	}
 
-	if (write(data->fd, &hdr, sizeof(hdr)) != sizeof(hdr)) {
+	if (write_full(data->fd, &hdr, sizeof(hdr)) < 0) {
 		index_set_error(data->index, "write() failed for data file "
 				"%s: %m", data->filepath);
 		return FALSE;
@@ -216,7 +217,7 @@
 		return -1;
 	}
 
-	if ((size_t) write(data->fd, buffer, size) != size) {
+	if (write_full(data->fd, buffer, size) < 0) {
 		index_set_error(data->index, "Error appending to file %s: %m",
 				data->filepath);
 		return -1;
@@ -376,3 +377,12 @@
 			(unsigned long) DATA_FILE_POSITION(data, rec));
 	return FALSE;
 }
+
+void *mail_index_data_get_mmaped(MailIndexData *data, size_t *size)
+{
+	if (!mmap_update(data, 0, UINT_MAX))
+		return NULL;
+
+	*size = data->mmap_length;
+	return data->mmap_base;
+}