~ubuntu-branches/ubuntu/wily/dovecot/wily

« back to all changes in this revision

Viewing changes to src/plugins/fts-lucene/fts-backend-lucene.c

  • Committer: Package Import Robot
  • Author(s): Jaldhar H. Vyas
  • Date: 2013-09-09 00:57:32 UTC
  • mfrom: (1.13.11)
  • mto: (4.8.5 experimental) (1.16.1)
  • mto: This revision was merged to the branch mainline in revision 97.
  • Revision ID: package-import@ubuntu.com-20130909005732-dn1eell8srqbhh0e
Tags: upstream-2.2.5
ImportĀ upstreamĀ versionĀ 2.2.5

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2006-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2006-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "array.h"
53
53
 
54
54
static int fts_backend_lucene_mkdir(struct lucene_fts_backend *backend)
55
55
{
56
 
        const char *error;
57
 
 
58
56
        if (backend->dir_created)
59
57
                return 0;
60
58
 
61
59
        backend->dir_created = TRUE;
62
60
        if (mailbox_list_mkdir_root(backend->backend.ns->list,
63
61
                                    backend->dir_path,
64
 
                                    MAILBOX_LIST_PATH_TYPE_INDEX, &error) < 0) {
65
 
                i_error("lucene: Couldn't create root dir %s: %s",
66
 
                        backend->dir_path, error);
 
62
                                    MAILBOX_LIST_PATH_TYPE_INDEX) < 0)
67
63
                return -1;
68
 
        }
69
64
        return 0;
70
65
}
71
66
 
102
97
        if (box != NULL) {
103
98
                if (fts_lucene_get_mailbox_guid(box, guid) < 0)
104
99
                        return -1;
105
 
                buffer_create_data(&buf, guid_hex, MAILBOX_GUID_HEX_LENGTH);
 
100
                buffer_create_from_data(&buf, guid_hex, MAILBOX_GUID_HEX_LENGTH);
106
101
                binary_to_hex_append(&buf, guid, GUID_128_SIZE);
107
102
                for (i = 0; i < N_ELEMENTS(wguid_hex); i++)
108
103
                        wguid_hex[i] = guid_hex[i];
144
139
                return -1;
145
140
        }
146
141
 
147
 
        path = mailbox_list_get_path(_backend->ns->list, NULL,
148
 
                                     MAILBOX_LIST_PATH_TYPE_INDEX);
149
 
        i_assert(path != NULL); /* fts already checked this */
 
142
        /* fts already checked that index exists */
 
143
        path = mailbox_list_get_root_forced(_backend->ns->list,
 
144
                                            MAILBOX_LIST_PATH_TYPE_INDEX);
150
145
 
151
146
        backend->dir_path = i_strconcat(path, "/"LUCENE_INDEX_DIR_NAME, NULL);
152
147
        backend->index = lucene_index_init(backend->dir_path,
198
193
        if (lucene_index_get_last_uid(backend->index, last_uid_r) < 0)
199
194
                return -1;
200
195
 
201
 
        (void)fts_index_set_last_uid(box, *last_uid_r);
 
196
        fts_index_set_last_uid(box, *last_uid_r);
202
197
        return 0;
203
198
}
204
199
 
248
243
        i_assert(backend->updating);
249
244
 
250
245
        backend->updating = FALSE;
251
 
        if (ctx->lucene_opened)
252
 
                lucene_index_build_deinit(backend->index);
 
246
        if (ctx->lucene_opened) {
 
247
                if (lucene_index_build_deinit(backend->index) < 0)
 
248
                        ret = -1;
 
249
        }
253
250
 
254
251
        if (ctx->expunge_ctx != NULL) {
255
252
                if (fts_expunge_log_append_commit(&ctx->expunge_ctx) < 0)
271
268
                                str_tabescape(ctx->first_box_vname));
272
269
                        fd = fts_indexer_cmd(user, cmd, &path);
273
270
                        if (fd != -1)
274
 
                                (void)close(fd);
 
271
                                i_close_fd(&fd);
275
272
                }
276
273
        }
277
274
 
288
285
                (struct lucene_fts_backend_update_context *)_ctx;
289
286
 
290
287
        if (ctx->last_uid != 0) {
291
 
                (void)fts_index_set_last_uid(ctx->box, ctx->last_uid);
 
288
                fts_index_set_last_uid(ctx->box, ctx->last_uid);
292
289
                ctx->last_uid = 0;
293
290
        }
294
291
        if (ctx->first_box_vname == NULL)
469
466
}
470
467
 
471
468
/* a char* hash function from ASU -- from glib */
472
 
static unsigned int wstr_hash(const void *p)
 
469
static unsigned int wstr_hash(const wchar_t *s)
473
470
{
474
 
        const wchar_t *s = p;
475
471
        unsigned int g, h = 0;
476
472
 
477
473
        while (*s != '\0') {
488
484
 
489
485
static int
490
486
mailboxes_get_guids(struct mailbox *const boxes[],
491
 
                    struct hash_table *guids, struct fts_multi_result *result)
 
487
                    HASH_TABLE_TYPE(wguid_result) guids,
 
488
                    struct fts_multi_result *result)
492
489
{
493
 
        ARRAY_DEFINE(box_results, struct fts_result);
 
490
        ARRAY(struct fts_result) box_results;
494
491
        struct fts_result *box_result;
495
492
        const char *guid;
496
493
        wchar_t *guid_dup;
511
508
                hash_table_insert(guids, guid_dup, box_result);
512
509
        }
513
510
 
514
 
        (void)array_append_space(&box_results);
 
511
        array_append_zero(&box_results);
515
512
        result->box_results = array_idx_modifiable(&box_results, 0);
516
513
        return 0;
517
514
}
527
524
        int ret;
528
525
 
529
526
        T_BEGIN {
530
 
                struct hash_table *guids;
 
527
                HASH_TABLE_TYPE(wguid_result) guids;
531
528
 
532
 
                guids = hash_table_create(default_pool, default_pool, 0,
533
 
                                          wstr_hash,
534
 
                                          (hash_cmp_callback_t *)wcscmp);
 
529
                hash_table_create(&guids, default_pool, 0, wstr_hash, wcscmp);
535
530
                ret = mailboxes_get_guids(boxes, guids, result);
536
531
                if (ret == 0) {
537
532
                        ret = lucene_index_lookup_multi(backend->index,
547
542
{
548
543
        /* the next refresh is going to close the index anyway, so we might as
549
544
           well do it now */
550
 
        fts_backend_lucene_refresh(_backend);
 
545
        (void)fts_backend_lucene_refresh(_backend);
551
546
}
552
547
 
553
548
struct fts_backend fts_backend_lucene = {