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);
}
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 ||