annotate src/lib-index/mail-index-transaction-update.c @ 22576:707ae9de3812

lib: istream-multiplex - Minor code cleanup Avoid propagating the error twice, and avoid any confusion about what "got" actually contains.
author Timo Sirainen <timo.sirainen@dovecot.fi>
date Thu, 05 Oct 2017 20:24:11 +0300
parents 542b9643d6b1
children cb108f786fb4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21390
2e2563132d5f Updated copyright notices to include the year 2017.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21389
diff changeset
1 /* Copyright (c) 2003-2017 Dovecot authors, see the included COPYING file */
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
2
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
3 /* Inside transaction we keep messages stored in sequences in uid fields.
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
4 Before they're written to transaction log the sequences are changed to
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
5 UIDs. */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
6
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
7 #include "lib.h"
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
8 #include "array.h"
21855
d9283deab5d1 lib-index: Use time_to_local_day_start() instead of reimplementing
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21750
diff changeset
9 #include "time-util.h"
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
10 #include "mail-index-private.h"
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
11 #include "mail-index-transaction-private.h"
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
12
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
13 static bool
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
14 mail_index_transaction_has_ext_changes(struct mail_index_transaction *t);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
15
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
16 struct mail_index_record *
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
17 mail_index_transaction_lookup(struct mail_index_transaction *t, uint32_t seq)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
18 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
19 i_assert(seq >= t->first_new_seq && seq <= t->last_new_seq);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
20
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
21 return array_idx_modifiable(&t->appends, seq - t->first_new_seq);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
22 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
23
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
24 void mail_index_transaction_reset_v(struct mail_index_transaction *t)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
25 {
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
26 ARRAY_TYPE(seq_array) *rec;
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
27 struct mail_index_transaction_ext_hdr_update *ext_hdr;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
28
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
29 if (array_is_created(&t->ext_rec_updates)) {
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
30 array_foreach_modifiable(&t->ext_rec_updates, rec) {
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
31 if (array_is_created(rec))
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
32 array_free(rec);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
33 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
34 array_free(&t->ext_rec_updates);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
35 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
36 if (array_is_created(&t->ext_rec_atomics)) {
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
37 array_foreach_modifiable(&t->ext_rec_atomics, rec) {
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
38 if (array_is_created(rec))
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
39 array_free(rec);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
40 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
41 array_free(&t->ext_rec_atomics);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
42 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
43 if (array_is_created(&t->ext_hdr_updates)) {
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
44 array_foreach_modifiable(&t->ext_hdr_updates, ext_hdr) {
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
45 i_free(ext_hdr->data);
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
46 i_free(ext_hdr->mask);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
47 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
48 array_free(&t->ext_hdr_updates);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
49 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
50
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
51 if (array_is_created(&t->keyword_updates)) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
52 struct mail_index_transaction_keyword_update *u;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
53
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
54 array_foreach_modifiable(&t->keyword_updates, u) {
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
55 if (array_is_created(&u->add_seq))
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
56 array_free(&u->add_seq);
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
57 if (array_is_created(&u->remove_seq))
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
58 array_free(&u->remove_seq);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
59 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
60 array_free(&t->keyword_updates);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
61 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
62
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
63 if (array_is_created(&t->appends))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
64 array_free(&t->appends);
9691
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
65 if (array_is_created(&t->modseq_updates))
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
66 array_free(&t->modseq_updates);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
67 if (array_is_created(&t->expunges))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
68 array_free(&t->expunges);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
69 if (array_is_created(&t->updates))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
70 array_free(&t->updates);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
71 if (array_is_created(&t->ext_resizes))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
72 array_free(&t->ext_resizes);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
73 if (array_is_created(&t->ext_resets))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
74 array_free(&t->ext_resets);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
75 if (array_is_created(&t->ext_reset_ids))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
76 array_free(&t->ext_reset_ids);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
77 if (array_is_created(&t->ext_reset_atomic))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
78 array_free(&t->ext_reset_atomic);
16023
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
79 if (t->attribute_updates != NULL)
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
80 buffer_free(&t->attribute_updates);
16208
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
81 if (t->attribute_updates_suffix != NULL)
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
82 buffer_free(&t->attribute_updates_suffix);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
83
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
84 t->first_new_seq = mail_index_view_get_messages_count(t->view)+1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
85 t->last_new_seq = 0;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
86 t->last_update_idx = 0;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
87 t->min_flagupdate_seq = 0;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
88 t->max_flagupdate_seq = 0;
9725
1411f157ffdd lib-index: Added mail_index_update_highest_modseq().
Timo Sirainen <tss@iki.fi>
parents: 9724
diff changeset
89 t->min_highest_modseq = 0;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
90
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
91 memset(t->pre_hdr_mask, 0, sizeof(t->pre_hdr_mask));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
92 memset(t->post_hdr_mask, 0, sizeof(t->post_hdr_mask));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
93
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
94 t->appends_nonsorted = FALSE;
9624
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
95 t->expunges_nonsorted = FALSE;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
96 t->drop_unnecessary_flag_updates = FALSE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
97 t->pre_hdr_changed = FALSE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
98 t->post_hdr_changed = FALSE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
99 t->reset = FALSE;
10655
fc0ac73f0b36 Added support for marking mailbox index deleted. Don't allow any changes after that.
Timo Sirainen <tss@iki.fi>
parents: 10618
diff changeset
100 t->index_deleted = FALSE;
10674
22354f505277 lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents: 10673
diff changeset
101 t->index_undeleted = FALSE;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
102 t->log_updates = FALSE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
103 t->log_ext_updates = FALSE;
17609
16d4cf2c0d65 lib-index: Don't update log_file_tail_offset unnecessarily.
Timo Sirainen <tss@iki.fi>
parents: 17130
diff changeset
104 t->tail_offset_changed = FALSE;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
105 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
106
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
107 void mail_index_transaction_set_log_updates(struct mail_index_transaction *t)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
108 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
109 /* flag updates aren't included in log_updates */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
110 t->log_updates = array_is_created(&t->appends) ||
9691
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
111 array_is_created(&t->modseq_updates) ||
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
112 array_is_created(&t->expunges) ||
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
113 array_is_created(&t->keyword_updates) ||
16023
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
114 t->attribute_updates != NULL ||
9725
1411f157ffdd lib-index: Added mail_index_update_highest_modseq().
Timo Sirainen <tss@iki.fi>
parents: 9724
diff changeset
115 t->pre_hdr_changed || t->post_hdr_changed ||
1411f157ffdd lib-index: Added mail_index_update_highest_modseq().
Timo Sirainen <tss@iki.fi>
parents: 9724
diff changeset
116 t->min_highest_modseq != 0;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
117 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
118
21570
d1860907acf9 lib-index: Add day_stamp parameter to mail_index_update_day_headers()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
119 void mail_index_update_day_headers(struct mail_index_transaction *t,
d1860907acf9 lib-index: Add day_stamp parameter to mail_index_update_day_headers()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21390
diff changeset
120 time_t day_stamp)
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
121 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
122 struct mail_index_header hdr;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
123 const struct mail_index_record *rec;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
124 const int max_days = N_ELEMENTS(hdr.day_first_uid);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
125 time_t stamp;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
126 int i, days;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
127
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
128 hdr = *mail_index_get_header(t->view);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
129 rec = array_idx(&t->appends, 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
130
21855
d9283deab5d1 lib-index: Use time_to_local_day_start() instead of reimplementing
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21750
diff changeset
131 stamp = time_to_local_day_start(day_stamp);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
132 if ((time_t)hdr.day_stamp >= stamp)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
133 return;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
134
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
135 /* get number of days since last message */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
136 days = (stamp - hdr.day_stamp) / (3600*24);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
137 if (days > max_days)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
138 days = max_days;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
139
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
140 /* @UNSAFE: move days forward and fill the missing days with old
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
141 day_first_uid[0]. */
21571
3538545077cb lib-index: Fix updating mail_index_header.day_first_uid
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21570
diff changeset
142 if (days > 0 && days < max_days)
20654
afabdcf82622 lib-index: Do not do pointless memmove
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20312
diff changeset
143 memmove(hdr.day_first_uid + days, hdr.day_first_uid,
afabdcf82622 lib-index: Do not do pointless memmove
Aki Tuomi <aki.tuomi@dovecot.fi>
parents: 20312
diff changeset
144 (max_days - days) * sizeof(hdr.day_first_uid[0]));
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
145 for (i = 1; i < days; i++)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
146 hdr.day_first_uid[i] = hdr.day_first_uid[0];
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
147
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
148 hdr.day_stamp = stamp;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
149 hdr.day_first_uid[0] = rec->uid;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
150
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
151 mail_index_update_header(t,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
152 offsetof(struct mail_index_header, day_stamp),
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
153 &hdr.day_stamp, sizeof(hdr.day_stamp), FALSE);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
154 mail_index_update_header(t,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
155 offsetof(struct mail_index_header, day_first_uid),
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
156 hdr.day_first_uid, sizeof(hdr.day_first_uid), FALSE);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
157 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
158
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
159 void mail_index_append(struct mail_index_transaction *t, uint32_t uid,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
160 uint32_t *seq_r)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
161 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
162 struct mail_index_record *rec;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
163
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
164 i_assert(!t->no_appends);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
165
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
166 t->log_updates = TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
167
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
168 if (!array_is_created(&t->appends))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
169 i_array_init(&t->appends, 32);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
170
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
171 /* sequence number is visible only inside given view,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
172 so let it generate it */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
173 if (t->last_new_seq != 0)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
174 *seq_r = ++t->last_new_seq;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
175 else
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
176 *seq_r = t->last_new_seq = t->first_new_seq;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
177
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
178 rec = array_append_space(&t->appends);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
179 if (uid != 0) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
180 rec->uid = uid;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
181 if (!t->appends_nonsorted &&
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
182 t->last_new_seq != t->first_new_seq) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
183 /* if previous record's UID is larger than this one,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
184 we'll have to sort the appends later */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
185 rec = mail_index_transaction_lookup(t, *seq_r - 1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
186 if (rec->uid > uid)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
187 t->appends_nonsorted = TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
188 else if (rec->uid == uid)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
189 i_panic("Duplicate UIDs added in transaction");
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
190 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
191 if (t->highest_append_uid < uid)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
192 t->highest_append_uid = uid;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
193 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
194 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
195
9684
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
196 void mail_index_append_finish_uids(struct mail_index_transaction *t,
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
197 uint32_t first_uid,
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
198 ARRAY_TYPE(seq_range) *uids_r)
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
199 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
200 struct mail_index_record *recs;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
201 unsigned int i, count;
9684
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
202 struct seq_range *range;
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
203 uint32_t next_uid;
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
204
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
205 if (!array_is_created(&t->appends))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
206 return;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
207
21871
6616f1c6e20b lib-index: Assert in mail_index_append_finish_uids() to prevent UID wrapping
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21855
diff changeset
208 i_assert(first_uid < (uint32_t)-1);
6616f1c6e20b lib-index: Assert in mail_index_append_finish_uids() to prevent UID wrapping
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21855
diff changeset
209
9684
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
210 /* first find the highest assigned uid */
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
211 recs = array_get_modifiable(&t->appends, &count);
9684
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
212 i_assert(count > 0);
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
213
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
214 next_uid = first_uid;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
215 for (i = 0; i < count; i++) {
9684
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
216 if (next_uid <= recs[i].uid)
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
217 next_uid = recs[i].uid + 1;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
218 }
21871
6616f1c6e20b lib-index: Assert in mail_index_append_finish_uids() to prevent UID wrapping
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21855
diff changeset
219 i_assert(next_uid > 0 && next_uid < (uint32_t)-1);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
220
9684
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
221 /* assign missing uids */
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
222 for (i = 0; i < count; i++) {
21871
6616f1c6e20b lib-index: Assert in mail_index_append_finish_uids() to prevent UID wrapping
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21855
diff changeset
223 if (recs[i].uid == 0 || recs[i].uid < first_uid) {
6616f1c6e20b lib-index: Assert in mail_index_append_finish_uids() to prevent UID wrapping
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21855
diff changeset
224 i_assert(next_uid < (uint32_t)-1);
9684
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
225 recs[i].uid = next_uid++;
22374
542b9643d6b1 lib-index: Fix next_uid lookup in open transaction that has appended mails
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22004
diff changeset
226 if (t->highest_append_uid < recs[i].uid)
542b9643d6b1 lib-index: Fix next_uid lookup in open transaction that has appended mails
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 22004
diff changeset
227 t->highest_append_uid = recs[i].uid;
21871
6616f1c6e20b lib-index: Assert in mail_index_append_finish_uids() to prevent UID wrapping
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21855
diff changeset
228 } else {
15663
df2e46c38c92 lib-index: Fixed sorting appended messages when some were assigned new UIDs.
Timo Sirainen <tss@iki.fi>
parents: 15647
diff changeset
229 if (next_uid != first_uid)
15647
6139eac53d72 lib-index: Newly added messages weren't always sorted by UIDs.
Timo Sirainen <tss@iki.fi>
parents: 15263
diff changeset
230 t->appends_nonsorted = TRUE;
6139eac53d72 lib-index: Newly added messages weren't always sorted by UIDs.
Timo Sirainen <tss@iki.fi>
parents: 15263
diff changeset
231 }
9684
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
232 }
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
233
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
234 /* write the saved uids range */
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
235 array_clear(uids_r);
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
236 range = array_append_space(uids_r);
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
237 range->seq1 = range->seq2 = recs[0].uid;
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
238 for (i = 1; i < count; i++) {
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
239 if (range->seq2 + 1 == recs[i].uid)
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
240 range->seq2++;
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
241 else {
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
242 range = array_append_space(uids_r);
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
243 range->seq1 = range->seq2 = recs[i].uid;
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
244 }
fb8bc26d7194 Changed mail_index_append_assign_uids() to mail_index_append_finish_uids() with API changes.
Timo Sirainen <tss@iki.fi>
parents: 9681
diff changeset
245 }
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
246 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
247
9691
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
248 void mail_index_update_modseq(struct mail_index_transaction *t, uint32_t seq,
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
249 uint64_t min_modseq)
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
250 {
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
251 struct mail_transaction_modseq_update *u;
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
252
10321
2a2261f5a0be lib-index: Ignore modseq->1 updates, they can never happen.
Timo Sirainen <tss@iki.fi>
parents: 10038
diff changeset
253 /* modseq=1 is the minimum always and it's only for mails that were
2a2261f5a0be lib-index: Ignore modseq->1 updates, they can never happen.
Timo Sirainen <tss@iki.fi>
parents: 10038
diff changeset
254 created/modified before modseqs were enabled. */
2a2261f5a0be lib-index: Ignore modseq->1 updates, they can never happen.
Timo Sirainen <tss@iki.fi>
parents: 10038
diff changeset
255 if (min_modseq <= 1)
2a2261f5a0be lib-index: Ignore modseq->1 updates, they can never happen.
Timo Sirainen <tss@iki.fi>
parents: 10038
diff changeset
256 return;
2a2261f5a0be lib-index: Ignore modseq->1 updates, they can never happen.
Timo Sirainen <tss@iki.fi>
parents: 10038
diff changeset
257
9691
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
258 if (!array_is_created(&t->modseq_updates))
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
259 i_array_init(&t->modseq_updates, 32);
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
260
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
261 u = array_append_space(&t->modseq_updates);
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
262 u->uid = seq;
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
263 u->modseq_low32 = min_modseq & 0xffffffff;
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
264 u->modseq_high32 = min_modseq >> 32;
9725
1411f157ffdd lib-index: Added mail_index_update_highest_modseq().
Timo Sirainen <tss@iki.fi>
parents: 9724
diff changeset
265
1411f157ffdd lib-index: Added mail_index_update_highest_modseq().
Timo Sirainen <tss@iki.fi>
parents: 9724
diff changeset
266 t->log_updates = TRUE;
1411f157ffdd lib-index: Added mail_index_update_highest_modseq().
Timo Sirainen <tss@iki.fi>
parents: 9724
diff changeset
267 }
1411f157ffdd lib-index: Added mail_index_update_highest_modseq().
Timo Sirainen <tss@iki.fi>
parents: 9724
diff changeset
268
1411f157ffdd lib-index: Added mail_index_update_highest_modseq().
Timo Sirainen <tss@iki.fi>
parents: 9724
diff changeset
269 void mail_index_update_highest_modseq(struct mail_index_transaction *t,
1411f157ffdd lib-index: Added mail_index_update_highest_modseq().
Timo Sirainen <tss@iki.fi>
parents: 9724
diff changeset
270 uint64_t min_modseq)
1411f157ffdd lib-index: Added mail_index_update_highest_modseq().
Timo Sirainen <tss@iki.fi>
parents: 9724
diff changeset
271 {
10321
2a2261f5a0be lib-index: Ignore modseq->1 updates, they can never happen.
Timo Sirainen <tss@iki.fi>
parents: 10038
diff changeset
272 /* modseq=1 is the minimum always and it's only for mails that were
2a2261f5a0be lib-index: Ignore modseq->1 updates, they can never happen.
Timo Sirainen <tss@iki.fi>
parents: 10038
diff changeset
273 created/modified before modseqs were enabled. */
2a2261f5a0be lib-index: Ignore modseq->1 updates, they can never happen.
Timo Sirainen <tss@iki.fi>
parents: 10038
diff changeset
274 if (min_modseq <= 1)
2a2261f5a0be lib-index: Ignore modseq->1 updates, they can never happen.
Timo Sirainen <tss@iki.fi>
parents: 10038
diff changeset
275 return;
2a2261f5a0be lib-index: Ignore modseq->1 updates, they can never happen.
Timo Sirainen <tss@iki.fi>
parents: 10038
diff changeset
276
9725
1411f157ffdd lib-index: Added mail_index_update_highest_modseq().
Timo Sirainen <tss@iki.fi>
parents: 9724
diff changeset
277 if (t->min_highest_modseq < min_modseq)
1411f157ffdd lib-index: Added mail_index_update_highest_modseq().
Timo Sirainen <tss@iki.fi>
parents: 9724
diff changeset
278 t->min_highest_modseq = min_modseq;
1411f157ffdd lib-index: Added mail_index_update_highest_modseq().
Timo Sirainen <tss@iki.fi>
parents: 9724
diff changeset
279
1411f157ffdd lib-index: Added mail_index_update_highest_modseq().
Timo Sirainen <tss@iki.fi>
parents: 9724
diff changeset
280 t->log_updates = TRUE;
9691
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
281 }
b09d9350a2d9 Added ability to specify message's minimum modseq value.
Timo Sirainen <tss@iki.fi>
parents: 9684
diff changeset
282
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
283 static void
21293
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
284 mail_index_revert_ext(ARRAY_TYPE(seq_array_array) *ext_updates,
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
285 uint32_t seq)
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
286 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
287 ARRAY_TYPE(seq_array) *seqs;
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
288 unsigned int idx;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
289
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
290 if (!array_is_created(ext_updates))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
291 return;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
292
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
293 array_foreach_modifiable(ext_updates, seqs) {
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
294 if (array_is_created(seqs) &&
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
295 mail_index_seq_array_lookup(seqs, seq, &idx))
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
296 array_delete(seqs, idx, 1);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
297 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
298 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
299
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
300 static void
21293
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
301 mail_index_revert_changes_common(struct mail_index_transaction *t, uint32_t seq)
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
302 {
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
303 struct mail_index_transaction_keyword_update *kw_update;
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
304 unsigned int i;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
305
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
306 /* remove extension updates */
21293
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
307 mail_index_revert_ext(&t->ext_rec_updates, seq);
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
308 mail_index_revert_ext(&t->ext_rec_atomics, seq);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
309 t->log_ext_updates = mail_index_transaction_has_ext_changes(t);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
310
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
311 /* remove keywords */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
312 if (array_is_created(&t->keyword_updates)) {
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
313 array_foreach_modifiable(&t->keyword_updates, kw_update) {
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
314 if (array_is_created(&kw_update->add_seq)) {
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
315 seq_range_array_remove(&kw_update->add_seq,
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
316 seq);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
317 }
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
318 if (array_is_created(&kw_update->remove_seq)) {
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
319 seq_range_array_remove(&kw_update->remove_seq,
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
320 seq);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
321 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
322 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
323 }
9719
810a70b696fc mail_index_expunge: Drop also modseq updates when expunging a newly appended record.
Timo Sirainen <tss@iki.fi>
parents: 9691
diff changeset
324 /* remove modseqs */
810a70b696fc mail_index_expunge: Drop also modseq updates when expunging a newly appended record.
Timo Sirainen <tss@iki.fi>
parents: 9691
diff changeset
325 if (array_is_created(&t->modseq_updates) &&
810a70b696fc mail_index_expunge: Drop also modseq updates when expunging a newly appended record.
Timo Sirainen <tss@iki.fi>
parents: 9691
diff changeset
326 mail_index_seq_array_lookup((void *)&t->modseq_updates, seq, &i))
810a70b696fc mail_index_expunge: Drop also modseq updates when expunging a newly appended record.
Timo Sirainen <tss@iki.fi>
parents: 9691
diff changeset
327 array_delete(&t->modseq_updates, i, 1);
21293
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
328 }
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
329
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
330 void mail_index_revert_changes(struct mail_index_transaction *t, uint32_t seq)
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
331 {
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
332 mail_index_revert_changes_common(t, seq);
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
333 mail_index_cancel_flag_updates(t, seq);
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
334 }
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
335
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
336 static void
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
337 mail_index_expunge_last_append(struct mail_index_transaction *t, uint32_t seq)
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
338 {
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
339 i_assert(seq == t->last_new_seq);
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
340
0b5ede227460 lib-index: Add mail_index_revert_changes()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21224
diff changeset
341 mail_index_revert_changes_common(t, seq);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
342
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
343 /* and finally remove the append itself */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
344 array_delete(&t->appends, seq - t->first_new_seq, 1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
345 t->last_new_seq--;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
346 if (t->first_new_seq > t->last_new_seq) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
347 t->last_new_seq = 0;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
348 t->appends_nonsorted = FALSE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
349 array_free(&t->appends);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
350 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
351 mail_index_transaction_set_log_updates(t);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
352 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
353
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
354 void mail_index_expunge(struct mail_index_transaction *t, uint32_t seq)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
355 {
13287
957060ca5b69 Moved GUID code to liblib. Use guid_128_t type consistently everywhere.
Timo Sirainen <tss@iki.fi>
parents: 12782
diff changeset
356 static guid_128_t null_guid =
9624
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
357 { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
358 mail_index_expunge_guid(t, seq, null_guid);
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
359 }
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
360
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
361 void mail_index_expunge_guid(struct mail_index_transaction *t, uint32_t seq,
13287
957060ca5b69 Moved GUID code to liblib. Use guid_128_t type consistently everywhere.
Timo Sirainen <tss@iki.fi>
parents: 12782
diff changeset
362 const guid_128_t guid_128)
9624
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
363 {
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
364 const struct mail_transaction_expunge_guid *expunges;
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
365 struct mail_transaction_expunge_guid *expunge;
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
366 unsigned int count;
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
367
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
368 i_assert(seq > 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
369 if (seq >= t->first_new_seq) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
370 /* we can handle only the last append. otherwise we'd have to
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
371 renumber sequences and that gets tricky. for now this is
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
372 enough, since we typically want to expunge all the
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
373 appends. */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
374 mail_index_expunge_last_append(t, seq);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
375 } else {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
376 t->log_updates = TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
377
13499
79d54b6ccfe1 s/commiting/committing/
Timo Sirainen <tss@iki.fi>
parents: 12782
diff changeset
378 /* ignore duplicates here. drop them when committing. */
9624
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
379 if (!array_is_created(&t->expunges))
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
380 i_array_init(&t->expunges, 64);
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
381 else if (!t->expunges_nonsorted) {
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
382 /* usually expunges are added in increasing order. */
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
383 expunges = array_get(&t->expunges, &count);
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
384 if (count > 0 && seq < expunges[count-1].uid)
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
385 t->expunges_nonsorted = TRUE;
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
386 }
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
387 expunge = array_append_space(&t->expunges);
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
388 expunge->uid = seq;
2558ba736207 Keep track of expunged messages' GUIDs and expose them via mailbox_get_expunges().
Timo Sirainen <tss@iki.fi>
parents: 9622
diff changeset
389 memcpy(expunge->guid_128, guid_128, sizeof(expunge->guid_128));
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
390 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
391 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
392
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
393 static void update_minmax_flagupdate_seq(struct mail_index_transaction *t,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
394 uint32_t seq1, uint32_t seq2)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
395 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
396 if (t->min_flagupdate_seq == 0) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
397 t->min_flagupdate_seq = seq1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
398 t->max_flagupdate_seq = seq2;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
399 } else {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
400 if (t->min_flagupdate_seq > seq1)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
401 t->min_flagupdate_seq = seq1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
402 if (t->max_flagupdate_seq < seq2)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
403 t->max_flagupdate_seq = seq2;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
404 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
405 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
406
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
407 unsigned int
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
408 mail_index_transaction_get_flag_update_pos(struct mail_index_transaction *t,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
409 unsigned int left_idx,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
410 unsigned int right_idx,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
411 uint32_t seq)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
412 {
14599
dbd42f7198eb shared mailboxes: Per-user flags can now be stored in private index files.
Timo Sirainen <tss@iki.fi>
parents: 14580
diff changeset
413 const struct mail_index_flag_update *updates;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
414 unsigned int idx, count;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
415
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
416 updates = array_get(&t->updates, &count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
417 i_assert(left_idx <= right_idx && right_idx <= count);
16361
38ca85ccd5af Added asserts to binary searches to make sure we don't go to infinite loop.
Timo Sirainen <tss@iki.fi>
parents: 16208
diff changeset
418 i_assert(count < INT_MAX);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
419
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
420 /* find the first update with either overlapping range,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
421 or the update which will come after our insert */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
422 idx = left_idx;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
423 while (left_idx < right_idx) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
424 idx = (left_idx + right_idx) / 2;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
425
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
426 if (updates[idx].uid2 < seq)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
427 left_idx = idx+1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
428 else if (updates[idx].uid1 > seq)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
429 right_idx = idx;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
430 else
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
431 break;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
432 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
433 if (left_idx > idx)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
434 idx++;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
435 return idx;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
436 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
437
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
438 static void
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
439 mail_index_insert_flag_update(struct mail_index_transaction *t,
14599
dbd42f7198eb shared mailboxes: Per-user flags can now be stored in private index files.
Timo Sirainen <tss@iki.fi>
parents: 14580
diff changeset
440 struct mail_index_flag_update u,
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
441 unsigned int idx)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
442 {
14599
dbd42f7198eb shared mailboxes: Per-user flags can now be stored in private index files.
Timo Sirainen <tss@iki.fi>
parents: 14580
diff changeset
443 struct mail_index_flag_update *updates, tmp_update;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
444 unsigned int count, first_idx, max;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
445
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
446 updates = array_get_modifiable(&t->updates, &count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
447
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
448 /* overlapping ranges, split/merge them */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
449 i_assert(idx == 0 || updates[idx-1].uid2 < u.uid1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
450 i_assert(idx == count || updates[idx].uid2 >= u.uid1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
451
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
452 /* first we'll just add the changes without trying to merge anything */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
453 first_idx = idx;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
454 for (; idx < count && u.uid2 >= updates[idx].uid1; idx++) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
455 i_assert(u.uid1 <= updates[idx].uid2);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
456 if (u.uid1 != updates[idx].uid1 &&
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
457 (updates[idx].add_flags != u.add_flags ||
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
458 updates[idx].remove_flags != u.remove_flags)) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
459 if (u.uid1 < updates[idx].uid1) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
460 /* insert new update */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
461 tmp_update = u;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
462 tmp_update.uid2 = updates[idx].uid1 - 1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
463 } else {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
464 /* split existing update from beginning */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
465 tmp_update = updates[idx];
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
466 tmp_update.uid2 = u.uid1 - 1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
467 updates[idx].uid1 = u.uid1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
468 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
469
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
470 i_assert(tmp_update.uid1 <= tmp_update.uid2);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
471 i_assert(updates[idx].uid1 <= updates[idx].uid2);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
472
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
473 array_insert(&t->updates, idx, &tmp_update, 1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
474 updates = array_get_modifiable(&t->updates, &count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
475 idx++;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
476 } else if (u.uid1 < updates[idx].uid1) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
477 updates[idx].uid1 = u.uid1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
478 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
479
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
480 if (u.uid2 < updates[idx].uid2 &&
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
481 (updates[idx].add_flags != u.add_flags ||
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
482 updates[idx].remove_flags != u.remove_flags)) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
483 /* split existing update from end */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
484 tmp_update = updates[idx];
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
485 tmp_update.uid2 = u.uid2;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
486 updates[idx].uid1 = u.uid2 + 1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
487
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
488 i_assert(tmp_update.uid1 <= tmp_update.uid2);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
489 i_assert(updates[idx].uid1 <= updates[idx].uid2);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
490
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
491 array_insert(&t->updates, idx, &tmp_update, 1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
492 updates = array_get_modifiable(&t->updates, &count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
493 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
494
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
495 updates[idx].add_flags =
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
496 (updates[idx].add_flags | u.add_flags) &
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
497 ~u.remove_flags;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
498 updates[idx].remove_flags =
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
499 (updates[idx].remove_flags | u.remove_flags) &
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
500 ~u.add_flags;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
501 u.uid1 = updates[idx].uid2 + 1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
502
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
503 if (updates[idx].add_flags == 0 &&
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
504 updates[idx].remove_flags == 0) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
505 /* we can remove this update completely */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
506 array_delete(&t->updates, idx, 1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
507 updates = array_get_modifiable(&t->updates, &count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
508 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
509
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
510 if (u.uid1 > u.uid2) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
511 /* break here before idx++ so last_update_idx is set
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
512 correctly */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
513 break;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
514 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
515 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
516 i_assert(idx <= count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
517
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
518 if (u.uid1 <= u.uid2) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
519 i_assert(idx == 0 || updates[idx-1].uid2 < u.uid1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
520 i_assert(idx == count || updates[idx].uid1 > u.uid2);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
521 array_insert(&t->updates, idx, &u, 1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
522 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
523 updates = array_get_modifiable(&t->updates, &count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
524 t->last_update_idx = idx == count ? count-1 : idx;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
525
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
526 /* merge everything */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
527 idx = first_idx == 0 ? 0 : first_idx - 1;
10618
2893ca172707 mail_index_update_flags_range(): Fixed merging last update.
Timo Sirainen <tss@iki.fi>
parents: 10582
diff changeset
528 max = count == 0 ? 0 : I_MIN(t->last_update_idx + 1, count-1);
2893ca172707 mail_index_update_flags_range(): Fixed merging last update.
Timo Sirainen <tss@iki.fi>
parents: 10582
diff changeset
529 for (; idx < max; ) {
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
530 if (updates[idx].uid2 + 1 == updates[idx+1].uid1 &&
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
531 updates[idx].add_flags == updates[idx+1].add_flags &&
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
532 updates[idx].remove_flags == updates[idx+1].remove_flags) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
533 /* merge */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
534 updates[idx].uid2 = updates[idx+1].uid2;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
535 array_delete(&t->updates, idx + 1, 1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
536 max--;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
537 if (t->last_update_idx > idx)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
538 t->last_update_idx--;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
539 updates = array_get_modifiable(&t->updates, &count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
540 } else {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
541 idx++;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
542 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
543 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
544 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
545
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
546 static void mail_index_record_modify_flags(struct mail_index_record *rec,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
547 enum modify_type modify_type,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
548 enum mail_flags flags)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
549 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
550 switch (modify_type) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
551 case MODIFY_REPLACE:
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
552 rec->flags = flags;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
553 break;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
554 case MODIFY_ADD:
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
555 rec->flags |= flags;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
556 break;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
557 case MODIFY_REMOVE:
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
558 rec->flags &= ~flags;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
559 break;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
560 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
561 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
562
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
563 void mail_index_update_flags_range(struct mail_index_transaction *t,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
564 uint32_t seq1, uint32_t seq2,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
565 enum modify_type modify_type,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
566 enum mail_flags flags)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
567 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
568 struct mail_index_record *rec;
14599
dbd42f7198eb shared mailboxes: Per-user flags can now be stored in private index files.
Timo Sirainen <tss@iki.fi>
parents: 14580
diff changeset
569 struct mail_index_flag_update u, *last_update;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
570 unsigned int idx, first_idx, count;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
571
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
572 update_minmax_flagupdate_seq(t, seq1, seq2);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
573 if (seq2 >= t->first_new_seq) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
574 /* updates for appended messages, modify them directly */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
575 uint32_t seq;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
576
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
577 for (seq = I_MAX(t->first_new_seq, seq1); seq <= seq2; seq++) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
578 rec = mail_index_transaction_lookup(t, seq);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
579 mail_index_record_modify_flags(rec, modify_type, flags);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
580 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
581 if (seq1 >= t->first_new_seq)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
582 return;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
583
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
584 /* range contains also existing messages. update them next. */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
585 seq2 = t->first_new_seq - 1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
586 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
587
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
588 i_assert(seq1 <= seq2 && seq1 > 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
589 i_assert(seq2 <= mail_index_view_get_messages_count(t->view));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
590
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
591 if ((t->flags & MAIL_INDEX_TRANSACTION_FLAG_AVOID_FLAG_UPDATES) != 0)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
592 t->drop_unnecessary_flag_updates = TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
593
21389
59437f8764c6 global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21293
diff changeset
594 i_zero(&u);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
595 u.uid1 = seq1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
596 u.uid2 = seq2;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
597
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
598 switch (modify_type) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
599 case MODIFY_REPLACE:
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
600 u.add_flags = flags;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
601 u.remove_flags = ~flags & MAIL_INDEX_FLAGS_MASK;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
602 break;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
603 case MODIFY_ADD:
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
604 if (flags == 0)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
605 return;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
606 u.add_flags = flags;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
607 break;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
608 case MODIFY_REMOVE:
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
609 if (flags == 0)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
610 return;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
611 u.remove_flags = flags;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
612 break;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
613 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
614
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
615 if (!array_is_created(&t->updates)) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
616 i_array_init(&t->updates, 256);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
617 array_append(&t->updates, &u, 1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
618 return;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
619 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
620
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
621 last_update = array_get_modifiable(&t->updates, &count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
622 if (t->last_update_idx < count) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
623 /* fast path - hopefully we're updating the next message,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
624 or a message that is to be appended as last update */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
625 last_update += t->last_update_idx;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
626 if (seq1 - 1 == last_update->uid2) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
627 if (u.add_flags == last_update->add_flags &&
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
628 u.remove_flags == last_update->remove_flags &&
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
629 (t->last_update_idx + 1 == count ||
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
630 last_update[1].uid1 > seq2)) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
631 /* we can just update the UID range */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
632 last_update->uid2 = seq2;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
633 return;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
634 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
635 } else if (seq1 > last_update->uid2) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
636 /* hopefully we can just append it */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
637 t->last_update_idx++;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
638 last_update++;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
639 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
640 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
641
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
642 if (t->last_update_idx == count)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
643 array_append(&t->updates, &u, 1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
644 else {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
645 i_assert(t->last_update_idx < count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
646
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
647 /* slow path */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
648 if (seq1 > last_update->uid2) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
649 /* added after this */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
650 first_idx = t->last_update_idx + 1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
651 } else {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
652 /* added before this or on top of this */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
653 first_idx = 0;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
654 count = t->last_update_idx + 1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
655 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
656 idx = mail_index_transaction_get_flag_update_pos(t, first_idx,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
657 count, u.uid1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
658 mail_index_insert_flag_update(t, u, idx);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
659 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
660 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
661
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
662 void mail_index_update_flags(struct mail_index_transaction *t, uint32_t seq,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
663 enum modify_type modify_type,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
664 enum mail_flags flags)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
665 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
666 mail_index_update_flags_range(t, seq, seq, modify_type, flags);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
667 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
668
16023
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
669 static void
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
670 mail_index_attribute_set_full(struct mail_index_transaction *t,
16208
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
671 const char *key, bool pvt, char prefix,
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
672 time_t timestamp, uint32_t value_len)
16023
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
673 {
16208
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
674 uint32_t ts = timestamp;
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
675
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
676 if (t->attribute_updates == NULL) {
16023
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
677 t->attribute_updates = buffer_create_dynamic(default_pool, 64);
16208
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
678 t->attribute_updates_suffix = buffer_create_dynamic(default_pool, 64);
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
679 }
16023
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
680 buffer_append_c(t->attribute_updates, prefix);
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
681 buffer_append_c(t->attribute_updates, pvt ? 'p' : 's');
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
682 buffer_append(t->attribute_updates, key, strlen(key)+1);
16208
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
683
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
684 buffer_append(t->attribute_updates_suffix, &ts, sizeof(ts));
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
685 if (prefix == '+') {
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
686 buffer_append(t->attribute_updates_suffix,
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
687 &value_len, sizeof(value_len));
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
688 }
16023
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
689 t->log_updates = TRUE;
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
690 }
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
691
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
692 void mail_index_attribute_set(struct mail_index_transaction *t,
16208
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
693 bool pvt, const char *key,
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
694 time_t timestamp, uint32_t value_len)
16023
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
695 {
16208
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
696 mail_index_attribute_set_full(t, key, pvt, '+', timestamp, value_len);
16023
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
697 }
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
698
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
699 void mail_index_attribute_unset(struct mail_index_transaction *t,
16208
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
700 bool pvt, const char *key,
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
701 time_t timestamp)
16023
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
702 {
16208
1ef57aca7d2f lib-index: Add timestamps and value lengths to attribute change records in transaction log.
Timo Sirainen <tss@iki.fi>
parents: 16198
diff changeset
703 mail_index_attribute_set_full(t, key, pvt, '-', timestamp, 0);
16023
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
704 }
db0136374bb0 lib-index: mail_index_attribute_[un]set() adds changed attributes' keys to transaction log.
Timo Sirainen <tss@iki.fi>
parents: 15737
diff changeset
705
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
706 void mail_index_update_header(struct mail_index_transaction *t,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
707 size_t offset, const void *data, size_t size,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
708 bool prepend)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
709 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
710 i_assert(offset < sizeof(t->pre_hdr_change));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
711 i_assert(size <= sizeof(t->pre_hdr_change) - offset);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
712
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
713 t->log_updates = TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
714
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
715 if (prepend) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
716 t->pre_hdr_changed = TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
717 memcpy(t->pre_hdr_change + offset, data, size);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
718 for (; size > 0; size--)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
719 t->pre_hdr_mask[offset++] = 1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
720 } else {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
721 t->post_hdr_changed = TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
722 memcpy(t->post_hdr_change + offset, data, size);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
723 for (; size > 0; size--)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
724 t->post_hdr_mask[offset++] = 1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
725 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
726 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
727
20276
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
728 static void
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
729 mail_index_ext_rec_updates_resize(struct mail_index_transaction *t,
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
730 uint32_t ext_id, uint16_t new_record_size)
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
731 {
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
732 ARRAY_TYPE(seq_array) *array, old_array;
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
733 unsigned int i;
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
734
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
735 if (!array_is_created(&t->ext_rec_updates))
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
736 return;
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
737 array = array_idx_modifiable(&t->ext_rec_updates, ext_id);
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
738 if (!array_is_created(array))
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
739 return;
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
740
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
741 old_array = *array;
21389
59437f8764c6 global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21293
diff changeset
742 i_zero(array);
20276
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
743 mail_index_seq_array_alloc(array, new_record_size);
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
744
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
745 /* copy the records' beginnings. leave the end zero-filled. */
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
746 for (i = 0; i < array_count(&old_array); i++) {
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
747 const void *old_record = array_idx(&old_array, i);
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
748
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
749 memcpy(array_append_space(array), old_record,
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
750 old_array.arr.element_size);
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
751 }
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
752 array_free(&old_array);
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
753 }
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
754
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
755 void mail_index_ext_resize(struct mail_index_transaction *t, uint32_t ext_id,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
756 uint32_t hdr_size, uint16_t record_size,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
757 uint16_t record_align)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
758 {
20297
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
759 const struct mail_index_registered_ext *rext;
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
760 const struct mail_transaction_ext_intro *resizes;
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
761 unsigned int resizes_count;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
762 struct mail_transaction_ext_intro intro;
20297
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
763 uint32_t old_record_size = 0, old_record_align, old_header_size;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
764
21389
59437f8764c6 global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21293
diff changeset
765 i_zero(&intro);
20297
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
766 rext = array_idx(&t->view->index->extensions, ext_id);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
767
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
768 /* get ext_id from transaction's map if it's there */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
769 if (!mail_index_map_get_ext_idx(t->view->map, ext_id, &intro.ext_id)) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
770 /* have to create it */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
771 intro.ext_id = (uint32_t)-1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
772 old_record_align = rext->record_align;
16402
bd8ec99cf502 lib-index: Added mail_index_ext_resize_hdr()
Timo Sirainen <tss@iki.fi>
parents: 16361
diff changeset
773 old_header_size = rext->hdr_size;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
774 } else {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
775 const struct mail_index_ext *ext;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
776
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
777 ext = array_idx(&t->view->map->extensions, intro.ext_id);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
778 old_record_align = ext->record_align;
16402
bd8ec99cf502 lib-index: Added mail_index_ext_resize_hdr()
Timo Sirainen <tss@iki.fi>
parents: 16361
diff changeset
779 old_header_size = ext->hdr_size;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
780 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
781
20297
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
782 /* get the record size. if there are any existing record updates,
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
783 they're using the registered size, not the map's existing
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
784 record_size. */
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
785 if (array_is_created(&t->ext_resizes))
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
786 resizes = array_get(&t->ext_resizes, &resizes_count);
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
787 else {
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
788 resizes = NULL;
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
789 resizes_count = 0;
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
790 }
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
791 if (ext_id < resizes_count && resizes[ext_id].name_size != 0) {
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
792 /* already resized once. use the resized value. */
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
793 old_record_size = resizes[ext_id].record_size;
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
794 } else {
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
795 /* use the registered values. */
20312
43ea87e43f3f lib-index: mail_index_ext_resize() was broken when record_size wasn't changed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20297
diff changeset
796 old_record_size = rext->record_size;
20297
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
797 }
926381e95b53 lib-index: Extension record size resizing was still broken.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20276
diff changeset
798
20312
43ea87e43f3f lib-index: mail_index_ext_resize() was broken when record_size wasn't changed.
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20297
diff changeset
799 if (record_size != old_record_size && record_size != (uint16_t)-1) {
20276
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
800 /* if record_size grows, we'll just resize the existing
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
801 ext_rec_updates array. it's not possible to shrink
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
802 record_size without data loss. */
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
803 i_assert(record_size > old_record_size);
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
804 mail_index_ext_rec_updates_resize(t, ext_id, record_size);
d7c87461e5f2 lib-index: Allow growing ext record_size after mail_index_update_ext()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 19552
diff changeset
805 }
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
806
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
807 t->log_ext_updates = TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
808
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
809 if (!array_is_created(&t->ext_resizes))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
810 i_array_init(&t->ext_resizes, ext_id + 2);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
811
16402
bd8ec99cf502 lib-index: Added mail_index_ext_resize_hdr()
Timo Sirainen <tss@iki.fi>
parents: 16361
diff changeset
812 intro.hdr_size = hdr_size != (uint32_t)-1 ? hdr_size : old_header_size;
bd8ec99cf502 lib-index: Added mail_index_ext_resize_hdr()
Timo Sirainen <tss@iki.fi>
parents: 16361
diff changeset
813 if (record_size != (uint16_t)-1) {
bd8ec99cf502 lib-index: Added mail_index_ext_resize_hdr()
Timo Sirainen <tss@iki.fi>
parents: 16361
diff changeset
814 i_assert(record_align != (uint16_t)-1);
bd8ec99cf502 lib-index: Added mail_index_ext_resize_hdr()
Timo Sirainen <tss@iki.fi>
parents: 16361
diff changeset
815 intro.record_size = record_size;
bd8ec99cf502 lib-index: Added mail_index_ext_resize_hdr()
Timo Sirainen <tss@iki.fi>
parents: 16361
diff changeset
816 intro.record_align = record_align;
bd8ec99cf502 lib-index: Added mail_index_ext_resize_hdr()
Timo Sirainen <tss@iki.fi>
parents: 16361
diff changeset
817 } else {
bd8ec99cf502 lib-index: Added mail_index_ext_resize_hdr()
Timo Sirainen <tss@iki.fi>
parents: 16361
diff changeset
818 i_assert(record_align == (uint16_t)-1);
bd8ec99cf502 lib-index: Added mail_index_ext_resize_hdr()
Timo Sirainen <tss@iki.fi>
parents: 16361
diff changeset
819 intro.record_size = old_record_size;
bd8ec99cf502 lib-index: Added mail_index_ext_resize_hdr()
Timo Sirainen <tss@iki.fi>
parents: 16361
diff changeset
820 intro.record_align = old_record_align;
bd8ec99cf502 lib-index: Added mail_index_ext_resize_hdr()
Timo Sirainen <tss@iki.fi>
parents: 16361
diff changeset
821 }
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
822 intro.name_size = 1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
823 array_idx_set(&t->ext_resizes, ext_id, &intro);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
824 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
825
16402
bd8ec99cf502 lib-index: Added mail_index_ext_resize_hdr()
Timo Sirainen <tss@iki.fi>
parents: 16361
diff changeset
826 void mail_index_ext_resize_hdr(struct mail_index_transaction *t,
bd8ec99cf502 lib-index: Added mail_index_ext_resize_hdr()
Timo Sirainen <tss@iki.fi>
parents: 16361
diff changeset
827 uint32_t ext_id, uint32_t hdr_size)
bd8ec99cf502 lib-index: Added mail_index_ext_resize_hdr()
Timo Sirainen <tss@iki.fi>
parents: 16361
diff changeset
828 {
bd8ec99cf502 lib-index: Added mail_index_ext_resize_hdr()
Timo Sirainen <tss@iki.fi>
parents: 16361
diff changeset
829 mail_index_ext_resize(t, ext_id, hdr_size, (uint16_t)-1, (uint16_t)-1);
bd8ec99cf502 lib-index: Added mail_index_ext_resize_hdr()
Timo Sirainen <tss@iki.fi>
parents: 16361
diff changeset
830 }
bd8ec99cf502 lib-index: Added mail_index_ext_resize_hdr()
Timo Sirainen <tss@iki.fi>
parents: 16361
diff changeset
831
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
832 void mail_index_ext_reset(struct mail_index_transaction *t, uint32_t ext_id,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
833 uint32_t reset_id, bool clear_data)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
834 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
835 struct mail_transaction_ext_reset reset;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
836
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
837 i_assert(reset_id != 0);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
838
21389
59437f8764c6 global: Replaced all instances of memset(p, 0, sizeof(*p)) with the new i_zero() macro.
Stephan Bosch <stephan.bosch@dovecot.fi>
parents: 21293
diff changeset
839 i_zero(&reset);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
840 reset.new_reset_id = reset_id;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
841 reset.preserve_data = !clear_data;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
842
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
843 mail_index_ext_set_reset_id(t, ext_id, reset_id);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
844
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
845 if (!array_is_created(&t->ext_resets))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
846 i_array_init(&t->ext_resets, ext_id + 2);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
847 array_idx_set(&t->ext_resets, ext_id, &reset);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
848 t->log_ext_updates = TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
849 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
850
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
851 void mail_index_ext_reset_inc(struct mail_index_transaction *t, uint32_t ext_id,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
852 uint32_t prev_reset_id, bool clear_data)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
853 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
854 uint32_t expected_reset_id = prev_reset_id + 1;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
855
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
856 mail_index_ext_reset(t, ext_id, (uint32_t)-1, clear_data);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
857
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
858 if (!array_is_created(&t->ext_reset_atomic))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
859 i_array_init(&t->ext_reset_atomic, ext_id + 2);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
860 array_idx_set(&t->ext_reset_atomic, ext_id, &expected_reset_id);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
861 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
862
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
863 static bool
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
864 mail_index_transaction_has_ext_updates(const ARRAY_TYPE(seq_array_array) *arr)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
865 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
866 const ARRAY_TYPE(seq_array) *array;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
867
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
868 if (array_is_created(arr)) {
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
869 array_foreach(arr, array) {
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
870 if (array_is_created(array))
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
871 return TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
872 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
873 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
874 return FALSE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
875 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
876
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
877 static bool
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
878 mail_index_transaction_has_ext_changes(struct mail_index_transaction *t)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
879 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
880 if (mail_index_transaction_has_ext_updates(&t->ext_rec_updates))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
881 return TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
882 if (mail_index_transaction_has_ext_updates(&t->ext_rec_atomics))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
883 return TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
884
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
885 if (array_is_created(&t->ext_hdr_updates)) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
886 const struct mail_index_transaction_ext_hdr_update *hdr;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
887
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
888 array_foreach(&t->ext_hdr_updates, hdr) {
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
889 if (hdr->alloc_size > 0)
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
890 return TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
891 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
892 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
893 if (array_is_created(&t->ext_resets)) {
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
894 const struct mail_transaction_ext_reset *reset;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
895
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
896 array_foreach(&t->ext_resets, reset) {
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
897 if (reset->new_reset_id != 0)
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
898 return TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
899 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
900 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
901 if (array_is_created(&t->ext_resizes)) {
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
902 const struct mail_transaction_ext_intro *resize;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
903
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
904 array_foreach(&t->ext_resizes, resize) {
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
905 if (resize->name_size > 0)
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
906 return TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
907 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
908 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
909 return FALSE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
910 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
911
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
912 static void
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
913 mail_index_ext_update_reset(ARRAY_TYPE(seq_array_array) *arr, uint32_t ext_id)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
914 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
915 if (array_is_created(arr) && ext_id < array_count(arr)) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
916 /* if extension records have been updated, clear them */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
917 ARRAY_TYPE(seq_array) *array;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
918
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
919 array = array_idx_modifiable(arr, ext_id);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
920 if (array_is_created(array))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
921 array_clear(array);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
922 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
923 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
924
12250
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
925 static void
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
926 mail_index_ext_reset_changes(struct mail_index_transaction *t, uint32_t ext_id)
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
927 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
928 mail_index_ext_update_reset(&t->ext_rec_updates, ext_id);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
929 mail_index_ext_update_reset(&t->ext_rec_atomics, ext_id);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
930 if (array_is_created(&t->ext_hdr_updates) &&
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
931 ext_id < array_count(&t->ext_hdr_updates)) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
932 /* if extension headers have been updated, clear them */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
933 struct mail_index_transaction_ext_hdr_update *hdr;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
934
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
935 hdr = array_idx_modifiable(&t->ext_hdr_updates, ext_id);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
936 if (hdr->alloc_size > 0) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
937 i_free_and_null(hdr->mask);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
938 i_free_and_null(hdr->data);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
939 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
940 hdr->alloc_size = 0;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
941 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
942 if (array_is_created(&t->ext_resets) &&
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
943 ext_id < array_count(&t->ext_resets)) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
944 /* clear resets */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
945 array_idx_clear(&t->ext_resets, ext_id);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
946 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
947 if (array_is_created(&t->ext_resizes) &&
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
948 ext_id < array_count(&t->ext_resizes)) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
949 /* clear resizes */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
950 array_idx_clear(&t->ext_resizes, ext_id);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
951 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
952
12250
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
953 t->log_ext_updates = mail_index_transaction_has_ext_changes(t);
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
954 }
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
955
14682
d0d7b810646b Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents: 14677
diff changeset
956 void mail_index_ext_using_reset_id(struct mail_index_transaction *t,
12250
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
957 uint32_t ext_id, uint32_t reset_id)
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
958 {
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
959 uint32_t *reset_id_p;
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
960 bool changed;
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
961
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
962 if (!array_is_created(&t->ext_reset_ids))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
963 i_array_init(&t->ext_reset_ids, ext_id + 2);
12250
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
964 reset_id_p = array_idx_modifiable(&t->ext_reset_ids, ext_id);
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
965 changed = *reset_id_p != reset_id && *reset_id_p != 0;
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
966 *reset_id_p = reset_id;
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
967 if (changed) {
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
968 /* reset_id changed, clear existing changes */
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
969 mail_index_ext_reset_changes(t, ext_id);
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
970 }
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
971 }
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
972
12250
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
973 void mail_index_ext_set_reset_id(struct mail_index_transaction *t,
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
974 uint32_t ext_id, uint32_t reset_id)
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
975 {
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
976 mail_index_ext_using_reset_id(t, ext_id, reset_id);
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
977 /* make sure the changes get reset, even if reset_id doesn't change */
d0ddc30f0eef lib-index: Cache offsets were sometimes written pointing to an older cache file.
Timo Sirainen <tss@iki.fi>
parents: 12120
diff changeset
978 mail_index_ext_reset_changes(t, ext_id);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
979 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
980
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
981 void mail_index_update_header_ext(struct mail_index_transaction *t,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
982 uint32_t ext_id, size_t offset,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
983 const void *data, size_t size)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
984 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
985 struct mail_index_transaction_ext_hdr_update *hdr;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
986 size_t new_size;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
987
16185
87d0c4056b4d lib-index: Removed obsolete 16bit size check asserts from mail_index_update_header_ext()
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
988 i_assert(offset <= (uint32_t)-1 && size <= (uint32_t)-1 &&
87d0c4056b4d lib-index: Removed obsolete 16bit size check asserts from mail_index_update_header_ext()
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
989 offset + size <= (uint32_t)-1);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
990
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
991 if (!array_is_created(&t->ext_hdr_updates))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
992 i_array_init(&t->ext_hdr_updates, ext_id + 2);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
993
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
994 hdr = array_idx_modifiable(&t->ext_hdr_updates, ext_id);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
995 if (hdr->alloc_size < offset || hdr->alloc_size - offset < size) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
996 i_assert(size < (size_t)-1 - offset);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
997 new_size = nearest_power(offset + size);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
998 hdr->mask = i_realloc(hdr->mask, hdr->alloc_size, new_size);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
999 hdr->data = i_realloc(hdr->data, hdr->alloc_size, new_size);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1000 hdr->alloc_size = new_size;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1001 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1002 memset(hdr->mask + offset, 1, size);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1003 memcpy(hdr->data + offset, data, size);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1004
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1005 t->log_ext_updates = TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1006 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1007
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1008 void mail_index_update_ext(struct mail_index_transaction *t, uint32_t seq,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1009 uint32_t ext_id, const void *data, void *old_data_r)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1010 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1011 struct mail_index *index = t->view->index;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1012 const struct mail_index_registered_ext *rext;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1013 const struct mail_transaction_ext_intro *intro;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1014 uint16_t record_size;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1015 ARRAY_TYPE(seq_array) *array;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1016 unsigned int count;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1017
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1018 i_assert(seq > 0 &&
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1019 (seq <= mail_index_view_get_messages_count(t->view) ||
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1020 seq <= t->last_new_seq));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1021 i_assert(ext_id < array_count(&index->extensions));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1022
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1023 t->log_ext_updates = TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1024
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1025 if (!array_is_created(&t->ext_resizes)) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1026 intro = NULL;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1027 count = 0;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1028 } else {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1029 intro = array_get(&t->ext_resizes, &count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1030 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1031 if (ext_id < count && intro[ext_id].name_size != 0) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1032 /* resized record */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1033 record_size = intro[ext_id].record_size;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1034 } else {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1035 rext = array_idx(&index->extensions, ext_id);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1036 record_size = rext->record_size;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1037 }
18738
fd8edab94849 lib-index: Added asserts to make sure invalid extension records aren't written to log.
Timo Sirainen <tss@iki.fi>
parents: 18137
diff changeset
1038 i_assert(record_size > 0);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1039
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1040 if (!array_is_created(&t->ext_rec_updates))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1041 i_array_init(&t->ext_rec_updates, ext_id + 2);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1042 array = array_idx_modifiable(&t->ext_rec_updates, ext_id);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1043
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1044 /* @UNSAFE */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1045 if (!mail_index_seq_array_add(array, seq, data, record_size,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1046 old_data_r)) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1047 /* not found, clear old_data if it was given */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1048 if (old_data_r != NULL)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1049 memset(old_data_r, 0, record_size);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1050 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1051 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1052
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1053 int mail_index_atomic_inc_ext(struct mail_index_transaction *t,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1054 uint32_t seq, uint32_t ext_id, int diff)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1055 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1056 ARRAY_TYPE(seq_array) *array;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1057 int32_t old_diff32, diff32 = diff;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1058
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1059 i_assert(seq > 0 &&
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1060 (seq <= mail_index_view_get_messages_count(t->view) ||
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1061 seq <= t->last_new_seq));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1062 i_assert(ext_id < array_count(&t->view->index->extensions));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1063 /* currently non-external transactions can be applied multiple times,
10038
499f5575d503 Removed some unused FIXME code.
Timo Sirainen <tss@iki.fi>
parents: 10000
diff changeset
1064 causing multiple increments. FIXME: we need this now and it doesn't
499f5575d503 Removed some unused FIXME code.
Timo Sirainen <tss@iki.fi>
parents: 10000
diff changeset
1065 actually seem to be a real problem at least right now - why? */
499f5575d503 Removed some unused FIXME code.
Timo Sirainen <tss@iki.fi>
parents: 10000
diff changeset
1066 /*i_assert((t->flags & MAIL_INDEX_TRANSACTION_FLAG_EXTERNAL) != 0);*/
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1067
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1068 t->log_ext_updates = TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1069 if (!array_is_created(&t->ext_rec_atomics))
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1070 i_array_init(&t->ext_rec_atomics, ext_id + 2);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1071 array = array_idx_modifiable(&t->ext_rec_atomics, ext_id);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1072 if (mail_index_seq_array_add(array, seq, &diff32, sizeof(diff32),
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1073 &old_diff32)) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1074 /* already incremented this sequence in this transaction */
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1075 diff32 += old_diff32;
14682
d0d7b810646b Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents: 14677
diff changeset
1076 (void)mail_index_seq_array_add(array, seq, &diff32,
d0d7b810646b Make sure we check all the functions' return values. Minor API changes to simplify this.
Timo Sirainen <tss@iki.fi>
parents: 14677
diff changeset
1077 sizeof(diff32), NULL);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1078 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1079 return diff32;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1080 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1081
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1082 static bool
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1083 keyword_update_has_changes(struct mail_index_transaction *t, uint32_t seq,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1084 enum modify_type modify_type,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1085 struct mail_keywords *keywords)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1086 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1087 ARRAY_TYPE(keyword_indexes) existing;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1088 const unsigned int *existing_idx;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1089 unsigned int i, j, existing_count;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1090 bool found;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1091
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1092 t_array_init(&existing, 32);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1093 if (seq < t->first_new_seq)
14532
5d45870e2e4a lib-index: Fixed MAIL_INDEX_SYNC_FLAG_AVOID_FLAG_UPDATES with concurrent keyword changes.
Timo Sirainen <tss@iki.fi>
parents: 14133
diff changeset
1094 mail_index_transaction_lookup_latest_keywords(t, seq, &existing);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1095 existing_idx = array_get(&existing, &existing_count);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1096
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1097 if (modify_type == MODIFY_REPLACE && existing_count != keywords->count)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1098 return TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1099
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1100 for (i = 0; i < keywords->count; i++) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1101 found = FALSE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1102 for (j = 0; j < existing_count; j++) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1103 if (existing_idx[j] == keywords->idx[i]) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1104 found = TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1105 break;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1106 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1107 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1108 switch (modify_type) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1109 case MODIFY_ADD:
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1110 case MODIFY_REPLACE:
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1111 if (!found)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1112 return TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1113 break;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1114 case MODIFY_REMOVE:
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1115 if (found)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1116 return TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1117 break;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1118 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1119 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1120 return FALSE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1121 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1122
14580
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1123 static struct mail_keywords *
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1124 keyword_update_remove_existing(struct mail_index_transaction *t, uint32_t seq)
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1125 {
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1126 ARRAY_TYPE(keyword_indexes) keywords;
15262
b0a6fe3aa61f lib-index: Avoid assert-crashing when syncing an old "keyword reset" from transaction log.
Timo Sirainen <tss@iki.fi>
parents: 14685
diff changeset
1127 uint32_t i, keywords_count;
14580
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1128
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1129 t_array_init(&keywords, 32);
15262
b0a6fe3aa61f lib-index: Avoid assert-crashing when syncing an old "keyword reset" from transaction log.
Timo Sirainen <tss@iki.fi>
parents: 14685
diff changeset
1130 if (t->view->v.lookup_full == NULL) {
b0a6fe3aa61f lib-index: Avoid assert-crashing when syncing an old "keyword reset" from transaction log.
Timo Sirainen <tss@iki.fi>
parents: 14685
diff changeset
1131 /* syncing is saving a list of changes into this transaction.
b0a6fe3aa61f lib-index: Avoid assert-crashing when syncing an old "keyword reset" from transaction log.
Timo Sirainen <tss@iki.fi>
parents: 14685
diff changeset
1132 the seq is actual an uid, so we can't lookup the existing
b0a6fe3aa61f lib-index: Avoid assert-crashing when syncing an old "keyword reset" from transaction log.
Timo Sirainen <tss@iki.fi>
parents: 14685
diff changeset
1133 keywords. we shouldn't get here unless we're reading
b0a6fe3aa61f lib-index: Avoid assert-crashing when syncing an old "keyword reset" from transaction log.
Timo Sirainen <tss@iki.fi>
parents: 14685
diff changeset
1134 pre-v2.2 keyword-reset records from .log files. so we don't
b0a6fe3aa61f lib-index: Avoid assert-crashing when syncing an old "keyword reset" from transaction log.
Timo Sirainen <tss@iki.fi>
parents: 14685
diff changeset
1135 really care about performance that much here, */
b0a6fe3aa61f lib-index: Avoid assert-crashing when syncing an old "keyword reset" from transaction log.
Timo Sirainen <tss@iki.fi>
parents: 14685
diff changeset
1136 keywords_count = array_count(&t->view->index->keywords);
b0a6fe3aa61f lib-index: Avoid assert-crashing when syncing an old "keyword reset" from transaction log.
Timo Sirainen <tss@iki.fi>
parents: 14685
diff changeset
1137 for (i = 0; i < keywords_count; i++)
b0a6fe3aa61f lib-index: Avoid assert-crashing when syncing an old "keyword reset" from transaction log.
Timo Sirainen <tss@iki.fi>
parents: 14685
diff changeset
1138 array_append(&keywords, &i, 1);
b0a6fe3aa61f lib-index: Avoid assert-crashing when syncing an old "keyword reset" from transaction log.
Timo Sirainen <tss@iki.fi>
parents: 14685
diff changeset
1139 } else {
b0a6fe3aa61f lib-index: Avoid assert-crashing when syncing an old "keyword reset" from transaction log.
Timo Sirainen <tss@iki.fi>
parents: 14685
diff changeset
1140 mail_index_transaction_lookup_latest_keywords(t, seq, &keywords);
b0a6fe3aa61f lib-index: Avoid assert-crashing when syncing an old "keyword reset" from transaction log.
Timo Sirainen <tss@iki.fi>
parents: 14685
diff changeset
1141 }
14580
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1142 if (array_count(&keywords) == 0)
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1143 return NULL;
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1144 return mail_index_keywords_create_from_indexes(t->view->index,
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1145 &keywords);
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1146 }
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1147
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1148 void mail_index_update_keywords(struct mail_index_transaction *t, uint32_t seq,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1149 enum modify_type modify_type,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1150 struct mail_keywords *keywords)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1151 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1152 struct mail_index_transaction_keyword_update *u;
14580
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1153 struct mail_keywords *add_keywords = NULL, *remove_keywords = NULL;
15737
be320a216190 lib-index: Memory leak fix
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
1154 struct mail_keywords *unref_keywords = NULL;
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
1155 unsigned int i;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1156 bool changed;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1157
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1158 i_assert(seq > 0 &&
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1159 (seq <= mail_index_view_get_messages_count(t->view) ||
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1160 seq <= t->last_new_seq));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1161 i_assert(keywords->index == t->view->index);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1162
22004
db8e1a2f07be lib-index: mail_index_update_keywords() - don't assert if adding/removing 0 keywords
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21871
diff changeset
1163 if (keywords->count == 0 && modify_type != MODIFY_REPLACE)
db8e1a2f07be lib-index: mail_index_update_keywords() - don't assert if adding/removing 0 keywords
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21871
diff changeset
1164 return;
db8e1a2f07be lib-index: mail_index_update_keywords() - don't assert if adding/removing 0 keywords
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 21871
diff changeset
1165
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1166 update_minmax_flagupdate_seq(t, seq, seq);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1167
14580
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1168 if (!array_is_created(&t->keyword_updates)) {
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1169 uint32_t max_idx = keywords->count == 0 ? 3 :
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1170 keywords->idx[keywords->count-1];
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1171
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1172 i_array_init(&t->keyword_updates, max_idx + 1);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1173 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1174
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1175 if ((t->flags & MAIL_INDEX_TRANSACTION_FLAG_AVOID_FLAG_UPDATES) != 0) {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1176 T_BEGIN {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1177 changed = keyword_update_has_changes(t, seq,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1178 modify_type,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1179 keywords);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1180 } T_END;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1181 if (!changed)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1182 return;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1183 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1184
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1185 switch (modify_type) {
14580
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1186 case MODIFY_REPLACE:
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1187 /* split this into add+remove. remove all existing keywords not
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1188 included in the keywords list */
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1189 if (seq < t->first_new_seq) {
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1190 /* remove the ones currently in index */
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1191 remove_keywords = keyword_update_remove_existing(t, seq);
15737
be320a216190 lib-index: Memory leak fix
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
1192 unref_keywords = remove_keywords;
14580
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1193 }
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1194 /* remove from all changes we've done in this transaction */
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1195 array_foreach_modifiable(&t->keyword_updates, u)
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1196 seq_range_array_remove(&u->add_seq, seq);
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1197 add_keywords = keywords;
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1198 break;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1199 case MODIFY_ADD:
14580
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1200 add_keywords = keywords;
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1201 break;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1202 case MODIFY_REMOVE:
14580
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1203 remove_keywords = keywords;
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1204 break;
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1205 }
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1206
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1207 /* Update add_seq and remove_seq arrays which describe the keyword
14580
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1208 changes. First do the removes, since replace removes everything
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1209 first. */
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1210 if (remove_keywords != NULL) {
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1211 for (i = 0; i < remove_keywords->count; i++) {
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1212 u = array_idx_modifiable(&t->keyword_updates,
14580
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1213 remove_keywords->idx[i]);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1214 seq_range_array_remove(&u->add_seq, seq);
14580
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1215 /* Don't bother updating remove_seq for new messages,
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1216 since their initial state is "no keyword" anyway */
14676
69ba6977bed8 seq_range_array_add() API changed. Added other functions to provide the less common use cases.
Timo Sirainen <tss@iki.fi>
parents: 14599
diff changeset
1217 if (seq < t->first_new_seq) {
69ba6977bed8 seq_range_array_add() API changed. Added other functions to provide the less common use cases.
Timo Sirainen <tss@iki.fi>
parents: 14599
diff changeset
1218 seq_range_array_add_with_init(&u->remove_seq,
69ba6977bed8 seq_range_array_add() API changed. Added other functions to provide the less common use cases.
Timo Sirainen <tss@iki.fi>
parents: 14599
diff changeset
1219 16, seq);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1220 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1221 }
14580
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1222 }
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1223 if (add_keywords != NULL) {
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1224 for (i = 0; i < add_keywords->count; i++) {
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1225 u = array_idx_modifiable(&t->keyword_updates,
14580
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1226 add_keywords->idx[i]);
14676
69ba6977bed8 seq_range_array_add() API changed. Added other functions to provide the less common use cases.
Timo Sirainen <tss@iki.fi>
parents: 14599
diff changeset
1227 seq_range_array_add_with_init(&u->add_seq, 16, seq);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1228 seq_range_array_remove(&u->remove_seq, seq);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1229 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1230 }
15737
be320a216190 lib-index: Memory leak fix
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
1231 if (unref_keywords != NULL)
be320a216190 lib-index: Memory leak fix
Timo Sirainen <tss@iki.fi>
parents: 15715
diff changeset
1232 mail_index_keywords_unref(&unref_keywords);
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1233
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1234 t->log_updates = TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1235 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1236
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1237 bool mail_index_cancel_flag_updates(struct mail_index_transaction *t,
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1238 uint32_t seq)
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1239 {
14599
dbd42f7198eb shared mailboxes: Per-user flags can now be stored in private index files.
Timo Sirainen <tss@iki.fi>
parents: 14580
diff changeset
1240 struct mail_index_flag_update *updates, tmp_update;
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1241 unsigned int i, count;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1242
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1243 if (!array_is_created(&t->updates))
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1244 return FALSE;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1245
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1246 updates = array_get_modifiable(&t->updates, &count);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1247 i = mail_index_transaction_get_flag_update_pos(t, 0, count, seq);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1248 if (i == count)
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1249 return FALSE;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1250 else {
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1251 i_assert(seq <= updates[i].uid2);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1252 if (seq < updates[i].uid1)
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1253 return FALSE;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1254 }
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1255
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1256 /* exists */
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1257 if (updates[i].uid1 == seq) {
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1258 if (updates[i].uid2 != seq)
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1259 updates[i].uid1++;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1260 else if (count > 1)
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1261 array_delete(&t->updates, i, 1);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1262 else
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1263 array_free(&t->updates);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1264 } else if (updates[i].uid2 == seq) {
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1265 updates[i].uid2--;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1266 } else {
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1267 /* need to split it in two */
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1268 tmp_update = updates[i];
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1269 tmp_update.uid1 = seq+1;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1270 updates[i].uid2 = seq-1;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1271 array_insert(&t->updates, i + 1, &tmp_update, 1);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1272 }
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1273 return TRUE;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1274 }
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1275
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1276 static bool mail_index_cancel_array(ARRAY_TYPE(seq_range) *array, uint32_t seq)
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1277 {
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1278 if (array_is_created(array)) {
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1279 if (seq_range_array_remove(array, seq)) {
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1280 if (array_count(array) == 0)
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1281 array_free(array);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1282 return TRUE;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1283 }
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1284 }
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1285 return FALSE;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1286 }
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1287
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1288 bool mail_index_cancel_keyword_updates(struct mail_index_transaction *t,
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1289 uint32_t seq)
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1290 {
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1291 struct mail_index_transaction_keyword_update *kw;
14580
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1292 bool ret = FALSE, have_kw_changes = FALSE;
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1293
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1294 if (!array_is_created(&t->keyword_updates))
14580
2e7d718609fd Don't write "keyword reset" records to transaction log anymore.
Timo Sirainen <tss@iki.fi>
parents: 14532
diff changeset
1295 return FALSE;
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1296
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
1297 array_foreach_modifiable(&t->keyword_updates, kw) {
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
1298 if (mail_index_cancel_array(&kw->add_seq, seq))
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1299 ret = TRUE;
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
1300 if (mail_index_cancel_array(&kw->remove_seq, seq))
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1301 ret = TRUE;
10000
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
1302 if (array_is_created(&kw->add_seq) ||
c610321584ca Use array_foreach*() in some useful places.
Timo Sirainen <tss@iki.fi>
parents: 9725
diff changeset
1303 array_is_created(&kw->remove_seq))
9626
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1304 have_kw_changes = TRUE;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1305 }
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1306 if (!have_kw_changes)
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1307 array_free(&t->keyword_updates);
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1308 return ret;
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1309 }
b45be8d8b388 mail index transactions: More code cleanups and unit tests.
Timo Sirainen <tss@iki.fi>
parents: 9624
diff changeset
1310
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1311 void mail_index_transaction_reset(struct mail_index_transaction *t)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1312 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1313 t->v.reset(t);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1314 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1315
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1316 void mail_index_reset(struct mail_index_transaction *t)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1317 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1318 mail_index_transaction_reset(t);
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1319
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1320 t->reset = TRUE;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1321 }
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1322
21224
1455417c56a5 lib-index: Add mail_index_unset_fscked()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20654
diff changeset
1323 void mail_index_unset_fscked(struct mail_index_transaction *t)
1455417c56a5 lib-index: Add mail_index_unset_fscked()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20654
diff changeset
1324 {
1455417c56a5 lib-index: Add mail_index_unset_fscked()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20654
diff changeset
1325 struct mail_index_header new_hdr =
1455417c56a5 lib-index: Add mail_index_unset_fscked()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20654
diff changeset
1326 *mail_index_get_header(t->view);
1455417c56a5 lib-index: Add mail_index_unset_fscked()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20654
diff changeset
1327
1455417c56a5 lib-index: Add mail_index_unset_fscked()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20654
diff changeset
1328 i_assert(t->view->index->log_sync_locked);
1455417c56a5 lib-index: Add mail_index_unset_fscked()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20654
diff changeset
1329
1455417c56a5 lib-index: Add mail_index_unset_fscked()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20654
diff changeset
1330 /* remove fsck'd-flag if it exists. */
1455417c56a5 lib-index: Add mail_index_unset_fscked()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20654
diff changeset
1331 if ((new_hdr.flags & MAIL_INDEX_HDR_FLAG_FSCKD) != 0) {
1455417c56a5 lib-index: Add mail_index_unset_fscked()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20654
diff changeset
1332 new_hdr.flags &= ~MAIL_INDEX_HDR_FLAG_FSCKD;
1455417c56a5 lib-index: Add mail_index_unset_fscked()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20654
diff changeset
1333 mail_index_update_header(t,
1455417c56a5 lib-index: Add mail_index_unset_fscked()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20654
diff changeset
1334 offsetof(struct mail_index_header, flags),
1455417c56a5 lib-index: Add mail_index_unset_fscked()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20654
diff changeset
1335 &new_hdr.flags, sizeof(new_hdr.flags), FALSE);
1455417c56a5 lib-index: Add mail_index_unset_fscked()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20654
diff changeset
1336 }
1455417c56a5 lib-index: Add mail_index_unset_fscked()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20654
diff changeset
1337 }
1455417c56a5 lib-index: Add mail_index_unset_fscked()
Timo Sirainen <timo.sirainen@dovecot.fi>
parents: 20654
diff changeset
1338
10655
fc0ac73f0b36 Added support for marking mailbox index deleted. Don't allow any changes after that.
Timo Sirainen <tss@iki.fi>
parents: 10618
diff changeset
1339 void mail_index_set_deleted(struct mail_index_transaction *t)
fc0ac73f0b36 Added support for marking mailbox index deleted. Don't allow any changes after that.
Timo Sirainen <tss@iki.fi>
parents: 10618
diff changeset
1340 {
10674
22354f505277 lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents: 10673
diff changeset
1341 i_assert(!t->index_undeleted);
22354f505277 lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents: 10673
diff changeset
1342
10655
fc0ac73f0b36 Added support for marking mailbox index deleted. Don't allow any changes after that.
Timo Sirainen <tss@iki.fi>
parents: 10618
diff changeset
1343 t->index_deleted = TRUE;
fc0ac73f0b36 Added support for marking mailbox index deleted. Don't allow any changes after that.
Timo Sirainen <tss@iki.fi>
parents: 10618
diff changeset
1344 }
fc0ac73f0b36 Added support for marking mailbox index deleted. Don't allow any changes after that.
Timo Sirainen <tss@iki.fi>
parents: 10618
diff changeset
1345
10674
22354f505277 lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents: 10673
diff changeset
1346 void mail_index_set_undeleted(struct mail_index_transaction *t)
22354f505277 lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents: 10673
diff changeset
1347 {
22354f505277 lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents: 10673
diff changeset
1348 i_assert(!t->index_deleted);
22354f505277 lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents: 10673
diff changeset
1349
22354f505277 lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents: 10673
diff changeset
1350 t->index_undeleted = TRUE;
22354f505277 lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents: 10673
diff changeset
1351 }
22354f505277 lib-index: Added support for undeleting a deleted index.
Timo Sirainen <tss@iki.fi>
parents: 10673
diff changeset
1352
9622
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1353 void mail_index_transaction_set_max_modseq(struct mail_index_transaction *t,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1354 uint64_t max_modseq,
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1355 ARRAY_TYPE(seq_range) *seqs)
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1356 {
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1357 i_assert(array_is_created(seqs));
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1358
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1359 t->max_modseq = max_modseq;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1360 t->conflict_seqs = seqs;
cae78e734cdb Moved around mail-index-transaction code and added initial unit tests.
Timo Sirainen <tss@iki.fi>
parents:
diff changeset
1361 }