~james-page/ubuntu/raring/dovecot/autopkgtest

« back to all changes in this revision

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

  • Committer: Package Import Robot
  • Author(s): James Page
  • Date: 2012-06-11 11:11:54 UTC
  • mfrom: (1.15.2) (4.1.27 sid)
  • Revision ID: package-import@ubuntu.com-20120611111154-678cwbdj6ktgsv1h
Tags: 1:2.1.7-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/{control,rules}: enable PIE hardening.
  + 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.
  + d/control: Added Pre-Depends: dpkg (>= 1.15.6) to dovecot-dbg to support
    xz compression in Ubuntu.
  + d/control: Demote dovecot-common Recommends: to Suggests: to prevent
    install of extra packages on upgrade.
  + d/patches/dovecot-drac.patch: Updated with version for dovecot >= 2.0.0.
  + d/control: Drop B-D on systemd.
* Dropped changes:
  + d/patches/fix-racey-restart.patch: part of 2.1.x, no longer required.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* Copyright (c) 2003-2011 Dovecot authors, see the included COPYING file */
 
1
/* Copyright (c) 2003-2012 Dovecot authors, see the included COPYING file */
2
2
 
3
3
#include "lib.h"
4
4
#include "ioloop.h"
77
77
        array_free(&index->keywords);
78
78
        array_free(&index->module_contexts);
79
79
 
 
80
        i_free(index->ext_hdr_init_data);
80
81
        i_free(index->gid_origin);
81
82
        i_free(index->error);
82
83
        i_free(index->dir);
110
111
        index->max_lock_timeout_secs = max_timeout_secs;
111
112
}
112
113
 
 
114
void mail_index_set_ext_init_data(struct mail_index *index, uint32_t ext_id,
 
115
                                  const void *data, size_t size)
 
116
{
 
117
        const struct mail_index_registered_ext *rext;
 
118
 
 
119
        i_assert(index->ext_hdr_init_data == NULL ||
 
120
                 index->ext_hdr_init_id == ext_id);
 
121
 
 
122
        rext = array_idx(&index->extensions, ext_id);
 
123
        i_assert(rext->hdr_size == size);
 
124
 
 
125
        index->ext_hdr_init_id = ext_id;
 
126
        i_free(index->ext_hdr_init_data);
 
127
        index->ext_hdr_init_data = i_malloc(size);
 
128
        memcpy(index->ext_hdr_init_data, data, size);
 
129
}
 
130
 
113
131
uint32_t mail_index_ext_register(struct mail_index *index, const char *name,
114
132
                                 uint32_t default_hdr_size,
115
133
                                 uint16_t default_record_size,
504
522
                        return -1;
505
523
        }
506
524
 
507
 
        index->cache = created ? mail_cache_create(index) :
508
 
                mail_cache_open_or_create(index);
 
525
        if (index->cache == NULL) {
 
526
                index->cache = created ? mail_cache_create(index) :
 
527
                        mail_cache_open_or_create(index);
 
528
        }
 
529
        return 1;
 
530
}
 
531
 
 
532
static int
 
533
mail_index_open_opened(struct mail_index *index,
 
534
                       enum mail_index_open_flags flags)
 
535
{
 
536
        int ret;
 
537
 
 
538
        i_assert(index->map != NULL);
 
539
 
 
540
        if ((index->map->hdr.flags & MAIL_INDEX_HDR_FLAG_CORRUPTED) != 0) {
 
541
                /* index was marked corrupted. we'll probably need to
 
542
                   recreate the files. */
 
543
                if (index->map != NULL)
 
544
                        mail_index_unmap(&index->map);
 
545
                mail_index_close_file(index);
 
546
                mail_transaction_log_close(index->log);
 
547
                if ((ret = mail_index_open_files(index, flags)) <= 0)
 
548
                        return ret;
 
549
        }
 
550
 
 
551
        index->open_count++;
509
552
        return 1;
510
553
}
511
554
 
514
557
        int ret;
515
558
 
516
559
        if (index->open_count > 0) {
517
 
                i_assert(index->map != NULL);
518
 
                index->open_count++;
519
 
                return 1;
 
560
                if ((ret = mail_index_open_opened(index, flags)) <= 0) {
 
561
                        /* doesn't exist and create flag not used */
 
562
                        index->open_count++;
 
563
                        mail_index_close(index);
 
564
                }
 
565
                return ret;
520
566
        }
521
567
 
522
568
        index->filepath = MAIL_INDEX_IS_IN_MEMORY(index) ?
542
588
            (flags & MAIL_INDEX_OPEN_FLAG_MMAP_DISABLE) == 0)
543
589
                i_fatal("nfs flush requires mmap_disable=yes");
544
590
 
 
591
        /* NOTE: increase open_count only after mail_index_open_files().
 
592
           it's used elsewhere to check if we're doing an initial opening
 
593
           of the index files */
545
594
        if ((ret = mail_index_open_files(index, flags)) <= 0) {
546
595
                /* doesn't exist and create flag not used */
547
596
                index->open_count++;
589
638
        if (--index->open_count > 0)
590
639
                return;
591
640
 
 
641
        i_assert(!index->syncing);
 
642
        i_assert(index->view_count == 0);
 
643
 
592
644
        if (index->map != NULL)
593
645
                mail_index_unmap(&index->map);
594
646
 
768
820
                if (unlink(index->filepath) < 0 &&
769
821
                    errno != ENOENT && errno != ESTALE)
770
822
                        mail_index_set_syscall_error(index, "unlink()");
 
823
                (void)mail_transaction_log_unlink(index->log);
771
824
        }
772
825
}
773
826