Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

fts-squat: fix Corrupted squat uidlist bug #5

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 23 additions & 13 deletions src/plugins/fts-squat/fts-backend-squat.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ static void fts_backend_squat_deinit(struct fts_backend *_backend)
i_free(backend);
}

static void
static int
fts_backend_squat_set_box(struct squat_fts_backend *backend,
struct mailbox *box)
{
Expand All @@ -105,12 +105,22 @@ fts_backend_squat_set_box(struct squat_fts_backend *backend,
struct mailbox_status status;
const char *path;
enum squat_index_flags flags = 0;
int ret;

if (backend->box == box)
return;
{
if (backend->refresh) {
ret = squat_trie_refresh(backend->trie);
if (ret < 0)
return ret;
backend->refresh = FALSE;
}
return 0;
}
fts_backend_squat_unset_box(backend);
backend->refresh = FALSE;
if (box == NULL)
return;
return 0;

perm = mailbox_get_permissions(box);
storage = mailbox_get_storage(box);
Expand All @@ -137,6 +147,7 @@ fts_backend_squat_set_box(struct squat_fts_backend *backend,
if (backend->full_len != 0)
squat_trie_set_full_len(backend->trie, backend->full_len);
backend->box = box;
return squat_trie_open(backend->trie);
}

static int
Expand All @@ -146,7 +157,9 @@ fts_backend_squat_get_last_uid(struct fts_backend *_backend,
struct squat_fts_backend *backend =
(struct squat_fts_backend *)_backend;

fts_backend_squat_set_box(backend, box);
int ret = fts_backend_squat_set_box(backend, box);
if (ret < 0)
return -1;
return squat_trie_get_last_uid(backend->trie, last_uid_r);
}

Expand Down Expand Up @@ -254,9 +267,9 @@ fts_backend_squat_update_set_mailbox(struct fts_backend_update_context *_ctx,

if (fts_backend_squat_build_deinit(ctx) < 0)
ctx->failed = TRUE;
fts_backend_squat_set_box(backend, box);

if (box != NULL) {
if (fts_backend_squat_set_box(backend, box) < 0)
ctx->failed = TRUE;
else if (box != NULL) {
if (squat_trie_build_init(backend->trie, &ctx->build_ctx) < 0)
ctx->failed = TRUE;
}
Expand Down Expand Up @@ -439,12 +452,9 @@ fts_backend_squat_lookup(struct fts_backend *_backend, struct mailbox *box,
bool first = TRUE;
int ret;

fts_backend_squat_set_box(backend, box);
if (backend->refresh) {
if (squat_trie_refresh(backend->trie) < 0)
return -1;
backend->refresh = FALSE;
}
ret = fts_backend_squat_set_box(backend, box);
if (ret < 0)
return -1;

for (; args != NULL; args = args->next) {
ret = squat_lookup_arg(backend, args, first ? FALSE : and_args,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/fts-squat/squat-trie.c
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ static int squat_trie_open_fd(struct squat_trie *trie)
return 0;
}

static int squat_trie_open(struct squat_trie *trie)
int squat_trie_open(struct squat_trie *trie)
{
squat_trie_close(trie);

Expand Down
1 change: 1 addition & 0 deletions src/plugins/fts-squat/squat-trie.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ void squat_trie_deinit(struct squat_trie **trie);
void squat_trie_set_partial_len(struct squat_trie *trie, unsigned int len);
void squat_trie_set_full_len(struct squat_trie *trie, unsigned int len);

int squat_trie_open(struct squat_trie *trie);
int squat_trie_refresh(struct squat_trie *trie);

int squat_trie_build_init(struct squat_trie *trie,
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/fts-squat/squat-uidlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ static int squat_uidlist_map_header(struct squat_uidlist *uidlist)
}
if (uidlist->hdr.indexid != uidlist->trie->hdr.indexid) {
/* see if trie was recreated */
(void)squat_trie_refresh(uidlist->trie);
(void)squat_trie_open(uidlist->trie);
}
if (uidlist->hdr.indexid != uidlist->trie->hdr.indexid) {
squat_uidlist_set_corrupted(uidlist, "wrong indexid");
Expand Down