[dovecot-cvs] dovecot/src/plugins/quota quota-dirsize.c,1.8,1.9

cras at dovecot.org cras at dovecot.org
Thu Apr 13 22:15:47 EEST 2006


Update of /var/lib/cvs/dovecot/src/plugins/quota
In directory talvi:/tmp/cvs-serv26422

Modified Files:
	quota-dirsize.c 
Log Message:
Count INBOX also if it's outside the default mail directory.



Index: quota-dirsize.c
===================================================================
RCS file: /var/lib/cvs/dovecot/src/plugins/quota/quota-dirsize.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -d -r1.8 -r1.9
--- quota-dirsize.c	6 Mar 2006 15:48:33 -0000	1.8
+++ quota-dirsize.c	13 Apr 2006 19:15:45 -0000	1.9
@@ -133,22 +133,51 @@
 	return ret;
 }
 
+static int get_usage(struct dirsize_quota_root *root,
+		     const char *path, bool is_file, uint64_t *value_r)
+{
+	struct stat st;
+
+	if (is_file) {
+		if (lstat(path, &st) < 0) {
+			if (errno == ENOENT)
+				return 0;
+
+			i_error("lstat(%s) failed: %m", path);
+			return -1;
+		}
+		*value_r += st.st_size;
+	} else {
+		if (get_dir_usage(path, value_r) < 0) {
+			quota_set_error(root->root.setup->quota,
+					"Internal quota calculation error");
+			return -1;
+		}
+	}
+	return 0;
+}
+
 static int
 get_quota_root_usage(struct dirsize_quota_root *root, uint64_t *value_r)
 {
 	struct mail_storage *const *storages;
 	unsigned int i, count;
-	const char *path;
+	const char *path, *inbox_path;
 	bool is_file;
 
 	storages = array_get(&root->root.storages, &count);
 	for (i = 0; i < count; i++) {
 		path = mail_storage_get_mailbox_path(storages[i], "", &is_file);
 
-		if (get_dir_usage(path, value_r) < 0) {
-			quota_set_error(root->root.setup->quota,
-					"Internal quota calculation error");
+		if (get_usage(root, path, is_file, value_r) < 0)
 			return -1;
+
+		/* INBOX may be in different path. */
+		inbox_path = mail_storage_get_mailbox_path(storages[i],
+							   "INBOX", &is_file);
+		if (strncmp(inbox_path, path, strlen(path)) != 0) {
+			if (get_usage(root, inbox_path, is_file, value_r) < 0)
+				return -1;
 		}
 	}
 



More information about the dovecot-cvs mailing list