dovecot-2.0: doveadm -v: Print progress counter.

dovecot at dovecot.org dovecot at dovecot.org
Fri May 15 23:25:36 EEST 2009


details:   http://hg.dovecot.org/dovecot-2.0/rev/468273e27777
changeset: 9298:468273e27777
user:      Timo Sirainen <tss at iki.fi>
date:      Fri May 15 16:25:29 2009 -0400
description:
doveadm -v: Print progress counter.

diffstat:

1 file changed, 17 insertions(+), 1 deletion(-)
src/util/doveadm.c |   18 +++++++++++++++++-

diffs (49 lines):

diff -r 3d20388cee21 -r 468273e27777 src/util/doveadm.c
--- a/src/util/doveadm.c	Fri May 15 16:12:49 2009 -0400
+++ b/src/util/doveadm.c	Fri May 15 16:25:29 2009 -0400
@@ -11,6 +11,7 @@
 #include "mail-storage-settings.h"
 #include "mail-storage-service.h"
 
+#include <stdio.h>
 #include <stdlib.h>
 
 static struct mail_user *mail_user;
@@ -152,6 +153,7 @@ handle_all_users(struct master_service *
 {
 	struct mail_storage_service_input input;
 	struct mail_storage_service_multi_ctx *multi;
+	unsigned int user_idx, user_count, interval, n;
 	const char *user;
 	pool_t pool;
 	int ret;
@@ -166,6 +168,12 @@ handle_all_users(struct master_service *
         lib_signals_set_handler(SIGINT, FALSE, sig_die, NULL);
 	lib_signals_set_handler(SIGTERM, FALSE, sig_die, NULL);
 
+	user_count = mail_storage_service_multi_all_init(multi);
+	n = user_count / 10000;
+	for (interval = 10; n > 0 && interval < 1000; interval *= 10)
+		n /= 10;
+	
+	user_idx = 0;
 	while ((ret = mail_storage_service_multi_all_next(multi, &user)) > 0) {
 		if (killed_signo != 0) {
 			/* killed by a signal */
@@ -180,7 +188,15 @@ handle_all_users(struct master_service *
 		} T_END;
 		if (ret < 0)
 			break;
-	}
+		if ((service_flags & MAIL_STORAGE_SERVICE_FLAG_DEBUG) != 0) {
+			if (++user_idx % interval == 0) {
+				printf("\r%d / %d", user_idx, user_count);
+				fflush(stdout);
+			}
+		}
+	}
+	if ((service_flags & MAIL_STORAGE_SERVICE_FLAG_DEBUG) != 0)
+		printf("\n");
 	i_set_failure_prefix("doveadm: ");
 	if (ret < 0)
 		i_error("Failed to iterate through some users");


More information about the dovecot-cvs mailing list