dovecot-2.0: mdbox: Purging shouldn't give "unknown error" if md...

dovecot at dovecot.org dovecot at dovecot.org
Sat Apr 10 08:07:44 EEST 2010


details:   http://hg.dovecot.org/dovecot-2.0/rev/2200450752bd
changeset: 11127:2200450752bd
user:      Timo Sirainen <tss at iki.fi>
date:      Sat Apr 10 08:07:40 2010 +0300
description:
mdbox: Purging shouldn't give "unknown error" if mdbox storage doesn't exist.

diffstat:

 src/lib-storage/index/dbox-multi/mdbox-mail.c            |   2 +-
 src/lib-storage/index/dbox-multi/mdbox-map.c             |  32 +++++++++++-----
 src/lib-storage/index/dbox-multi/mdbox-map.h             |   6 ++-
 src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c |   2 +-
 src/lib-storage/index/dbox-multi/mdbox-storage.c         |   2 +-
 5 files changed, 29 insertions(+), 15 deletions(-)

diffs (140 lines):

diff -r 4dd372d1e80a -r 2200450752bd src/lib-storage/index/dbox-multi/mdbox-mail.c
--- a/src/lib-storage/index/dbox-multi/mdbox-mail.c	Sat Apr 10 07:39:39 2010 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-mail.c	Sat Apr 10 08:07:40 2010 +0300
@@ -40,7 +40,7 @@
 		}
 		mbox->map_uid_validity = hdr.map_uid_validity;
 	}
-	if (dbox_map_open(mbox->storage->map, TRUE) < 0)
+	if (dbox_map_open_or_create(mbox->storage->map) < 0)
 		return -1;
 
 	cur_map_uid_validity = dbox_map_get_uid_validity(mbox->storage->map);
diff -r 4dd372d1e80a -r 2200450752bd src/lib-storage/index/dbox-multi/mdbox-map.c
--- a/src/lib-storage/index/dbox-multi/mdbox-map.c	Sat Apr 10 07:39:39 2010 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-map.c	Sat Apr 10 08:07:40 2010 +0300
@@ -99,14 +99,14 @@
 	return 0;
 }
 
-int dbox_map_open(struct dbox_map *map, bool create_missing)
+static int dbox_map_open_internal(struct dbox_map *map, bool create_missing)
 {
 	enum mail_index_open_flags open_flags;
 	int ret;
 
 	if (map->view != NULL) {
 		/* already opened */
-		return 0;
+		return 1;
 	}
 
 	open_flags = MAIL_INDEX_OPEN_FLAG_NEVER_IN_MEMORY |
@@ -125,11 +125,22 @@
 	}
 	if (ret == 0) {
 		/* index not found - for now just return failure */
-		return -1;
+		i_assert(!create_missing);
+		return 0;
 	}
 
 	map->view = mail_index_view_open(map->index);
-	return 0;
+	return 1;
+}
+
+int dbox_map_open(struct dbox_map *map)
+{
+	return dbox_map_open_internal(map, FALSE);
+}
+
+int dbox_map_open_or_create(struct dbox_map *map)
+{
+	return dbox_map_open_internal(map, TRUE) <= 0 ? -1 : 0;
 }
 
 int dbox_map_refresh(struct dbox_map *map)
@@ -202,7 +213,7 @@
 	uoff_t size;
 	int ret;
 
-	if (dbox_map_open(map, TRUE) < 0)
+	if (dbox_map_open_or_create(map) < 0)
 		return -1;
 
 	if ((ret = dbox_map_get_seq(map, map_uid, &seq)) <= 0)
@@ -276,10 +287,11 @@
 	const void *data;
 	uint32_t seq;
 	bool expunged;
+	int ret;
 
-	if (dbox_map_open(map, FALSE) < 0) {
-		/* some internal error */
-		return -1;
+	if ((ret = dbox_map_open(map)) <= 0) {
+		/* no map / internal error */
+		return ret;
 	}
 	if (dbox_map_refresh(map) < 0)
 		return -1;
@@ -316,7 +328,7 @@
 
 	ctx = i_new(struct dbox_map_transaction_context, 1);
 	ctx->map = map;
-	if (dbox_map_open(map, FALSE) == 0 &&
+	if (dbox_map_open(map) > 0 &&
 	    dbox_map_refresh(map) == 0)
 		ctx->trans = mail_index_transaction_begin(map->view, flags);
 	return ctx;
@@ -496,7 +508,7 @@
 	i_array_init(&ctx->files, 64);
 	i_array_init(&ctx->appends, 128);
 
-	if (dbox_map_open(ctx->map, TRUE) < 0)
+	if (dbox_map_open_or_create(map) < 0)
 		ctx->failed = TRUE;
 	else {
 		/* refresh the map so we can try appending to the
diff -r 4dd372d1e80a -r 2200450752bd src/lib-storage/index/dbox-multi/mdbox-map.h
--- a/src/lib-storage/index/dbox-multi/mdbox-map.h	Sat Apr 10 07:39:39 2010 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-map.h	Sat Apr 10 08:07:40 2010 +0300
@@ -33,9 +33,11 @@
 	      const char *path);
 void dbox_map_deinit(struct dbox_map **map);
 
-/* Open the map. This is done automatically for most operations.
+/* Open the map. Returns 1 if ok, 0 if map doesn't exist, -1 if error. */
+int dbox_map_open(struct dbox_map *map);
+/* Open or create the map. This is done automatically for most operations.
    Returns 0 if ok, -1 if error. */
-int dbox_map_open(struct dbox_map *map, bool create_missing);
+int dbox_map_open_or_create(struct dbox_map *map);
 /* Refresh the map. Returns 0 if ok, -1 if error. */
 int dbox_map_refresh(struct dbox_map *map);
 
diff -r 4dd372d1e80a -r 2200450752bd src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c
--- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c	Sat Apr 10 07:39:39 2010 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c	Sat Apr 10 08:07:40 2010 +0300
@@ -800,7 +800,7 @@
 	uint32_t uid_validity;
 	int ret = 0;
 
-	if (dbox_map_open(ctx->storage->map, TRUE) < 0)
+	if (dbox_map_open_or_create(ctx->storage->map) < 0)
 		return -1;
 
 	/* begin by locking the map, so that other processes can't try to
diff -r 4dd372d1e80a -r 2200450752bd src/lib-storage/index/dbox-multi/mdbox-storage.c
--- a/src/lib-storage/index/dbox-multi/mdbox-storage.c	Sat Apr 10 07:39:39 2010 +0300
+++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c	Sat Apr 10 08:07:40 2010 +0300
@@ -182,7 +182,7 @@
 	const struct mail_index_header *hdr;
 	uint32_t uid_validity, uid_next;
 
-	if (dbox_map_open(mbox->storage->map, TRUE) < 0)
+	if (dbox_map_open_or_create(mbox->storage->map) < 0)
 		return -1;
 
 	hdr = mail_index_get_header(box->view);


More information about the dovecot-cvs mailing list