[pacman-dev] output issues status

Xavier shiningxc at gmail.com
Mon Dec 3 17:20:44 EST 2007


So, a while ago I reported some output issues here, making the distinction
between two kind :
http://www.archlinux.org/pipermail/pacman-dev/2007-September/009317.html

The first kind was worked around by Dan by removing these pointless "done"
messages :
http://projects.archlinux.org/git/?p=pacman.git;a=commit;h=3017b71cb5cde3aef7e0efb5f49843cccf759956

For the second one, Dan and Aaron had an argument about how to solve it.
Dan has a preference for delaying the output, and Aaron prefers padding with
space (the way it was in 3.0).

22:56   phrakture >> i don't get why you dislike padding with spaces. lots of other apps do that
22:57   phrakture >> i personally think it's a far better idea than blocking message output
22:57   phrakture >> because, well, what if we have a front end that doesn't output progress
22:57   phrakture >> and thus has no progress callback
22:59   toofishes >> we aren't blocking message output *from the backend*
22:59   toofishes >> this is all in the frontend!
23:00   toofishes >> if you had an install where there were 20 permission errors,
                     we are going to have 20 progress bar fragments right now.
23:00   phrakture >> right, and I'm saying we can solve that with maybe 3 lines of code
23:00   toofishes >> ok, patches welcome :)
23:00   phrakture >> but it's padding, and you dislike that
23:01   toofishes >> well i haven't seen your implementation. maybe i won't dislike it.
23:01   toofishes >> i just feel like this isn't the right way or something.


Since Aaron promised restoring the padding way in 3 lines, I couldn't really
compete with that ;), and besides 3.0 already has a sample implementation.
So I tried exploring the delayed output way instead, and hacked something
together in ~50 lines. It's very ugly and hackish, but it's just meant as a
proof of concept, because I'm not even sure the idea is right.


>From 9de58523ee64c4c2d86148fad30be1c6cf543d22 Mon Sep 17 00:00:00 2001
From: Chantry Xavier <shiningxc at gmail.com>
Date: Mon, 3 Dec 2007 22:57:54 +0100
Subject: [PATCH] Delay output during progress bar.

This is just a proof of concept patch to fix the output issue related to the
progress bar by delaying the output.

Signed-off-by: Chantry Xavier <shiningxc at gmail.com>
---
 src/pacman/callback.c |   27 ++++++++++++++++++++++++++-
 src/pacman/util.c     |   29 +++++++++++++++++++++++++++++
 src/pacman/util.h     |    1 +
 3 files changed, 56 insertions(+), 1 deletions(-)

diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index 6129d8d..7d52f5d 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -48,6 +48,10 @@ static struct timeval initial_time;
 /* transaction progress bar ? */
 static int prevpercent=0; /* for less progressbar output */
 
+/* delayed output */
+static int on_progress = 0;
+static alpm_list_t *output = NULL;
+
 /* Silly little helper function, determines if the caller needs a visual update
  * since the last time this function was called.
  * This is made for the two progress bar functions, to prevent flicker
@@ -408,6 +412,19 @@ void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
 
 	/* call refactored fill progress function */
 	fill_progress(percent, percent, getcols() - infolen);
+
+	if(percent == 100) {
+		alpm_list_t *i = NULL;
+		on_progress = 0;
+		for(i = output; i; i = i->next) {
+			printf("%s", (char *)i->data);
+		}
+		alpm_list_free_inner(output, free);
+		alpm_list_free(output);
+		output = NULL;
+	} else {
+		on_progress = 1;
+	}
 }
 
 /* callback to handle display of download progress */
@@ -546,7 +563,15 @@ void cb_log(pmloglevel_t level, char *fmt, va_list args)
 		return;
 	}
 
-	pm_vfprintf(stdout, level, fmt, args);
+	if(on_progress) {
+		char *string = NULL;
+		pm_vasprintf(&string, level, fmt, args);
+		if(string != NULL) {
+			output = alpm_list_add(output, string);
+		}
+	} else {
+		pm_vfprintf(stdout, level, fmt, args);
+	}
 }
 
 /* vim: set ts=2 sw=2 noet: */
diff --git a/src/pacman/util.c b/src/pacman/util.c
index 89313c8..78b6fcf 100644
--- a/src/pacman/util.c
+++ b/src/pacman/util.c
@@ -526,6 +526,35 @@ int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...)
 	return(ret);
 }
 
+int pm_vasprintf(char **string, pmloglevel_t level, const char *format, va_list args)
+{
+	int ret = 0;
+	char *msg = NULL;
+
+	/* if current logmask does not overlap with level, do not print msg */
+	if(!(config->logmask & level)) {
+		return ret;
+	}
+
+	/* print the message using va_arg list */
+	ret = vasprintf(&msg, format, args);
+
+	/* print a prefix to the message */
+	switch(level) {
+		case PM_LOG_ERROR:
+			asprintf(string, _("error: %s"), msg);
+			break;
+		case PM_LOG_WARNING:
+			asprintf(string, _("warning: %s"), msg);
+			break;
+		default:
+			break;
+	}
+	free(msg);
+
+	return(ret);
+}
+
 int pm_vfprintf(FILE *stream, pmloglevel_t level, const char *format, va_list args)
 {
 	int ret = 0;
diff --git a/src/pacman/util.h b/src/pacman/util.h
index 0295d7e..4f4b3db 100644
--- a/src/pacman/util.h
+++ b/src/pacman/util.h
@@ -55,6 +55,7 @@ int yesno(char *fmt, ...);
 int pm_printf(pmloglevel_t level, const char *format, ...) __attribute__((format(printf,2,3)));
 int pm_fprintf(FILE *stream, pmloglevel_t level, const char *format, ...) __attribute__((format(printf,3,4)));
 int pm_vfprintf(FILE *stream, pmloglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0)));
+int pm_vasprintf(char **string, pmloglevel_t level, const char *format, va_list args) __attribute__((format(printf,3,0)));
 
 #ifndef HAVE_STRNDUP
 char *strndup(const char *s, size_t n);
-- 
1.5.3.6





More information about the pacman-dev mailing list