]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mdbox: Purging shouldn't give "unknown error" if mdbox storage doesn't exist.
authorTimo Sirainen <tss@iki.fi>
Sat, 10 Apr 2010 05:07:40 +0000 (08:07 +0300)
committerTimo Sirainen <tss@iki.fi>
Sat, 10 Apr 2010 05:07:40 +0000 (08:07 +0300)
--HG--
branch : HEAD

src/lib-storage/index/dbox-multi/mdbox-mail.c
src/lib-storage/index/dbox-multi/mdbox-map.c
src/lib-storage/index/dbox-multi/mdbox-map.h
src/lib-storage/index/dbox-multi/mdbox-storage-rebuild.c
src/lib-storage/index/dbox-multi/mdbox-storage.c

index 2598a350d15e2eb7e36b914159b333166fdb75c2..cdbfe4e6b622352c3122a62fa397452569e5b59f 100644 (file)
@@ -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);
index 750a7102a9adbae59502e457237bf55bab9f0b7a..eb020561f0d0660a0f7846a94114ae96309a7852 100644 (file)
@@ -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
index 47eafec50095e7a45e0bfc1339b1fe333fa0a0a1..73fa9ad593f19ec01036092a00bbb5843f9deef8 100644 (file)
@@ -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);
 
index 9810bdcad5e6245e039b81041e3a3d0326d20573..f2a155714ab9fa75245ff96df15138dc96a737f7 100644 (file)
@@ -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
index c68586867a7092e55677510360954c0592013d51..f4fcab0e2373d375ae50d5ffe685a710c9b444a6 100644 (file)
@@ -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);