Coverage Report

Created: 2026-10-17 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/dovecot/src/lib-index/mail-cache-sync-update.c
Line
Count
Source
1
/* Copyright (c) Dovecot authors, see top-level COPYING file */
2
3
#include "lib.h"
4
#include "mail-cache-private.h"
5
#include "mail-index-sync-private.h"
6
7
struct mail_cache_sync_context {
8
  unsigned int expunge_count;
9
};
10
11
void mail_cache_expunge_count(struct mail_cache *cache, unsigned int count)
12
0
{
13
0
  if (mail_cache_lock(cache) > 0) {
14
0
    cache->hdr_copy.deleted_record_count += count;
15
0
    if (cache->hdr_copy.record_count >= count)
16
0
      cache->hdr_copy.record_count -= count;
17
0
    else
18
0
       cache->hdr_copy.record_count = 0;
19
0
    cache->hdr_modified = TRUE;
20
0
    (void)mail_cache_flush_and_unlock(cache);
21
0
  }
22
0
}
23
24
static struct mail_cache_sync_context *mail_cache_handler_init(void **context)
25
0
{
26
0
  struct mail_cache_sync_context *ctx;
27
28
0
  if (*context != NULL)
29
0
    ctx = *context;
30
0
  else {
31
0
    *context = i_new(struct mail_cache_sync_context, 1);
32
0
    ctx = *context;
33
0
  }
34
0
  return ctx;
35
0
}
36
37
static void mail_cache_handler_deinit(struct mail_index_sync_map_ctx *sync_ctx,
38
              struct mail_cache_sync_context *ctx)
39
0
{
40
0
  struct mail_cache *cache = sync_ctx->view->index->cache;
41
42
0
  if (ctx == NULL)
43
0
    return;
44
45
0
  mail_cache_expunge_count(cache, ctx->expunge_count);
46
47
0
  i_free(ctx);
48
0
}
49
50
int mail_cache_expunge_handler(struct mail_index_sync_map_ctx *sync_ctx,
51
             const void *data, void **sync_context)
52
0
{
53
0
  struct mail_cache_sync_context *ctx = *sync_context;
54
0
  const uint32_t *cache_offset = data;
55
56
0
  if (data == NULL) {
57
0
    mail_cache_handler_deinit(sync_ctx, ctx);
58
0
    *sync_context = NULL;
59
0
    return 0;
60
0
  }
61
62
0
  if (*cache_offset == 0)
63
0
    return 0;
64
65
0
  ctx = mail_cache_handler_init(sync_context);
66
0
  ctx->expunge_count++;
67
0
  return 0;
68
0
}