Mercurial > dovecot > original-hg > dovecot-1.2
changeset 8246:8e5fd70ea3be HEAD
Maildir++ quota: Fixed maildirsize recalculation when quota limits were read from the file.
author | Timo Sirainen <tss@iki.fi> |
---|---|
date | Sun, 05 Oct 2008 19:29:22 +0300 |
parents | 2b39142e6430 |
children | a43b7da805f8 |
files | src/plugins/quota/quota-maildir.c |
diffstat | 1 files changed, 17 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/src/plugins/quota/quota-maildir.c Sun Oct 05 19:11:35 2008 +0300 +++ b/src/plugins/quota/quota-maildir.c Sun Oct 05 19:29:22 2008 +0300 @@ -556,23 +556,22 @@ /* @UNSAFE */ size = 0; - while (size < sizeof(buf)-1 && - (ret = read(root->fd, buf + size, sizeof(buf)-1 - size)) != 0) { + while ((ret = read(root->fd, buf + size, sizeof(buf)-1 - size)) != 0) { if (ret < 0) { if (errno == ESTALE) break; i_error("read(%s) failed: %m", root->maildirsize_path); + break; } size += ret; - } - if (ret < 0 || size >= sizeof(buf)-1) { - /* error / recalculation needed. */ - (void)close(root->fd); - root->fd = -1; - return ret < 0 ? -1 : 0; + if (size >= sizeof(buf)-1) { + /* we'll need to recalculate the quota */ + break; + } } - /* file is smaller than 5120 bytes, which means we can use it */ + /* try to use the file even if we ran into some error. if we don't have + forced limits, we'll need to read the header to get them */ root->total_bytes = root->total_count = 0; root->last_size = size; @@ -582,6 +581,13 @@ if (size > 0) size--; buf[size] = '\0'; + if (ret < 0 && size == 0) { + /* the read failed and there's no usable header, fail. */ + (void)close(root->fd); + root->fd = -1; + return -1; + } + /* If there are any NUL bytes, the file is broken. */ for (i = 0; i < size; i++) { if (buf[i] == '\0') @@ -589,7 +595,8 @@ } if (i == size && - maildirsize_parse(root, root->fd, t_strsplit(buf, "\n")) > 0) + maildirsize_parse(root, root->fd, t_strsplit(buf, "\n")) > 0 && + ret == 0) ret = 1; else { /* broken file / need recalculation */