[pacman-dev] CVS update of pacman-lib/src/pacman (downloadprog.c)

Aaron Griffin aaron at archlinux.org
Tue Feb 6 16:54:39 EST 2007


    Date: Tuesday, February 6, 2007 @ 16:54:39
  Author: aaron
    Path: /home/cvs-pacman/pacman-lib/src/pacman

Modified: downloadprog.c (1.9 -> 1.10)

Minor experimental changes to the download progress bar:
* change to Mb and Gb for both total size and transfer rate if needed
* round up to 1 second for downloads that were between 1s and 0.5s

This function needs some serious looking at, as it's probably not 64bit safe (thus the "wrong calculation" problem on the list).


----------------+
 downloadprog.c |   50 ++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 38 insertions(+), 12 deletions(-)


Index: pacman-lib/src/pacman/downloadprog.c
diff -u pacman-lib/src/pacman/downloadprog.c:1.9 pacman-lib/src/pacman/downloadprog.c:1.10
--- pacman-lib/src/pacman/downloadprog.c:1.9	Sat Feb  3 20:36:45 2007
+++ pacman-lib/src/pacman/downloadprog.c	Tue Feb  6 16:54:39 2007
@@ -73,7 +73,7 @@
 		timediff = get_update_timediff(0);
 	}
 
-	if(percent > 0 && percent < 100 && !timediff) {
+	if(percent > 0 && percent <= 100 && !timediff) {
 		/* only update the progress bar when
 		 * a) we first start
 		 * b) we end the progress
@@ -84,17 +84,22 @@
 
 	gettimeofday(&current_time, NULL);
 	total_timediff = current_time.tv_sec-initial_time.tv_sec
-		+ (float)(current_time.tv_usec-initial_time.tv_usec) / 1000000;
+		+ (float)(current_time.tv_usec-initial_time.tv_usec) / 1000000.0;
 
 	if(xfered == total) {
 		/* compute final values */
-		rate = (float)total / (total_timediff * 1024);
-		eta_s = (unsigned int)total_timediff;
+		rate = (float)total / (total_timediff * 1024.0);
+		if(total_timediff < 1.0 && total_timediff > 0.5) {
+			/* round up so we don't display 00:00:00 for quick downloads all the time*/
+			eta_s = 1;
+		} else {
+			eta_s = (unsigned int)total_timediff;
+		}
 		set_output_padding(0); /* shut off padding */
 	} else {
-		rate = (float)(xfered - xfered_last) / (timediff * 1024);
+		rate = (float)(xfered - xfered_last) / (timediff * 1024.0);
 		rate = (float)(rate + 2*rate_last) / 3;
-		eta_s = (unsigned int)(total - xfered) / (rate * 1024);
+		eta_s = (unsigned int)(total - xfered) / (rate * 1024.0);
 	}
 
 	rate_last = rate;
@@ -114,14 +119,35 @@
 		fname[FILENAME_TRIM_LEN] = '\0';
 	}
 
-	/* DL rate cap, for printf formatting - this should be sane for a while
-	 * if anything we can change to MB/s if we need a higher rate */
-	if(rate > 9999.9) {
-		rate = 9999.9;
+	/* Awesome formatting for progress bar.  We need a mess of Kb->Mb->Gb stuff
+	 * here. We'll use limit of 2048 for each until we get some empirical */
+	char rate_size = 'K';
+	char xfered_size = 'K';
+	if(rate > 2048.0) {
+		rate /= 1024.0;
+		rate_size = 'M';
+		if(rate > 2048.0) {
+			rate /= 1024.0;
+			rate_size = 'G';
+			/* we should not go higher than this for a few years (9999.9 Gb/s?)*/
+		}
 	}
 
-	printf(" %-*s %6dK %#6.1fK/s %02u:%02u:%02u", FILENAME_TRIM_LEN, fname, 
-				 xfered/1024, rate, eta_h, eta_m, eta_s);
+	xfered /= 1024; /* convert to K by default */
+	if(xfered > 2048) {
+		xfered /= 1024;
+		xfered_size = 'M';
+		if(xfered > 2048) {
+			xfered /= 1024;
+			xfered_size = 'G';
+			/* I should seriously hope that archlinux packages never break
+			 * the 9999.9GB mark... we'd have more serious problems than the progress
+			 * bar in pacman */ 
+		}
+	}
+
+	printf(" %-*s %6d%c %#6.1f%c/s %02u:%02u:%02u", FILENAME_TRIM_LEN, fname, 
+				 xfered/1024, xfered_size, rate, rate_size, eta_h, eta_m, eta_s);
 
 	free(fname);
 	




More information about the pacman-dev mailing list