mail-index-transaction.c revision b492193936f0e63dd0a24137e600d495351bfca4
c25356d5978632df6203437e1953bcb29e0c736fTimo Sirainen/* Copyright (C) 2003-2004 Timo Sirainen */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen/* Inside transaction we keep messages stored in sequences in uid fields.
49e358eebea107aad9919dcc4bd88cee8519ba2eTimo Sirainen Before they're written to transaction log the sequences are changed to
49e358eebea107aad9919dcc4bd88cee8519ba2eTimo Sirainen UIDs. This is because we're able to compress sequence ranges better. */
411d6baa37f31d90730e90c4a28c43e1974bbe58Timo Sirainenstatic void mail_index_transaction_add_last(struct mail_index_transaction *t);
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainenmail_index_transaction_begin(struct mail_index_view *view, int hide)
5ac0b0bf32898c63da086ae169674ecac151a31eTimo Sirainen /* don't allow syncing view while there's ongoing transactions */
fe363b433b8038a69b55169da9dca27892ad7d18Timo Sirainen t->first_new_seq = mail_index_view_get_message_count(t->view)+1;
10c96a244935de4add8213ba0b894178dfb889a5Timo Sirainenstatic void mail_index_transaction_free(struct mail_index_transaction *t)
bdcb00145ad87765e3fd22d4ebc4d2c029a326b9Timo Sirainen unsigned int i;
8cb72c59d5ea4e9e5f638d7ec840bb853f5a188eTimo Sirainen for (i = 0; i < t->view->index->extra_records_count; i++) {
a10ed8c47534b4c6b6bf2711ccfe577e720a47b4Timo Sirainenvoid mail_index_transaction_ref(struct mail_index_transaction *t)
27a44fcfd8d19bffe0f267f20a2b5d3fe7600fddTimo Sirainenvoid mail_index_transaction_unref(struct mail_index_transaction *t)
c28f6aa0b70af4811c9ace9114fe827c2f503455Timo Sirainen if (--t->refcount == 0)
e2ce8d4a6ac5d82a906178148453e7613fab9ba0Timo Sirainenmail_index_buffer_convert_to_uids(struct mail_index_view *view,
07e4875d250e7a7157cd99132aafc773cf3cdf83Timo Sirainen unsigned char *data;
7662010b03ffe5f2a6ecf4b4eb220d1c65efea76Timo Sirainen /* @UNSAFE */
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen data = buffer_get_modifyable_data(buf, &size);
51e1a1c280ccb461a15827f7987d09cb9708b6e3Timo Sirainen seq[0] = MAIL_INDEX_MAP_IDX(view->map, seq[0]-1)->uid;
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen seq[1] = MAIL_INDEX_MAP_IDX(view->map, seq[1]-1)->uid;
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainenmail_index_transaction_convert_to_uids(struct mail_index_transaction *t)
c0435c854a0e7246373b9752d163095cc4fbe985Timo Sirainen unsigned int i;
602a0434db30d8e3292d1c161a803d96a879a74fTimo Sirainen for (i = 0; i < index->extra_records_count; i++) {
4b9f99761df5014c659cd87fddaf6854af428cfcTimo Sirainen mail_index_buffer_convert_to_uids(t->view, t->expunges,
7e1f68ad71d3485f1882142837b01f7a98ca8467Timo Sirainen sizeof(struct mail_transaction_expunge), TRUE);
68a4946b12583b88fa802e52ebee45cd96056772Timo Sirainen mail_index_buffer_convert_to_uids(t->view, t->updates,
a3c197999dfe2b0c8ea38cb77cfa5e95026005c0Timo Sirainen sizeof(struct mail_transaction_flag_update), TRUE);
a3c197999dfe2b0c8ea38cb77cfa5e95026005c0Timo Sirainen mail_index_buffer_convert_to_uids(t->view, t->cache_updates,
923115fd382904fa13bb09bf307bf2835b52df60Timo Sirainen sizeof(struct mail_transaction_cache_update), FALSE);
89e195dfb5c4b0efd9b9f459771a4467674e5b1fTimo Sirainenint mail_index_transaction_commit(struct mail_index_transaction *t,
a0b6b441fc679e562e79be0fb2819ffc24ab5b74Timo Sirainen if (mail_index_view_is_inconsistent(t->view)) {
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen mail_cache_transaction_commit(t->cache_trans_ctx);
68a4946b12583b88fa802e52ebee45cd96056772Timo Sirainen if (mail_index_transaction_convert_to_uids(t) < 0)
699fdc186f982f70d990820796eaa0f12133e27cTimo Sirainen ret = mail_transaction_log_append(t, log_file_seq_r,
282a436a74d8835edb45cc019b1c916013013fd3Timo Sirainenvoid mail_index_transaction_rollback(struct mail_index_transaction *t)
ecc81625167ed96c04c02aa190a1ea5baa65b474Timo Sirainen mail_cache_transaction_rollback(t->cache_trans_ctx);
unsigned int new_record_size;
const void *src;
void *dest;
if (t->append_record_size != 0) {
for (i = 0; i < size; i++) {
struct mail_index_record *
if (t->last_new_seq != 0)
idx++;
sizeof(*data));
sizeof(*data));
switch (modify_type) {
case MODIFY_REPLACE:
case MODIFY_ADD:
for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++)
case MODIFY_REMOVE:
for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++)
INDEX_KEYWORDS_BYTE_COUNT) == 0)
switch (t->last_update_modify_type) {
case MODIFY_REPLACE:
for (i = 0; i < INDEX_KEYWORDS_BYTE_COUNT; i++)
case MODIFY_ADD:
case MODIFY_REMOVE:
idx++;
size++;
void *data;
if (size == 0)
idx = 0;
return TRUE;
return FALSE;
void *old_record)
return FALSE;
return TRUE;
return FALSE;
if (t->last_cache_file_seq == 0)
if (t->first_new_seq != 0) {
*old_offset_r = 0;
return FALSE;
return FALSE;
sizeof(*offset_r));
return TRUE;
const void *data)