diff src/lib-index/mail-index.c @ 4876:f1d77064884c HEAD

Lock handling changes. Everything goes through file-lock API now and there's only a single enum listing the different lock methods. This change exposed some unneeded (or possibly even wrong?) unlock calls in index file handling which were fixed.
author Timo Sirainen <tss@iki.fi>
date Wed, 06 Dec 2006 17:08:22 +0200
parents 23f63cd499ee
children 204d7edc7cdc
line wrap: on
line diff
--- a/src/lib-index/mail-index.c	Wed Dec 06 16:46:37 2006 +0200
+++ b/src/lib-index/mail-index.c	Wed Dec 06 17:08:22 2006 +0200
@@ -1275,6 +1275,7 @@
 	int ret;
 
         i_assert(index->fd == -1);
+	i_assert(index->lock_type == F_UNLCK);
 
 	if (lock_id_r != NULL)
 		*lock_id_r = 0;
@@ -1298,6 +1299,7 @@
 		if (lock_id_r != NULL)
 			*lock_id_r = 0;
 
+		i_assert(index->file_lock == NULL);
 		(void)close(index->fd);
 		index->fd = -1;
 	} else {
@@ -1535,7 +1537,7 @@
 }
 
 int mail_index_open(struct mail_index *index, enum mail_index_open_flags flags,
-		    enum mail_index_lock_method lock_method)
+		    enum file_lock_method lock_method)
 {
 	int i = 0, ret;
 
@@ -1571,7 +1573,7 @@
 
 		/* don't even bother to handle dotlocking without mmap being
 		   disabled. that combination simply doesn't make any sense */
-		if (lock_method == MAIL_INDEX_LOCK_DOTLOCK &&
+		if (lock_method == FILE_LOCK_METHOD_DOTLOCK &&
 		    !index->mmap_disable) {
 			i_fatal("lock_method=dotlock and mmap_disable=no "
 				"combination isn't supported. "
@@ -1611,6 +1613,8 @@
 		mail_index_unmap(index, &index->map);
 	if (index->cache != NULL)
 		mail_cache_free(&index->cache);
+	if (index->file_lock != NULL)
+		file_lock_free(&index->file_lock);
 
 	if (index->fd != -1) {
 		if (close(index->fd) < 0)
@@ -1628,11 +1632,12 @@
 int mail_index_reopen(struct mail_index *index, int fd)
 {
 	struct mail_index_map *old_map;
+	struct file_lock *old_file_lock;
 	unsigned int old_shared_locks, old_lock_id, lock_id = 0;
 	int ret, old_fd, old_lock_type;
 
 	i_assert(!MAIL_INDEX_IS_IN_MEMORY(index));
-	i_assert(index->copy_lock_path == NULL || index->excl_lock_count == 0);
+	i_assert(index->excl_lock_count == 0);
 
 	old_map = index->map;
 	old_fd = index->fd;
@@ -1643,11 +1648,13 @@
 	old_lock_type = index->lock_type;
 	old_lock_id = index->lock_id;
 	old_shared_locks = index->shared_lock_count;
- 
+	old_file_lock = index->file_lock;
+
 	if (index->lock_type == F_RDLCK)
 		index->lock_type = F_UNLCK;
 	index->lock_id += 2;
 	index->shared_lock_count = 0;
+	index->file_lock = NULL;
 
 	if (fd != -1) {
 		index->fd = fd;
@@ -1676,11 +1683,14 @@
 
 	if (ret == 0) {
 		mail_index_unmap(index, &old_map);
+		if (old_file_lock != NULL)
+			file_lock_free(&old_file_lock);
 		if (close(old_fd) < 0)
 			mail_index_set_syscall_error(index, "close()");
 	} else {
 		if (index->map != NULL)
 			mail_index_unmap(index, &index->map);
+
 		if (index->fd != -1) {
 			if (close(index->fd) < 0)
 				mail_index_set_syscall_error(index, "close()");
@@ -1689,6 +1699,7 @@
 		index->map = old_map;
 		index->hdr = &index->map->hdr;
 		index->fd = old_fd;
+		index->file_lock = old_file_lock;
 		index->lock_type = old_lock_type;
 		index->lock_id = old_lock_id;
 		index->shared_lock_count = old_shared_locks;
@@ -1824,6 +1835,9 @@
 			ret = -1;
 	}
 
+	if (index->file_lock != NULL)
+		file_lock_free(&index->file_lock);
+
 	/* close the index file. */
 	if (close(index->fd) < 0)
 		mail_index_set_syscall_error(index, "close()");