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

« back to all changes in this revision

Viewing changes to src/lib-storage/index/mbox/mbox-sync-list-index.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) 2013 Dovecot authors, see the included COPYING file */
 
2
 
 
3
#include "lib.h"
 
4
#include "mbox-storage.h"
 
5
#include "mbox-sync-private.h"
 
6
 
 
7
static unsigned int
 
8
mbox_list_get_ext_id(struct mbox_mailbox *mbox,
 
9
                     struct mail_index_view *view)
 
10
{
 
11
        if (mbox->mbox_list_index_ext_id == (uint32_t)-1) {
 
12
                mbox->mbox_list_index_ext_id =
 
13
                        mail_index_ext_register(mail_index_view_get_index(view),
 
14
                                "mbox", 0,
 
15
                                sizeof(struct mbox_list_index_record),
 
16
                                sizeof(uint32_t));
 
17
        }
 
18
        return mbox->mbox_list_index_ext_id;
 
19
}
 
20
 
 
21
int mbox_list_index_has_changed(struct mailbox *box,
 
22
                                struct mail_index_view *list_view,
 
23
                                uint32_t seq)
 
24
{
 
25
        struct mbox_mailbox *mbox = (struct mbox_mailbox *)box;
 
26
        const struct mbox_list_index_record *rec;
 
27
        const void *data;
 
28
        const char *path;
 
29
        struct stat st;
 
30
        uint32_t ext_id;
 
31
        bool expunged;
 
32
        int ret;
 
33
 
 
34
        ret = index_storage_list_index_has_changed(box, list_view, seq);
 
35
        if (ret != 0)
 
36
                return ret;
 
37
 
 
38
        ext_id = mbox_list_get_ext_id(mbox, list_view);
 
39
        mail_index_lookup_ext(list_view, seq, ext_id, &data, &expunged);
 
40
        rec = data;
 
41
 
 
42
        if (rec == NULL || expunged || rec->mtime == 0) {
 
43
                /* doesn't exist or not synced */
 
44
                return 1;
 
45
        }
 
46
 
 
47
        ret = mailbox_get_path_to(box, MAILBOX_LIST_PATH_TYPE_MAILBOX, &path);
 
48
        if (ret < 0)
 
49
                return ret;
 
50
        i_assert(ret > 0);
 
51
 
 
52
        if (stat(path, &st) < 0) {
 
53
                mail_storage_set_critical(box->storage,
 
54
                                          "stat(%s) failed: %m", path);
 
55
                return -1;
 
56
        }
 
57
        if ((time_t)rec->mtime != st.st_mtime ||
 
58
            rec->size != (uint32_t)(st.st_size & 0xffffffffU))
 
59
                return 1;
 
60
        return 0;
 
61
}
 
62
 
 
63
void mbox_list_index_update_sync(struct mailbox *box,
 
64
                                 struct mail_index_transaction *trans,
 
65
                                 uint32_t seq)
 
66
{
 
67
        struct mbox_mailbox *mbox = (struct mbox_mailbox *)box;
 
68
        struct mail_index_view *list_view;
 
69
        const struct mbox_index_header *mhdr = &mbox->mbox_hdr;
 
70
        const struct mbox_list_index_record *old_rec;
 
71
        struct mbox_list_index_record new_rec;
 
72
        const void *data;
 
73
        uint32_t ext_id;
 
74
        bool expunged;
 
75
 
 
76
        index_storage_list_index_update_sync(box, trans, seq);
 
77
 
 
78
        /* get the current record */
 
79
        list_view = mail_index_transaction_get_view(trans);
 
80
        ext_id = mbox_list_get_ext_id(mbox, list_view);
 
81
        mail_index_lookup_ext(list_view, seq, ext_id, &data, &expunged);
 
82
        if (expunged)
 
83
                return;
 
84
        old_rec = data;
 
85
 
 
86
        memset(&new_rec, 0, sizeof(new_rec));
 
87
        new_rec.mtime = mhdr->sync_mtime;
 
88
        new_rec.size = mhdr->sync_size & 0xffffffffU;
 
89
 
 
90
        if (old_rec == NULL ||
 
91
            memcmp(old_rec, &new_rec, sizeof(*old_rec)) != 0)
 
92
                mail_index_update_ext(trans, seq, ext_id, &new_rec, NULL);
 
93
}