Skip to content

Commit

Permalink
lib-storage: Added mail_set_cache_corrupted_reason()
Browse files Browse the repository at this point in the history
  • Loading branch information
sirainen committed Feb 28, 2016
1 parent 85058e4 commit 6de6ec2
Show file tree
Hide file tree
Showing 15 changed files with 86 additions and 19 deletions.
10 changes: 9 additions & 1 deletion src/lib-storage/fail-mail.c
Expand Up @@ -228,6 +228,13 @@ fail_mail_set_cache_corrupted(struct mail *mail ATTR_UNUSED,
{
}

static void
fail_mail_set_cache_corrupted_reason(struct mail *mail ATTR_UNUSED,
enum mail_fetch_field field ATTR_UNUSED,
const char *reason ATTR_UNUSED)
{
}

struct mail_vfuncs fail_mail_vfuncs = {
NULL,
fail_mail_free,
Expand Down Expand Up @@ -263,5 +270,6 @@ struct mail_vfuncs fail_mail_vfuncs = {
NULL,
fail_mail_expunge,
fail_mail_set_cache_corrupted,
NULL
NULL,
fail_mail_set_cache_corrupted_reason
};
3 changes: 2 additions & 1 deletion src/lib-storage/index/cydir/cydir-mail.c
Expand Up @@ -165,5 +165,6 @@ struct mail_vfuncs cydir_mail_vfuncs = {
NULL,
index_mail_expunge,
index_mail_set_cache_corrupted,
index_mail_opened
index_mail_opened,
index_mail_set_cache_corrupted_reason
};
3 changes: 2 additions & 1 deletion src/lib-storage/index/dbox-multi/mdbox-mail.c
Expand Up @@ -261,5 +261,6 @@ struct mail_vfuncs mdbox_mail_vfuncs = {
NULL,
index_mail_expunge,
index_mail_set_cache_corrupted,
index_mail_opened
index_mail_opened,
index_mail_set_cache_corrupted_reason
};
3 changes: 2 additions & 1 deletion src/lib-storage/index/dbox-single/sdbox-mail.c
Expand Up @@ -170,5 +170,6 @@ struct mail_vfuncs sdbox_mail_vfuncs = {
NULL,
index_mail_expunge,
index_mail_set_cache_corrupted,
index_mail_opened
index_mail_opened,
index_mail_set_cache_corrupted_reason
};
3 changes: 2 additions & 1 deletion src/lib-storage/index/imapc/imapc-mail.c
Expand Up @@ -583,5 +583,6 @@ struct mail_vfuncs imapc_mail_vfuncs = {
NULL,
index_mail_expunge,
index_mail_set_cache_corrupted,
index_mail_opened
index_mail_opened,
index_mail_set_cache_corrupted_reason
};
19 changes: 16 additions & 3 deletions src/lib-storage/index/index-mail.c
Expand Up @@ -2115,6 +2115,13 @@ void index_mail_precache(struct mail *mail)

void index_mail_set_cache_corrupted(struct mail *mail,
enum mail_fetch_field field)
{
index_mail_set_cache_corrupted_reason(mail, field, "");
}

void index_mail_set_cache_corrupted_reason(struct mail *mail,
enum mail_fetch_field field,
const char *reason)
{
struct index_mail *imail = (struct index_mail *)mail;
const char *field_name;
Expand Down Expand Up @@ -2157,9 +2164,15 @@ void index_mail_set_cache_corrupted(struct mail *mail,
mail_cache_transaction_reset(mail->transaction->cache_trans);
imail->data.no_caching = TRUE;
imail->data.forced_no_caching = TRUE;
mail_cache_set_corrupted(mail->box->cache,
"Broken %s for mail UID %u",
field_name, mail->uid);
if (reason[0] == '\0') {
mail_cache_set_corrupted(mail->box->cache,
"Broken %s for mail UID %u",
field_name, mail->uid);
} else {
mail_cache_set_corrupted(mail->box->cache,
"Broken %s for mail UID %u: %s",
field_name, mail->uid, reason);
}
}

int index_mail_opened(struct mail *mail ATTR_UNUSED,
Expand Down
3 changes: 3 additions & 0 deletions src/lib-storage/index/index-mail.h
Expand Up @@ -235,6 +235,9 @@ void index_mail_expunge(struct mail *mail);
void index_mail_precache(struct mail *mail);
void index_mail_set_cache_corrupted(struct mail *mail,
enum mail_fetch_field field);
void index_mail_set_cache_corrupted_reason(struct mail *mail,
enum mail_fetch_field field,
const char *reason);
int index_mail_opened(struct mail *mail, struct istream **stream);
int index_mail_stream_check_failure(struct index_mail *mail);
void index_mail_stream_log_failure_for(struct index_mail *mail,
Expand Down
16 changes: 12 additions & 4 deletions src/lib-storage/index/maildir/maildir-mail.c
Expand Up @@ -753,15 +753,22 @@ maildir_mail_remove_sizes_from_filename(struct mail *mail,
(void)maildir_file_do(mbox, mail->uid, do_fix_size, &ctx);
}

static void maildir_mail_set_cache_corrupted(struct mail *_mail,
enum mail_fetch_field field)
static void maildir_mail_set_cache_corrupted_reason(struct mail *_mail,
enum mail_fetch_field field,
const char *reason)
{
if (field == MAIL_FETCH_PHYSICAL_SIZE ||
field == MAIL_FETCH_VIRTUAL_SIZE) {
maildir_mail_remove_sizes_from_uidlist(_mail);
maildir_mail_remove_sizes_from_filename(_mail, field);
}
index_mail_set_cache_corrupted(_mail, field);
index_mail_set_cache_corrupted_reason(_mail, field, reason);
}

static void maildir_mail_set_cache_corrupted(struct mail *_mail,
enum mail_fetch_field field)
{
maildir_mail_set_cache_corrupted_reason(_mail, field, "");
}

struct mail_vfuncs maildir_mail_vfuncs = {
Expand Down Expand Up @@ -799,5 +806,6 @@ struct mail_vfuncs maildir_mail_vfuncs = {
maildir_update_pop3_uidl,
index_mail_expunge,
maildir_mail_set_cache_corrupted,
index_mail_opened
index_mail_opened,
maildir_mail_set_cache_corrupted_reason
};
3 changes: 2 additions & 1 deletion src/lib-storage/index/mbox/mbox-mail.c
Expand Up @@ -446,5 +446,6 @@ struct mail_vfuncs mbox_mail_vfuncs = {
NULL,
index_mail_expunge,
index_mail_set_cache_corrupted,
index_mail_opened
index_mail_opened,
index_mail_set_cache_corrupted_reason
};
3 changes: 2 additions & 1 deletion src/lib-storage/index/pop3c/pop3c-mail.c
Expand Up @@ -302,5 +302,6 @@ struct mail_vfuncs pop3c_mail_vfuncs = {
NULL,
index_mail_expunge,
index_mail_set_cache_corrupted,
index_mail_opened
index_mail_opened,
index_mail_set_cache_corrupted_reason
};
3 changes: 2 additions & 1 deletion src/lib-storage/index/raw/raw-mail.c
Expand Up @@ -149,5 +149,6 @@ struct mail_vfuncs raw_mail_vfuncs = {
NULL,
index_mail_expunge,
index_mail_set_cache_corrupted,
index_mail_opened
index_mail_opened,
index_mail_set_cache_corrupted_reason
};
3 changes: 3 additions & 0 deletions src/lib-storage/mail-storage-private.h
Expand Up @@ -446,6 +446,9 @@ struct mail_vfuncs {
void (*set_cache_corrupted)(struct mail *mail,
enum mail_fetch_field field);
int (*istream_opened)(struct mail *mail, struct istream **input);
void (*set_cache_corrupted_reason)(struct mail *mail,
enum mail_fetch_field field,
const char *reason);
};

union mail_module_context {
Expand Down
3 changes: 3 additions & 0 deletions src/lib-storage/mail-storage.h
Expand Up @@ -897,6 +897,9 @@ void mail_expunge(struct mail *mail);
void mail_precache(struct mail *mail);
/* Mark a cached field corrupted and have it recalculated. */
void mail_set_cache_corrupted(struct mail *mail, enum mail_fetch_field field);
void mail_set_cache_corrupted_reason(struct mail *mail,
enum mail_fetch_field field,
const char *reason);

/* Return 128 bit GUID using input string. If guid is already 128 bit hex
encoded, it's returned as-is. Otherwise SHA1 sum is taken and its last
Expand Down
15 changes: 14 additions & 1 deletion src/lib-storage/mail.c
Expand Up @@ -403,10 +403,23 @@ void mail_precache(struct mail *mail)
}

void mail_set_cache_corrupted(struct mail *mail, enum mail_fetch_field field)
{
mail_set_cache_corrupted_reason(mail, field, "");
}

void mail_set_cache_corrupted_reason(struct mail *mail,
enum mail_fetch_field field,
const char *reason)
{
struct mail_private *p = (struct mail_private *)mail;

p->v.set_cache_corrupted(mail, field);
/* FIXME: v2.3: rename set_cache_corrupted_reason() to just
set_cache_corrupted(). we have two here for backwards API
compatibility. */
if (p->v.set_cache_corrupted_reason != NULL)
p->v.set_cache_corrupted_reason(mail, field, reason);
else
p->v.set_cache_corrupted(mail, field);
}

void mail_generate_guid_128_hash(const char *guid, guid_128_t guid_128_r)
Expand Down
15 changes: 12 additions & 3 deletions src/plugins/virtual/virtual-mail.c
Expand Up @@ -468,14 +468,22 @@ static void virtual_mail_expunge(struct mail *mail)
}

static void
virtual_mail_set_cache_corrupted(struct mail *mail, enum mail_fetch_field field)
virtual_mail_set_cache_corrupted_reason(struct mail *mail,
enum mail_fetch_field field,
const char *reason)
{
struct virtual_mail *vmail = (struct virtual_mail *)mail;
struct mail *backend_mail;

if (backend_mail_get(vmail, &backend_mail) < 0)
return;
mail_set_cache_corrupted(backend_mail, field);
mail_set_cache_corrupted_reason(backend_mail, field, reason);
}

static void
virtual_mail_set_cache_corrupted(struct mail *mail, enum mail_fetch_field field)
{
virtual_mail_set_cache_corrupted_reason(mail, field, "");
}

struct mail_vfuncs virtual_mail_vfuncs = {
Expand Down Expand Up @@ -513,5 +521,6 @@ struct mail_vfuncs virtual_mail_vfuncs = {
virtual_mail_update_pop3_uidl,
virtual_mail_expunge,
virtual_mail_set_cache_corrupted,
NULL
NULL,
virtual_mail_set_cache_corrupted_reason
};

0 comments on commit 6de6ec2

Please sign in to comment.