From: Stephan Bosch Date: Fri, 16 Nov 2018 14:27:22 +0000 (+0100) Subject: trash: Perform expunge in a separate function X-Git-Tag: 2.4.1~140 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=15dff4b97e504eb1421f25f5d1e4bb546cd33858;p=thirdparty%2Fdovecot%2Fcore.git trash: Perform expunge in a separate function Also, improve the integer calculations for updating the total amount of expunged resource usage. --- diff --git a/src/plugins/trash/trash-plugin.c b/src/plugins/trash/trash-plugin.c index fe05be564e..1c4564d249 100644 --- a/src/plugins/trash/trash-plugin.c +++ b/src/plugins/trash/trash-plugin.c @@ -171,6 +171,30 @@ static inline bool trash_clean_achieved(struct trash_clean *tclean) return TRUE; } +static int +trash_clean_mailbox_expunge(struct trash_clean *tclean, + struct trash_clean_mailbox *tcbox) +{ + uoff_t size; + + if (mail_get_physical_size(tcbox->mail, &size) < 0) { + /* maybe expunged already? */ + tcbox->mail = NULL; + return -1; + } + + mail_expunge(tcbox->mail); + if (tclean->count_expunged < UINT64_MAX) + tclean->count_expunged++; + if (tclean->bytes_expunged < (UINT64_MAX - size)) + tclean->bytes_expunged += size; + else + tclean->bytes_expunged = UINT64_MAX; + + tcbox->mail = NULL; + return 0; +} + static int trash_clean_do_execute(struct trash_clean *tclean) { struct quota_transaction_context *ctx = tclean->ctx; @@ -178,7 +202,6 @@ static int trash_clean_do_execute(struct trash_clean *tclean) const struct trash_mailbox *trashes; unsigned int i, j, trash_count, tcbox_count; struct trash_clean_mailbox *tcbox, *tcboxes; - uint64_t size; int ret = 0; trashes = array_get(&tuser->trash_boxes, &trash_count); @@ -221,19 +244,12 @@ static int trash_clean_do_execute(struct trash_clean *tclean) } if (oldest_idx < tcbox_count) { - if (mail_get_physical_size(tcboxes[oldest_idx].mail, - &size) < 0) { - /* maybe expunged already? */ - tcboxes[oldest_idx].mail = NULL; + ret = trash_clean_mailbox_expunge(tclean, + &tcboxes[oldest_idx]); + if (ret < 0) continue; - } - - mail_expunge(tcboxes[oldest_idx].mail); - tclean->count_expunged++; - tclean->bytes_expunged += size; if (trash_clean_achieved(tclean)) break; - tcboxes[oldest_idx].mail = NULL; } else { /* find more mails from next priority's mailbox */ i = j;