[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    [PATCHES] shared progress meter for wget and tftp
From:       Magnus Damm <magnus.damm () gmail ! com>
Date:       2009-09-30 13:03:32
Message-ID: aec7e5c30909300603u4d4775aesaf7d112d359ead4 () mail ! gmail ! com
[Download RAW message or body]

Hi everyone,

Here comes a few patches that break out the progress meter code from
wget and hooks it up to the tftp client. I'd like to see this feature
picked up for inclusion in upstream busybox. That said, I realize that
the patches may be far from perfect. So if you have any ideas on how
to improve things please let me know and i'll do my best to rewrite
and resubmit.

Apply in the following order on top of 2f3f09c287f43dcad50b740793c2b467f166c058:
1: busybox-git-tftp-tsize-20090930.patch
2: busybox-git-wget-break-out-progress-20090930.patch
3: busybox-git-tftp-progress-20090930.patch
4: busybox-git-progress-unknown-size-20090930.patch

Cheers,

/ magnus

["busybox-git-tftp-tsize-20090930.patch" (application/octet-stream)]

From: Magnus Damm <damm@opensource.se>

Add "tsize" option support to the tftp client
in the case of ENABLE_FEATURE_TFTP_BLOCKSIZE.

Signed-off-by: Magnus Damm <damm@opensource.se>
---

 networking/tftp.c |   30 ++++++++++++++++--------------
 1 file changed, 16 insertions(+), 14 deletions(-)

--- 0001/networking/tftp.c
+++ work/networking/tftp.c	2009-09-29 21:01:44.000000000 +0900
@@ -158,15 +158,12 @@ static int tftp_protocol(
 		len_and_sockaddr *peer_lsa,
 		const char *local_file
 		IF_TFTP(, const char *remote_file)
-		IF_FEATURE_TFTP_BLOCKSIZE(IF_TFTPD(, void *tsize))
+		IF_FEATURE_TFTP_BLOCKSIZE(, int tsize)
 		IF_FEATURE_TFTP_BLOCKSIZE(, int blksize))
 {
 #if !ENABLE_TFTP
 # define remote_file NULL
 #endif
-#if !(ENABLE_FEATURE_TFTP_BLOCKSIZE && ENABLE_TFTPD)
-# define tsize NULL
-#endif
 #if !ENABLE_FEATURE_TFTP_BLOCKSIZE
 	enum { blksize = TFTP_BLKSIZE_DEFAULT };
 #endif
@@ -326,11 +323,9 @@ static int tftp_protocol(
 		cp += sizeof("octet");
 
 #if ENABLE_FEATURE_TFTP_BLOCKSIZE
-		if (blksize == TFTP_BLKSIZE_DEFAULT)
-			goto send_pkt;
-
 		/* Non-standard blocksize: add option to pkt */
-		if ((&xbuf[io_bufsize - 1] - cp) < sizeof("blksize NNNNN")) {
+		if ((&xbuf[io_bufsize - 1] - cp)
+		    < sizeof("blksize NNNNN tsize NNNNNNNNNN")) {
 			bb_error_msg("remote filename is too long");
 			goto ret;
 		}
@@ -340,16 +335,17 @@ static int tftp_protocol(
 
 #if ENABLE_FEATURE_TFTP_BLOCKSIZE
  add_blksize_opt:
-#if ENABLE_TFTPD
 		if (tsize) {
 			struct stat st;
 			/* add "tsize", <nul>, size, <nul> */
 			strcpy(cp, "tsize");
 			cp += sizeof("tsize");
+			st.st_size = 0;
 			fstat(local_fd, &st);
 			cp += snprintf(cp, 10, "%u", (int) st.st_size) + 1;
+			tsize = 0;
 		}
-#endif
+
 		if (blksize != TFTP_BLKSIZE_DEFAULT) {
 			/* add "blksize", <nul>, blksize, <nul> */
 			strcpy(cp, "blksize");
@@ -497,6 +493,11 @@ static int tftp_protocol(
 					}
 					io_bufsize = blksize + 4;
 				}
+				res = tftp_get_option("tsize", &rbuf[2], len - 2);
+				if (res) {
+					tsize = bb_strtou(res, NULL, 10);
+				}
+
 				if (CMD_GET(option_mask32)) {
 					/* We'll send ACK for OACK,
 					 * such ACK has "block no" of 0 */
@@ -578,7 +579,6 @@ static int tftp_protocol(
 			&peer_lsa->u.sa, peer_lsa->len);
 	return EXIT_FAILURE;
 #undef remote_file
-#undef tsize
 }
 
 #if ENABLE_TFTP
@@ -645,7 +645,7 @@ int tftp_main(int argc UNUSED_PARAM, cha
 	result = tftp_protocol(
 		NULL /*our_lsa*/, peer_lsa,
 		local_file, remote_file
-		IF_FEATURE_TFTP_BLOCKSIZE(IF_TFTPD(, NULL /*tsize*/))
+		IF_FEATURE_TFTP_BLOCKSIZE(, 1 /*"tsize"*/)
 		IF_FEATURE_TFTP_BLOCKSIZE(, blksize)
 	);
 
@@ -667,7 +667,7 @@ int tftpd_main(int argc UNUSED_PARAM, ch
 	const char *error_msg;
 	int opt, result, opcode;
 	IF_FEATURE_TFTP_BLOCKSIZE(int blksize = TFTP_BLKSIZE_DEFAULT;)
-	IF_FEATURE_TFTP_BLOCKSIZE(char *tsize = NULL;)
+	IF_FEATURE_TFTP_BLOCKSIZE(int tsize = 0;)
 
 	INIT_G();
 
@@ -730,7 +730,9 @@ int tftpd_main(int argc UNUSED_PARAM, ch
 				}
 			}
 			/* did client ask us about file size? */
-			tsize = tftp_get_option("tsize", opt_str, opt_len);
+			if (tftp_get_option("tsize", opt_str, opt_len)) {
+				tsize = 1;
+			}
 		}
 	}
 #endif

["busybox-git-wget-break-out-progress-20090930.patch" (application/octet-stream)]

From: Magnus Damm <damm@opensource.se>

Break out the progress meter code from networking/wget.c
to libbb/progress.c and include/libbb.h. This change is
made so the progress meter code can be shared with other
applets such as the tftp client. The progress meter logic
is kept intact.

Signed-off-by: Magnus Damm <damm@opensource.se>
---

 include/libbb.h   |   10 ++++
 libbb/Kbuild      |    1 
 libbb/progress.c  |  130 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 networking/wget.c |  127 ++-------------------------------------------------
 4 files changed, 147 insertions(+), 121 deletions(-)

--- 0001/include/libbb.h
+++ work/include/libbb.h	2009-09-29 22:07:45.000000000 +0900
@@ -1426,6 +1426,16 @@ int print_flags_separated(const int *mas
 		int flags, const char *separator) FAST_FUNC;
 int print_flags(const masks_labels_t *ml, int flags) FAST_FUNC;
 
+typedef struct bb_progress_t {
+	off_t lastsize;
+	unsigned lastupdate_sec;
+	unsigned start_sec;
+} bb_progress_t;
+
+void bb_progress_init(bb_progress_t *p);
+void bb_progress_update(bb_progress_t *p, const char *curfile,
+			off_t beg_range, off_t transferred, off_t totalsize);
+void bb_progress_done(bb_progress_t *p);
 
 extern const char *applet_name;
 /* "BusyBox vN.N.N (timestamp or extra_version)" */
--- 0001/libbb/Kbuild
+++ work/libbb/Kbuild	2009-09-29 22:07:45.000000000 +0900
@@ -75,6 +75,7 @@ lib-y += printable.o
 lib-y += print_flags.o
 lib-y += process_escape_sequence.o
 lib-y += procps.o
+lib-y += progress.o
 lib-y += ptr_to_globals.o
 lib-y += read.o
 lib-y += read_key.o
--- /dev/null
+++ work/libbb/progress.c	2009-09-29 22:07:45.000000000 +0900
@@ -0,0 +1,130 @@
+
+#include "libbb.h"
+
+enum {
+	STALLTIME = 5                   /* Seconds when xfer considered "stalled" */
+};
+
+static unsigned int get_tty2_width(void)
+{
+	unsigned width;
+	get_terminal_width_height(2, &width, NULL);
+	return width;
+}
+
+void bb_progress_init(bb_progress_t *p)
+{
+	p->start_sec = monotonic_sec();
+	p->lastupdate_sec = p->start_sec;
+	p->lastsize = 0;
+}
+
+void bb_progress_done(bb_progress_t *p)
+{
+	(void)p;
+	fputc('\n', stderr);
+}
+
+void bb_progress_update(bb_progress_t *p, const char *curfile,
+			off_t beg_range, off_t transferred, off_t totalsize)
+{
+	off_t abbrevsize;
+	unsigned since_last_update, elapsed;
+	unsigned ratio;
+	int barlength, i;
+
+	ratio = 100;
+	if (totalsize) {
+		/* long long helps to have it working even if !LFS */
+		ratio = (unsigned) (100ULL * (transferred+beg_range) / totalsize);
+		if (ratio > 100) ratio = 100;
+	}
+
+	fprintf(stderr, "\r%-20.20s%4d%% ", curfile, ratio);
+
+	barlength = get_tty2_width() - 49;
+	if (barlength > 0) {
+		/* god bless gcc for variable arrays :) */
+		i = barlength * ratio / 100;
+		{
+			char buf[i+1];
+			memset(buf, '*', i);
+			buf[i] = '\0';
+			fprintf(stderr, "|%s%*s|", buf, barlength - i, "");
+		}
+	}
+	i = 0;
+	abbrevsize = transferred + beg_range;
+	while (abbrevsize >= 100000) {
+		i++;
+		abbrevsize >>= 10;
+	}
+	/* see http://en.wikipedia.org/wiki/Tera */
+	fprintf(stderr, "%6d%c ", (int)abbrevsize, " kMGTPEZY"[i]);
+
+// Nuts! Ain't it easier to update progress meter ONLY when we transferred++?
+
+	elapsed = monotonic_sec();
+	since_last_update = elapsed - p->lastupdate_sec;
+	if (transferred > p->lastsize) {
+		p->lastupdate_sec = elapsed;
+		p->lastsize = transferred;
+		if (since_last_update >= STALLTIME) {
+			/* We "cut off" these seconds from elapsed time
+			 * by adjusting start time */
+			p->start_sec += since_last_update;
+		}
+		since_last_update = 0; /* we are un-stalled now */
+	}
+	elapsed -= p->start_sec; /* now it's "elapsed since start" */
+
+	if (since_last_update >= STALLTIME) {
+		fprintf(stderr, " - stalled -");
+	} else {
+		off_t to_download = totalsize - beg_range;
+		if (!totalsize || transferred <= 0 || (int)elapsed <= 0 || transferred > to_download) {
+			fprintf(stderr, "--:--:-- ETA");
+		} else {
+			/* to_download / (transferred/elapsed) - elapsed: */
+			int eta = (int) ((unsigned long long)to_download*elapsed/transferred - elapsed);
+			/* (long long helps to have working ETA even if !LFS) */
+			i = eta % 3600;
+			fprintf(stderr, "%02d:%02d:%02d ETA", eta / 3600, i / 60, i % 60);
+		}
+	}
+}
+/* Original copyright notice which applies to the CONFIG_FEATURE_WGET_STATUSBAR stuff,
+ * much of which was blatantly stolen from openssh.  */
+/*-
+ * Copyright (c) 1992, 1993
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
+ *		ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
+ *
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ */
--- 0001/networking/wget.c
+++ work/networking/wget.c	2009-09-29 22:07:45.000000000 +0900
@@ -24,12 +24,9 @@ struct globals {
 	off_t content_len;        /* Content-length of the file */
 	off_t beg_range;          /* Range at which continue begins */
 #if ENABLE_FEATURE_WGET_STATUSBAR
-	off_t lastsize;
-	off_t totalsize;
 	off_t transferred;        /* Number of bytes transferred so far */
 	const char *curfile;      /* Name of current file being transferred */
-	unsigned lastupdate_sec;
-	unsigned start_sec;
+	bb_progress_t pmt;
 #endif
 	smallint chunked;         /* chunked transfer encoding */
 	smallint got_clen;        /* got content-length: from server  */
@@ -40,108 +37,30 @@ struct BUG_G_too_big {
 };
 #define content_len     (G.content_len    )
 #define beg_range       (G.beg_range      )
-#define lastsize        (G.lastsize       )
-#define totalsize       (G.totalsize      )
 #define transferred     (G.transferred    )
 #define curfile         (G.curfile        )
-#define lastupdate_sec  (G.lastupdate_sec )
-#define start_sec       (G.start_sec      )
 #define INIT_G() do { } while (0)
 
 
 #if ENABLE_FEATURE_WGET_STATUSBAR
-enum {
-	STALLTIME = 5                   /* Seconds when xfer considered "stalled" */
-};
-
-static unsigned int get_tty2_width(void)
-{
-	unsigned width;
-	get_terminal_width_height(2, &width, NULL);
-	return width;
-}
 
 static void progress_meter(int flag)
 {
 	/* We can be called from signal handler */
 	int save_errno = errno;
-	off_t abbrevsize;
-	unsigned since_last_update, elapsed;
-	unsigned ratio;
-	int barlength, i;
 
 	if (flag == -1) { /* first call to progress_meter */
-		start_sec = monotonic_sec();
-		lastupdate_sec = start_sec;
-		lastsize = 0;
-		totalsize = content_len + beg_range; /* as content_len changes.. */
-	}
-
-	ratio = 100;
-	if (totalsize != 0 && !G.chunked) {
-		/* long long helps to have it working even if !LFS */
-		ratio = (unsigned) (100ULL * (transferred+beg_range) / totalsize);
-		if (ratio > 100) ratio = 100;
-	}
-
-	fprintf(stderr, "\r%-20.20s%4d%% ", curfile, ratio);
-
-	barlength = get_tty2_width() - 49;
-	if (barlength > 0) {
-		/* god bless gcc for variable arrays :) */
-		i = barlength * ratio / 100;
-		{
-			char buf[i+1];
-			memset(buf, '*', i);
-			buf[i] = '\0';
-			fprintf(stderr, "|%s%*s|", buf, barlength - i, "");
-		}
-	}
-	i = 0;
-	abbrevsize = transferred + beg_range;
-	while (abbrevsize >= 100000) {
-		i++;
-		abbrevsize >>= 10;
-	}
-	/* see http://en.wikipedia.org/wiki/Tera */
-	fprintf(stderr, "%6d%c ", (int)abbrevsize, " kMGTPEZY"[i]);
-
-// Nuts! Ain't it easier to update progress meter ONLY when we transferred++?
-
-	elapsed = monotonic_sec();
-	since_last_update = elapsed - lastupdate_sec;
-	if (transferred > lastsize) {
-		lastupdate_sec = elapsed;
-		lastsize = transferred;
-		if (since_last_update >= STALLTIME) {
-			/* We "cut off" these seconds from elapsed time
-			 * by adjusting start time */
-			start_sec += since_last_update;
-		}
-		since_last_update = 0; /* we are un-stalled now */
+		bb_progress_init(&G.pmt);
 	}
-	elapsed -= start_sec; /* now it's "elapsed since start" */
 
-	if (since_last_update >= STALLTIME) {
-		fprintf(stderr, " - stalled -");
-	} else {
-		off_t to_download = totalsize - beg_range;
-		if (transferred <= 0 || (int)elapsed <= 0 || transferred > to_download || G.chunked) {
-			fprintf(stderr, "--:--:-- ETA");
-		} else {
-			/* to_download / (transferred/elapsed) - elapsed: */
-			int eta = (int) ((unsigned long long)to_download*elapsed/transferred - elapsed);
-			/* (long long helps to have working ETA even if !LFS) */
-			i = eta % 3600;
-			fprintf(stderr, "%02d:%02d:%02d ETA", eta / 3600, i / 60, i % 60);
-		}
-	}
+	bb_progress_update(&G.pmt, curfile, beg_range, transferred,
+			   G.chunked ? 0 : content_len + beg_range);
 
 	if (flag == 0) {
 		/* last call to progress_meter */
 		alarm(0);
+		bb_progress_done(&G.pmt);
 		transferred = 0;
-		fputc('\n', stderr);
 	} else {
 		if (flag == -1) { /* first call to progress_meter */
 			signal_SA_RESTART_empty_mask(SIGALRM, progress_meter);
@@ -151,41 +70,7 @@ static void progress_meter(int flag)
 
 	errno = save_errno;
 }
-/* Original copyright notice which applies to the CONFIG_FEATURE_WGET_STATUSBAR stuff,
- * much of which was blatantly stolen from openssh.  */
-/*-
- * Copyright (c) 1992, 1993
- *	The Regents of the University of California.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * 3. <BSD Advertising Clause omitted per the July 22, 1999 licensing change
- *		ftp://ftp.cs.berkeley.edu/pub/4bsd/README.Impt.License.Change>
- *
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
+
 #else /* FEATURE_WGET_STATUSBAR */
 
 static ALWAYS_INLINE void progress_meter(int flag UNUSED_PARAM) { }

["busybox-git-tftp-progress-20090930.patch" (application/octet-stream)]

From: Magnus Damm <damm@opensource.se>

Add a progress meter to the tftp applet.

The broken out wget progress meter code is tied in to
the tftp applet. If ENABLE_FEATURE_TFTP_BLOCKSIZE is
enabled then the tsize option will be used to calculate
the percentage for the progress meter.

Signed-off-by: Magnus Damm <damm@opensource.se>
---

 networking/Config.in |    7 +++++
 networking/tftp.c    |   61 ++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 68 insertions(+)

--- 0001/networking/Config.in
+++ work/networking/Config.in	2009-09-29 23:05:25.000000000 +0900
@@ -853,6 +853,13 @@ config FEATURE_TFTP_BLOCKSIZE
 	  Allow tftp to specify block size, and tftpd to understand
 	  "blksize" option.
 
+config FEATURE_TFTP_STATUSBAR
+	bool "Enable tftp progress meter"
+	default n
+	depends on TFTP
+	help
+	  Enable the transfer progress bar for tftp client transfers.
+
 config TFTP_DEBUG
 	bool "Enable debug"
 	default n
--- 0002/networking/tftp.c
+++ work/networking/tftp.c	2009-09-29 23:05:25.000000000 +0900
@@ -84,6 +84,12 @@ struct globals {
 	char *user_opt;
 	/* used in tftpd_main(), a bit big for stack: */
 	char block_buf[TFTP_BLKSIZE_DEFAULT];
+#if ENABLE_FEATURE_TFTP_STATUSBAR
+	off_t pos;
+	off_t size;
+	const char *file;
+	bb_progress_t pmt;
+#endif
 };
 #define G (*(struct globals*)&bb_common_bufsiz1)
 #define block_buf        (G.block_buf   )
@@ -94,6 +100,46 @@ struct globals {
 #define error_pkt_reason (error_pkt[3])
 #define error_pkt_str    (error_pkt + 4)
 
+#if ENABLE_FEATURE_TFTP_STATUSBAR
+
+/* SIGALRM logic nicked from the wget applet */
+static void progress_meter(int flag)
+{
+	/* We can be called from signal handler */
+	int save_errno = errno;
+
+	if (flag == -1) { /* first call to progress_meter */
+		bb_progress_init(&G.pmt);
+	}
+
+	bb_progress_update(&G.pmt, G.file, 0, G.pos, G.size);
+
+	if (flag == 0) {
+		/* last call to progress_meter */
+		alarm(0);
+		bb_progress_done(&G.pmt);
+	} else {
+		if (flag == -1) { /* first call to progress_meter */
+			signal_SA_RESTART_empty_mask(SIGALRM, progress_meter);
+		}
+		alarm(1);
+	}
+
+	errno = save_errno;
+}
+
+static void tftp_progress_init(const char *file)
+{
+	G.file = file;
+	progress_meter(-1);
+}
+
+static void tftp_progress_done(void)
+{
+	progress_meter(0);
+}
+
+#endif
 
 #if ENABLE_FEATURE_TFTP_BLOCKSIZE
 
@@ -395,6 +441,15 @@ static int tftp_protocol(
 		fprintf(stderr, "\n");
 #endif
 		xsendto(socket_fd, xbuf, send_len, &peer_lsa->u.sa, peer_lsa->len);
+
+#if ENABLE_FEATURE_TFTP_STATUSBAR
+		if (ENABLE_TFTP && remote_file) { /* tftp */
+#if ENABLE_FEATURE_TFTP_BLOCKSIZE
+			G.size = tsize;
+#endif
+			G.pos = (block_nr - 1) * blksize;
+		}
+#endif
 		/* Was it final ACK? then exit */
 		if (finished && (opcode == TFTP_ACK))
 			goto ret;
@@ -642,6 +697,9 @@ int tftp_main(int argc UNUSED_PARAM, cha
 			remote_file, local_file);
 #endif
 
+#if ENABLE_FEATURE_TFTP_STATUSBAR
+	tftp_progress_init(remote_file);
+#endif
 	result = tftp_protocol(
 		NULL /*our_lsa*/, peer_lsa,
 		local_file, remote_file
@@ -652,6 +710,9 @@ int tftp_main(int argc UNUSED_PARAM, cha
 	if (result != EXIT_SUCCESS && NOT_LONE_DASH(local_file) && CMD_GET(opt)) {
 		unlink(local_file);
 	}
+#if ENABLE_FEATURE_TFTP_STATUSBAR
+	tftp_progress_done();
+#endif
 	return result;
 }
 

["busybox-git-progress-unknown-size-20090930.patch" (application/octet-stream)]

From: Magnus Damm <damm@opensource.se>

This patch updates the shared progress meter code to only
print out percentage when the total size is known. Without
this patch the percentage is stuck at 100%.

Signed-off-by: Magnus Damm <damm@opensource.se>
---

 libbb/progress.c |    9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

--- 0003/libbb/progress.c
+++ work/libbb/progress.c	2009-09-30 21:41:15.000000000 +0900
@@ -33,14 +33,17 @@ void bb_progress_update(bb_progress_t *p
 	unsigned ratio;
 	int barlength, i;
 
-	ratio = 100;
+	/* print out percentage only when the total size is known */
 	if (totalsize) {
 		/* long long helps to have it working even if !LFS */
 		ratio = (unsigned) (100ULL * (transferred+beg_range) / totalsize);
 		if (ratio > 100) ratio = 100;
-	}
 
-	fprintf(stderr, "\r%-20.20s%4d%% ", curfile, ratio);
+		fprintf(stderr, "\r%-20.20s%4d%% ", curfile, ratio);
+	} else {
+		ratio = 0;
+		fprintf(stderr, "\r%-25.25s ", curfile);
+	}
 
 	barlength = get_tty2_width() - 49;
 	if (barlength > 0) {


_______________________________________________
busybox mailing list
busybox@busybox.net
http://lists.busybox.net/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic