dovecot: Expunging messages didn't update maildirsize file if it...
dovecot at dovecot.org
dovecot at dovecot.org
Mon Dec 17 17:25:44 EET 2007
details: http://hg.dovecot.org/dovecot/rev/2e9fcf711fc4
changeset: 6995:2e9fcf711fc4
user: Timo Sirainen <tss at iki.fi>
date: Mon Dec 17 17:25:40 2007 +0200
description:
Expunging messages didn't update maildirsize file if it wasn't already
opened or if the file had since been replaced by another process.
diffstat:
1 file changed, 29 insertions(+), 23 deletions(-)
src/plugins/quota/quota-maildir.c | 52 ++++++++++++++++++++-----------------
diffs (94 lines):
diff -r 79ba0e9a8725 -r 2e9fcf711fc4 src/plugins/quota/quota-maildir.c
--- 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 @@ static int maildirsize_parse(struct mail
return 1;
}
-static int maildirsize_read(struct maildir_quota_root *root)
-{
- char buf[5120+1];
- unsigned int i, size;
- int fd, ret = 0;
-
+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 = -1;
- }
-
- fd = nfs_safe_open(root->maildirsize_path, O_RDWR | O_APPEND);
- if (fd == -1) {
+ }
+
+ root->fd = nfs_safe_open(root->maildirsize_path, O_RDWR | O_APPEND);
+ if (root->fd == -1) {
if (errno == ENOENT)
- ret = 0;
- else {
- ret = -1;
- i_error("open(%s) failed: %m", root->maildirsize_path);
- }
+ 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 ret;
+
+ 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 @@ static int maildirsize_read(struct maild
}
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 @@ static int maildirsize_read(struct maild
}
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 @@ maildir_quota_update(struct quota_root *
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);
More information about the dovecot-cvs
mailing list