Mercurial > dovecot > original-hg > dovecot-1.2
changeset 6995:2e9fcf711fc4 HEAD
Expunging messages didn't update maildirsize file if it wasn't already
opened or if the file had since been replaced by another process.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Mon, 17 Dec 2007 17:25:40 +0200 |
parents | 79ba0e9a8725 |
children | 021b6900a900 |
files | src/plugins/quota/quota-maildir.c |
diffstat | 1 files changed, 28 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/quota/quota-maildir.c Mon Dec 17 17:17:22 2007 +0200 +++ b/src/plugins/quota/quota-maildir.c Mon Dec 17 17:25:40 2007 +0200 @@ -443,33 +443,36 @@ return 1; } +static int maildirsize_open(struct maildir_quota_root *root) +{ + if (root->fd != -1) { + if (close(root->fd) < 0) + i_error("close(%s) failed: %m", root->maildirsize_path); + } + + root->fd = nfs_safe_open(root->maildirsize_path, O_RDWR | O_APPEND); + if (root->fd == -1) { + if (errno == ENOENT) + return 0; + i_error("open(%s) failed: %m", root->maildirsize_path); + return -1; + } + return 1; +} + static int maildirsize_read(struct maildir_quota_root *root) { char buf[5120+1]; unsigned int i, size; - int fd, ret = 0; - - if (root->fd != -1) { - if (close(root->fd) < 0) - i_error("close(%s) failed: %m", root->maildirsize_path); - root->fd = -1; - } + int ret; - fd = nfs_safe_open(root->maildirsize_path, O_RDWR | O_APPEND); - if (fd == -1) { - if (errno == ENOENT) - ret = 0; - else { - ret = -1; - i_error("open(%s) failed: %m", root->maildirsize_path); - } + if ((ret = maildirsize_open(root)) <= 0) return ret; - } /* @UNSAFE */ size = 0; while (size < sizeof(buf)-1 && - (ret = read(fd, buf + size, sizeof(buf)-1 - size)) != 0) { + (ret = read(root->fd, buf + size, sizeof(buf)-1 - size)) != 0) { if (ret < 0) { if (errno == ESTALE) break; @@ -479,7 +482,8 @@ } if (ret < 0 || size >= sizeof(buf)-1) { /* error / recalculation needed. */ - (void)close(fd); + (void)close(root->fd); + root->fd = -1; return ret < 0 ? -1 : 0; } @@ -499,12 +503,11 @@ } if (i == size && - maildirsize_parse(root, fd, t_strsplit(buf, "\n")) > 0) { - root->fd = fd; + maildirsize_parse(root, root->fd, t_strsplit(buf, "\n")) > 0) ret = 1; - } else { + else { /* broken file / need recalculation */ - (void)close(fd); + (void)close(root->fd); root->fd = -1; ret = 0; } @@ -694,6 +697,9 @@ struct maildir_quota_root *root = (struct maildir_quota_root *) _root; + /* make sure the latest file is opened. */ + (void)maildirsize_open(root); + if (root->fd == -1 || ctx->recalculate || maildirsize_update(root, ctx->count_used, ctx->bytes_used) < 0) maildirsize_rebuild_later(root);