dovecot-1.1: Maildir++ quota: Fixed maildirsize recalculation wh...

dovecot at dovecot.org dovecot at dovecot.org
Sun Oct 5 19:29:09 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.1/rev/a80719eac45d
changeset: 7920:a80719eac45d
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Oct 05 19:29:06 2008 +0300
description:
Maildir++ quota: Fixed maildirsize recalculation when quota limits were read from the file.

diffstat:

1 file changed, 19 insertions(+), 12 deletions(-)
src/plugins/quota/quota-maildir.c |   31 +++++++++++++++++++------------

diffs (61 lines):

diff -r 32c63bf51172 -r a80719eac45d src/plugins/quota/quota-maildir.c
--- a/src/plugins/quota/quota-maildir.c	Sun Oct 05 19:09:23 2008 +0300
+++ b/src/plugins/quota/quota-maildir.c	Sun Oct 05 19:29:06 2008 +0300
@@ -529,23 +529,22 @@ static int maildirsize_read(struct maild
 
 	/* @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;
-	}
-
-	/* file is smaller than 5120 bytes, which means we can use it */
+		if (size >= sizeof(buf)-1) {
+			/* we'll need to recalculate the quota */
+			break;
+		}
+	}
+
+	/* 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;
 
@@ -555,6 +554,13 @@ static int maildirsize_read(struct maild
 	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')
@@ -562,7 +568,8 @@ static int maildirsize_read(struct maild
 	}
 
 	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 */


More information about the dovecot-cvs mailing list