Skip to content

Commit

Permalink
fts-squat: fix Corrupted squat uidlist bug
Browse files Browse the repository at this point in the history
  • Loading branch information
nikwrt authored and sirainen committed Aug 16, 2016
1 parent de4869f commit d5db0fd
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 15 deletions.
36 changes: 23 additions & 13 deletions src/plugins/fts-squat/fts-backend-squat.c
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
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
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
Expand Up @@ -372,7 +372,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

0 comments on commit d5db0fd

Please sign in to comment.