mail-cache-compress.c revision a817fdcc43aedf423e2134091d5f83f91d64bcc9
06509499ae5b6676db799057108433170a23ed28fuankg/* Copyright (C) 2003-2004 Timo Sirainen */
06509499ae5b6676db799057108433170a23ed28fuankgstatic void mail_cache_merge_bitmask(struct mail_cache *cache, buffer_t *buffer,
06509499ae5b6676db799057108433170a23ed28fuankg unsigned int i, buf_data_size;
06509499ae5b6676db799057108433170a23ed28fuankg buf_data = buffer_get_modifyable_data(buffer, &buf_size);
06509499ae5b6676db799057108433170a23ed28fuankg for (pos = sizeof(struct mail_cache_record); pos < buf_size; ) {
06509499ae5b6676db799057108433170a23ed28fuankg buf_field = *((uint32_t *)PTR_OFFSET(buf_data, pos));
06509499ae5b6676db799057108433170a23ed28fuankg buf_data_size = cache->fields[buf_field].field.field_size;
06509499ae5b6676db799057108433170a23ed28fuankg /* @UNSAFE: found it, do the merging */
06509499ae5b6676db799057108433170a23ed28fuankg for (i = 0; i < buf_data_size; i++)
06509499ae5b6676db799057108433170a23ed28fuankgmail_cache_compress_callback(struct mail_cache_view *view, uint32_t field,
06509499ae5b6676db799057108433170a23ed28fuankg field_seen = buffer_get_space_unsafe(ctx->field_seen, field, 1);
06509499ae5b6676db799057108433170a23ed28fuankg /* duplicate */
06509499ae5b6676db799057108433170a23ed28fuankg dec = cache_field->decision & ~MAIL_CACHE_DECISION_FORCED;
06509499ae5b6676db799057108433170a23ed28fuankg buffer_append_zero(ctx->buffer, 4 - (data_size & 3));
06509499ae5b6676db799057108433170a23ed28fuankgget_next_file_seq(struct mail_cache *cache, struct mail_index_view *view)
06509499ae5b6676db799057108433170a23ed28fuankg file_seq = ext != NULL ? ext->reset_id + 1 : (uint32_t)ioloop_time;
06509499ae5b6676db799057108433170a23ed28fuankgmail_cache_copy(struct mail_cache *cache, struct mail_index_view *view, int fd)
06509499ae5b6676db799057108433170a23ed28fuankg uint32_t i, message_count, seq, first_new_seq, old_offset;
06509499ae5b6676db799057108433170a23ed28fuankg /* get sequence of first message which doesn't need its temp fields
06509499ae5b6676db799057108433170a23ed28fuankg removed. */
06509499ae5b6676db799057108433170a23ed28fuankg message_count = mail_index_view_get_messages_count(view);
06509499ae5b6676db799057108433170a23ed28fuankg if (mail_index_lookup_uid_range(view, idx_hdr->day_first_uid[7],
06509499ae5b6676db799057108433170a23ed28fuankg output = o_stream_create_file(fd, default_pool, 0, FALSE);
06509499ae5b6676db799057108433170a23ed28fuankg ctx.buffer = buffer_create_dynamic(default_pool, 4096);
06509499ae5b6676db799057108433170a23ed28fuankg ctx.field_seen = buffer_create_dynamic(default_pool, 64);
06509499ae5b6676db799057108433170a23ed28fuankg mail_index_ext_reset(t, cache->ext_id, hdr.file_seq);
06509499ae5b6676db799057108433170a23ed28fuankg memset(buffer_get_modifyable_data(ctx.field_seen, NULL),
06509499ae5b6676db799057108433170a23ed28fuankg buffer_append(ctx.buffer, &cache_rec, sizeof(cache_rec));
06509499ae5b6676db799057108433170a23ed28fuankg mail_index_update_ext(t, seq, cache->ext_id, &output->offset,
06509499ae5b6676db799057108433170a23ed28fuankg buffer_write(ctx.buffer, 0, &cache_rec, sizeof(cache_rec));
06509499ae5b6676db799057108433170a23ed28fuankg o_stream_send(output, ctx.buffer->data, cache_rec.size);
06509499ae5b6676db799057108433170a23ed28fuankg /* we wrote everything using our internal field ids. so we want
06509499ae5b6676db799057108433170a23ed28fuankg mail_cache_header_fields_get() to use them and ignore any
06509499ae5b6676db799057108433170a23ed28fuankg existing id mappings in the old cache file. */
06509499ae5b6676db799057108433170a23ed28fuankg buffer = buffer_create_dynamic(pool_datastack_create(), 256);
06509499ae5b6676db799057108433170a23ed28fuankg mail_cache_set_syscall_error(cache, "o_stream_flush()");
06509499ae5b6676db799057108433170a23ed28fuankg /* grow the file some more. doesn't matter if it fails */
06509499ae5b6676db799057108433170a23ed28fuankg return mail_index_transaction_commit(t, &seq, &offset);
06509499ae5b6676db799057108433170a23ed28fuankgstatic int mail_cache_compress_locked(struct mail_cache *cache,
06509499ae5b6676db799057108433170a23ed28fuankg /* get the latest info on fields */
06509499ae5b6676db799057108433170a23ed28fuankg i_warning("Compressing cache file %s", cache->filepath);
06509499ae5b6676db799057108433170a23ed28fuankg fd = file_dotlock_open(&cache->dotlock_settings, cache->filepath,
0, &dotlock);
int ret;
return ret;