From bc3edce7712c3a912811bb1189b67765a9080373 Mon Sep 17 00:00:00 2001 From: Timo Sirainen Date: Sat, 10 Apr 2010 08:07:40 +0300 Subject: [PATCH] mdbox: Purging shouldn't give "unknown error" if mdbox storage doesn't exist. --HG-- branch : HEAD --- 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 ++-- .../index/dbox-multi/mdbox-storage-rebuild.c | 2 +- .../index/dbox-multi/mdbox-storage.c | 2 +- 5 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/lib-storage/index/dbox-multi/mdbox-mail.c b/src/lib-storage/index/dbox-multi/mdbox-mail.c index 2598a350d1..cdbfe4e6b6 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-mail.c +++ b/src/lib-storage/index/dbox-multi/mdbox-mail.c @@ -40,7 +40,7 @@ int mdbox_mail_lookup(struct mdbox_mailbox *mbox, struct mail_index_view *view, } 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 --git a/src/lib-storage/index/dbox-multi/mdbox-map.c b/src/lib-storage/index/dbox-multi/mdbox-map.c index 750a7102a9..eb020561f0 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-map.c +++ b/src/lib-storage/index/dbox-multi/mdbox-map.c @@ -99,14 +99,14 @@ static int dbox_map_mkdir_storage(struct dbox_map *map) 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 @@ int dbox_map_open(struct dbox_map *map, bool create_missing) } 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 @@ int dbox_map_lookup(struct dbox_map *map, uint32_t map_uid, 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 @@ int dbox_map_get_zero_ref_files(struct dbox_map *map, 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 @@ dbox_map_transaction_begin(struct dbox_map *map, bool external) 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 @@ dbox_map_append_begin(struct dbox_map *map, enum dbox_map_append_flags flags) 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 --git a/src/lib-storage/index/dbox-multi/mdbox-map.h b/src/lib-storage/index/dbox-multi/mdbox-map.h index 47eafec500..73fa9ad593 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-map.h +++ b/src/lib-storage/index/dbox-multi/mdbox-map.h @@ -33,9 +33,11 @@ dbox_map_init(struct mdbox_storage *storage, struct mailbox_list *root_list, 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 --git a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c index 9810bdcad5..f2a155714a 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c @@ -800,7 +800,7 @@ static int mdbox_storage_rebuild_scan(struct mdbox_storage_rebuild_context *ctx) 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 --git a/src/lib-storage/index/dbox-multi/mdbox-storage.c b/src/lib-storage/index/dbox-multi/mdbox-storage.c index c68586867a..f4fcab0e23 100644 --- a/src/lib-storage/index/dbox-multi/mdbox-storage.c +++ b/src/lib-storage/index/dbox-multi/mdbox-storage.c @@ -182,7 +182,7 @@ static int mdbox_write_index_header(struct mailbox *box, 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); -- 2.47.3