]> git.ipfire.org Git - thirdparty/dovecot/core.git/commitdiff
mdbox: Rebuilding storage ignored mails in alt storage.
authorTimo Sirainen <tss@iki.fi>
Tue, 16 Mar 2010 13:20:15 +0000 (15:20 +0200)
committerTimo Sirainen <tss@iki.fi>
Tue, 16 Mar 2010 13:20:15 +0000 (15:20 +0200)
--HG--
branch : HEAD

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

index 34837a5798cebdc57a4cf8d3758310618f2f2730..a274f163760200653a096fcb547268e0816b44ac 100644 (file)
@@ -735,46 +735,27 @@ static int rebuild_finish(struct mdbox_storage_rebuild_context *ctx)
        return 0;
 }
 
-static int mdbox_storage_rebuild_scan(struct mdbox_storage_rebuild_context *ctx)
+static int
+mdbox_storage_rebuild_scan_dir(struct mdbox_storage_rebuild_context *ctx,
+                              const char *storage_dir, bool alt)
 {
-       const struct mail_index_header *hdr;
        DIR *dir;
        struct dirent *d;
        string_t *path;
        unsigned int dir_len;
-       uint32_t uid_validity;
        int ret = 0;
 
-       if (dbox_map_open(ctx->storage->map, TRUE) < 0)
-               return -1;
-
-       /* begin by locking the map, so that other processes can't try to
-          rebuild at the same time. */
-       ret = mail_index_sync_begin(ctx->storage->map->index, &ctx->sync_ctx,
-                                   &ctx->sync_view, &ctx->trans, 0);
-       if (ret <= 0) {
-               i_assert(ret != 0);
-               mail_storage_set_internal_error(&ctx->storage->storage.storage);
-               mail_index_reset_error(ctx->storage->map->index);
-               return -1;
-       }
-
-       uid_validity = dbox_map_get_uid_validity(ctx->storage->map);
-       hdr = mail_index_get_header(ctx->sync_view);
-       if (hdr->uid_validity != uid_validity) {
-               mail_index_update_header(ctx->trans,
-                       offsetof(struct mail_index_header, uid_validity),
-                       &uid_validity, sizeof(uid_validity), TRUE);
-       }
-
-       dir = opendir(ctx->storage->storage_dir);
+       dir = opendir(storage_dir);
        if (dir == NULL) {
+               if (alt && errno == ENOENT)
+                       return 0;
+
                mail_storage_set_critical(&ctx->storage->storage.storage,
-                       "opendir(%s) failed: %m", ctx->storage->storage_dir);
+                       "opendir(%s) failed: %m", storage_dir);
                return -1;
        }
        path = t_str_new(256);
-       str_append(path, ctx->storage->storage_dir);
+       str_append(path, storage_dir);
        str_append_c(path, '/');
        dir_len = str_len(path);
 
@@ -794,14 +775,51 @@ static int mdbox_storage_rebuild_scan(struct mdbox_storage_rebuild_context *ctx)
        }
        if (ret == 0 && errno != 0) {
                mail_storage_set_critical(&ctx->storage->storage.storage,
-                       "readdir(%s) failed: %m", ctx->storage->storage_dir);
+                       "readdir(%s) failed: %m", storage_dir);
                ret = -1;
        }
        if (closedir(dir) < 0) {
                mail_storage_set_critical(&ctx->storage->storage.storage,
-                       "closedir(%s) failed: %m", ctx->storage->storage_dir);
+                       "closedir(%s) failed: %m", storage_dir);
                ret = -1;
        }
+       return ret;
+}
+
+static int mdbox_storage_rebuild_scan(struct mdbox_storage_rebuild_context *ctx)
+{
+       const struct mail_index_header *hdr;
+       uint32_t uid_validity;
+       int ret = 0;
+
+       if (dbox_map_open(ctx->storage->map, TRUE) < 0)
+               return -1;
+
+       /* begin by locking the map, so that other processes can't try to
+          rebuild at the same time. */
+       ret = mail_index_sync_begin(ctx->storage->map->index, &ctx->sync_ctx,
+                                   &ctx->sync_view, &ctx->trans, 0);
+       if (ret <= 0) {
+               i_assert(ret != 0);
+               mail_storage_set_internal_error(&ctx->storage->storage.storage);
+               mail_index_reset_error(ctx->storage->map->index);
+               return -1;
+       }
+
+       uid_validity = dbox_map_get_uid_validity(ctx->storage->map);
+       hdr = mail_index_get_header(ctx->sync_view);
+       if (hdr->uid_validity != uid_validity) {
+               mail_index_update_header(ctx->trans,
+                       offsetof(struct mail_index_header, uid_validity),
+                       &uid_validity, sizeof(uid_validity), TRUE);
+       }
+
+       if (mdbox_storage_rebuild_scan_dir(ctx, ctx->storage->storage_dir,
+                                          FALSE) < 0)
+               return -1;
+       if (mdbox_storage_rebuild_scan_dir(ctx, ctx->storage->alt_storage_dir,
+                                          TRUE) < 0)
+               return -1;
 
        if (ret < 0 ||
            rebuild_apply_map(ctx) < 0 ||