~ubuntu-branches/ubuntu/trusty/dovecot/trusty-updates

« back to all changes in this revision

Viewing changes to src/lib-index/mail-index-strmap.c

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2014-01-08 09:35:49 UTC
  • mfrom: (1.15.3) (96.1.1 trusty-proposed)
  • Revision ID: package-import@ubuntu.com-20140108093549-814nkqdcxfbvgktg
Tags: 1:2.2.9-1ubuntu1
* Merge from Debian unstable, remaining changes:
  + Add mail-stack-delivery package:
    - Update d/rules
    - d/control: convert existing dovecot-postfix package to a dummy
      package and add new mail-stack-delivery package.
    - Update maintainer scripts.
    - Rename d/dovecot-postfix.* to debian/mail-stack-delivery.*
    - d/mail-stack-delivery.preinst: Move previously installed backups and
      config files to a new package namespace.
    - d/mail-stack-delivery.prerm: Added to handle downgrades.
  + Use Snakeoil SSL certificates by default:
    - d/control: Depend on ssl-cert.
    - d/dovecot-core.postinst: Relax grep for SSL_* a bit.
  + Add autopkgtest to debian/tests/*.
  + Add ufw integration:
    - d/dovecot-core.ufw.profile: new ufw profile.
    - d/rules: install profile in dovecot-core.
    - d/control: dovecot-core - suggest ufw.
  + d/dovecot-core.dirs: Added usr/share/doc/dovecot-core
  + Add apport hook:
    - d/rules, d/source_dovecot.py
  + Add upstart job:
    - d/rules, d/dovecot-core.dovecot.upstart, d/control,
      d/dovecot-core.dirs, dovecot-imapd.{postrm, postinst, prerm},
      d/dovecot-pop3d.{postinst, postrm, prerm}.
      d/mail-stack-deliver.postinst: Convert init script to upstart.
  + Use the autotools-dev dh addon to update config.guess/config.sub for
    arm64.
* Dropped changes, included in Debian:
  - Update Dovecot name to reflect distribution in login greeting.
  - Update Drac plugin for >= 2.0.0 support.
* d/control: Drop dovecot-postfix package as its no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2008-2012 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2008-2013 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "array.h"
31
31
        struct mail_index_view *view;
32
32
 
33
33
        ARRAY_TYPE(mail_index_strmap_rec) recs;
34
 
        ARRAY_DEFINE(recs_crc32, uint32_t);
 
34
        ARRAY(uint32_t) recs_crc32;
35
35
        struct hash2_table *hash;
36
36
 
37
37
        mail_index_strmap_key_cmp_t *key_compare;
238
238
        view->desynced = FALSE;
239
239
}
240
240
 
241
 
static void
242
 
mail_index_strmap_view_set_corrupted(struct mail_index_strmap_view *view)
 
241
void mail_index_strmap_view_set_corrupted(struct mail_index_strmap_view *view)
243
242
{
244
243
        mail_index_set_error(view->strmap->index,
245
244
                             "Corrupted strmap index file: %s",
403
402
                   see if it's because the strmap is corrupted or because
404
403
                   our current view is a bit stale and the message has already
405
404
                   been expunged. */
406
 
                (void)mail_index_refresh(ctx->view->view->index);
 
405
                mail_index_refresh(ctx->view->view->index);
407
406
                if (mail_index_is_expunged(ctx->view->view,
408
407
                                           ctx->uid_lookup_idx + 1))
409
408
                        ctx->lost_expunged_uid = rec->uid;
803
802
        rec.ref_index = ref_index;
804
803
        rec.str_idx = view->next_str_idx++;
805
804
        array_append(&view->recs, &rec, 1);
806
 
        (void)array_append_space(&view->recs_crc32);
 
805
        array_append_zero(&view->recs_crc32);
807
806
 
808
807
        view->last_added_uid = uid;
809
808
        view->last_ref_index = ref_index;
813
812
mail_index_strmap_zero_terminate(struct mail_index_strmap_view *view)
814
813
{
815
814
        /* zero-terminate the records array */
816
 
        (void)array_append_space(&view->recs);
 
815
        array_append_zero(&view->recs);
817
816
        array_delete(&view->recs, array_count(&view->recs)-1, 1);
818
817
}
819
818
 
884
883
        i_free(renumber_map);
885
884
}
886
885
 
887
 
static int mail_index_strmap_write_block(struct mail_index_strmap_view *view,
888
 
                                         struct ostream *output,
889
 
                                         unsigned int i, uint32_t base_uid)
 
886
static void mail_index_strmap_write_block(struct mail_index_strmap_view *view,
 
887
                                          struct ostream *output,
 
888
                                          unsigned int i, uint32_t base_uid)
890
889
{
891
890
        const struct mail_index_strmap_rec *recs;
892
891
        const uint32_t *crc32;
898
897
        /* skip over the block size for now, we don't know it yet */
899
898
        block_offset = output->offset;
900
899
        block_size = 0;
901
 
        o_stream_send(output, &block_size, sizeof(block_size));
 
900
        o_stream_nsend(output, &block_size, sizeof(block_size));
902
901
 
903
902
        /* write records */
904
903
        recs = array_get(&view->recs, &count);
936
935
                }
937
936
 
938
937
                mail_index_pack_num(&p, n);
939
 
                o_stream_send(output, packed, p-packed);
 
938
                o_stream_nsend(output, packed, p-packed);
940
939
                for (j = 0; j < uid_rec_count; j++)
941
 
                        o_stream_send(output, &crc32[i+j], sizeof(crc32[i+j]));
 
940
                        o_stream_nsend(output, &crc32[i+j], sizeof(crc32[i+j]));
942
941
                for (j = 0; j < uid_rec_count; j++) {
943
942
                        i_assert(j < 2 || recs[i+j].ref_index == j+1);
944
 
                        o_stream_send(output, &recs[i+j].str_idx,
945
 
                                      sizeof(recs[i+j].str_idx));
 
943
                        o_stream_nsend(output, &recs[i+j].str_idx,
 
944
                                       sizeof(recs[i+j].str_idx));
946
945
                }
947
946
                i += uid_rec_count;
948
947
        }
953
952
        i_assert(block_size != 0);
954
953
 
955
954
        end_offset = output->offset;
956
 
        o_stream_seek(output, block_offset);
957
 
        o_stream_send(output, &block_size, sizeof(block_size));
958
 
        o_stream_seek(output, end_offset);
 
955
        (void)o_stream_seek(output, block_offset);
 
956
        o_stream_nsend(output, &block_size, sizeof(block_size));
 
957
        (void)o_stream_seek(output, end_offset);
959
958
 
960
959
        if (output->last_failed_errno != 0)
961
 
                return -1;
962
 
        else {
963
 
                i_assert(view->last_added_uid == recs[count-1].uid);
964
 
                view->last_read_uid = recs[count-1].uid;
965
 
                view->last_read_block_offset = output->offset;
966
 
                return 0;
967
 
        }
 
960
                return;
 
961
 
 
962
        i_assert(view->last_added_uid == recs[count-1].uid);
 
963
        view->last_read_uid = recs[count-1].uid;
 
964
        view->last_read_block_offset = output->offset;
968
965
}
969
966
 
970
967
static void
980
977
        memset(&hdr, 0, sizeof(hdr));
981
978
        hdr.version = MAIL_INDEX_STRMAP_VERSION;
982
979
        hdr.uid_validity = idx_hdr->uid_validity;
983
 
        o_stream_send(output, &hdr, sizeof(hdr));
 
980
        o_stream_nsend(output, &hdr, sizeof(hdr));
984
981
 
985
982
        view->total_ref_count = 0;
986
 
        (void)mail_index_strmap_write_block(view, output, 0, 1);
 
983
        mail_index_strmap_write_block(view, output, 0, 1);
987
984
}
988
985
 
989
986
static int mail_index_strmap_recreate(struct mail_index_strmap_view *view)
1017
1014
        output = o_stream_create_fd(fd, 0, FALSE);
1018
1015
        o_stream_cork(output);
1019
1016
        mail_index_strmap_recreate_write(view, output);
1020
 
        if (output->last_failed_errno != 0) {
1021
 
                errno = output->last_failed_errno;
 
1017
        if (o_stream_nfinish(output) < 0) {
1022
1018
                mail_index_set_error(strmap->index,
1023
1019
                                     "write(%s) failed: %m", temp_path);
1024
1020
                ret = -1;
1170
1166
 
1171
1167
        /* write the new records */
1172
1168
        output = o_stream_create_fd(view->strmap->fd, 0, FALSE);
1173
 
        o_stream_seek(output, view->last_read_block_offset);
 
1169
        (void)o_stream_seek(output, view->last_read_block_offset);
1174
1170
        o_stream_cork(output);
1175
 
        if (mail_index_strmap_write_block(view, output, i,
1176
 
                                          view->last_read_uid + 1) < 0) {
1177
 
                errno = output->last_failed_errno;
 
1171
        mail_index_strmap_write_block(view, output, i,
 
1172
                                      view->last_read_uid + 1);
 
1173
        if (o_stream_nfinish(output) < 0) {
1178
1174
                mail_index_strmap_set_syscall_error(view->strmap, "write()");
1179
1175
                ret = -1;
1180
1176
        }
1241
1237
        mail_index_strmap_zero_terminate(view);
1242
1238
 
1243
1239
        /* zero-terminate the records array */
1244
 
        (void)array_append_space(&view->recs);
 
1240
        array_append_zero(&view->recs);
1245
1241
        array_delete(&view->recs, array_count(&view->recs)-1, 1);
1246
1242
}
1247
1243