mirror of
https://github.com/sheumann/hush.git
synced 2024-09-12 00:55:11 +00:00
progress meter: fix bugs found in stall detection and unknown size logic
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
d55e139649
commit
ab8d00d64f
@ -1584,8 +1584,9 @@ int print_flags_separated(const int *masks, const char *labels,
|
|||||||
int print_flags(const masks_labels_t *ml, int flags) FAST_FUNC;
|
int print_flags(const masks_labels_t *ml, int flags) FAST_FUNC;
|
||||||
|
|
||||||
typedef struct bb_progress_t {
|
typedef struct bb_progress_t {
|
||||||
off_t lastsize;
|
unsigned last_size;
|
||||||
unsigned lastupdate_sec;
|
unsigned last_update_sec;
|
||||||
|
unsigned last_change_sec;
|
||||||
unsigned start_sec;
|
unsigned start_sec;
|
||||||
const char *curfile;
|
const char *curfile;
|
||||||
} bb_progress_t;
|
} bb_progress_t;
|
||||||
|
@ -61,8 +61,9 @@ void FAST_FUNC bb_progress_init(bb_progress_t *p, const char *curfile)
|
|||||||
p->curfile = curfile;
|
p->curfile = curfile;
|
||||||
#endif
|
#endif
|
||||||
p->start_sec = monotonic_sec();
|
p->start_sec = monotonic_sec();
|
||||||
p->lastupdate_sec = p->start_sec;
|
p->last_update_sec = p->start_sec;
|
||||||
p->lastsize = 0;
|
p->last_change_sec = p->start_sec;
|
||||||
|
p->last_size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* File already had beg_size bytes.
|
/* File already had beg_size bytes.
|
||||||
@ -79,12 +80,15 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
|
|||||||
{
|
{
|
||||||
uoff_t beg_and_transferred;
|
uoff_t beg_and_transferred;
|
||||||
unsigned since_last_update, elapsed;
|
unsigned since_last_update, elapsed;
|
||||||
unsigned ratio;
|
|
||||||
int barlength;
|
int barlength;
|
||||||
int kiloscale;
|
int kiloscale;
|
||||||
|
|
||||||
|
//transferred = 1234; /* use for stall detection testing */
|
||||||
|
//totalsize = 0; /* use for unknown size download testing */
|
||||||
|
|
||||||
elapsed = monotonic_sec();
|
elapsed = monotonic_sec();
|
||||||
since_last_update = elapsed - p->lastupdate_sec;
|
since_last_update = elapsed - p->last_update_sec;
|
||||||
|
p->last_update_sec = elapsed;
|
||||||
|
|
||||||
if (totalsize != 0 && transferred >= totalsize - beg_size) {
|
if (totalsize != 0 && transferred >= totalsize - beg_size) {
|
||||||
/* Last call. Do not skip this update */
|
/* Last call. Do not skip this update */
|
||||||
@ -131,23 +135,27 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ENABLE_UNICODE_SUPPORT)
|
||||||
|
fprintf(stderr, "\r%s", p->curfile);
|
||||||
|
else
|
||||||
|
fprintf(stderr, "\r%-20.20s", p->curfile);
|
||||||
|
|
||||||
beg_and_transferred = beg_size + transferred;
|
beg_and_transferred = beg_size + transferred;
|
||||||
|
|
||||||
ratio = 100 * beg_and_transferred / totalsize;
|
if (totalsize != 0) {
|
||||||
if (ENABLE_UNICODE_SUPPORT)
|
unsigned ratio = 100 * beg_and_transferred / totalsize;
|
||||||
fprintf(stderr, "\r%s%4u%% ", p->curfile, ratio);
|
fprintf(stderr, "%4u%%", ratio);
|
||||||
else
|
|
||||||
fprintf(stderr, "\r%-20.20s%4u%% ", p->curfile, ratio);
|
|
||||||
|
|
||||||
barlength = get_tty2_width() - 49;
|
barlength = get_tty2_width() - 49;
|
||||||
if (barlength > 0) {
|
if (barlength > 0) {
|
||||||
/* god bless gcc for variable arrays :) */
|
/* god bless gcc for variable arrays :) */
|
||||||
char buf[barlength + 1];
|
char buf[barlength + 1];
|
||||||
unsigned stars = (unsigned)barlength * beg_and_transferred / totalsize;
|
unsigned stars = (unsigned)barlength * beg_and_transferred / totalsize;
|
||||||
memset(buf, ' ', barlength);
|
memset(buf, ' ', barlength);
|
||||||
buf[barlength] = '\0';
|
buf[barlength] = '\0';
|
||||||
memset(buf, '*', stars);
|
memset(buf, '*', stars);
|
||||||
fprintf(stderr, "|%s|", buf);
|
fprintf(stderr, " |%s|", buf);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
while (beg_and_transferred >= 100000) {
|
while (beg_and_transferred >= 100000) {
|
||||||
@ -158,9 +166,10 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
|
|||||||
fprintf(stderr, "%6u%c", (unsigned)beg_and_transferred, " kMGTPEZY"[kiloscale]);
|
fprintf(stderr, "%6u%c", (unsigned)beg_and_transferred, " kMGTPEZY"[kiloscale]);
|
||||||
#define beg_and_transferred dont_use_beg_and_transferred_below()
|
#define beg_and_transferred dont_use_beg_and_transferred_below()
|
||||||
|
|
||||||
if (transferred != p->lastsize) {
|
since_last_update = elapsed - p->last_change_sec;
|
||||||
p->lastupdate_sec = elapsed;
|
if ((unsigned)transferred != p->last_size) {
|
||||||
p->lastsize = transferred;
|
p->last_change_sec = elapsed;
|
||||||
|
p->last_size = (unsigned)transferred;
|
||||||
if (since_last_update >= STALLTIME) {
|
if (since_last_update >= STALLTIME) {
|
||||||
/* We "cut out" these seconds from elapsed time
|
/* We "cut out" these seconds from elapsed time
|
||||||
* by adjusting start time */
|
* by adjusting start time */
|
||||||
@ -173,7 +182,7 @@ void FAST_FUNC bb_progress_update(bb_progress_t *p,
|
|||||||
|
|
||||||
if (since_last_update >= STALLTIME) {
|
if (since_last_update >= STALLTIME) {
|
||||||
fprintf(stderr, " - stalled -");
|
fprintf(stderr, " - stalled -");
|
||||||
} else if (!totalsize || !transferred || (int)elapsed <= 0) {
|
} else if (!totalsize || !transferred || (int)elapsed < 0) {
|
||||||
fprintf(stderr, " --:--:-- ETA");
|
fprintf(stderr, " --:--:-- ETA");
|
||||||
} else {
|
} else {
|
||||||
unsigned eta, secs, hours;
|
unsigned eta, secs, hours;
|
||||||
|
@ -119,7 +119,7 @@ static void tftp_progress_done(void)
|
|||||||
if (is_bb_progress_inited(&G.pmt)) {
|
if (is_bb_progress_inited(&G.pmt)) {
|
||||||
tftp_progress_update();
|
tftp_progress_update();
|
||||||
bb_putchar_stderr('\n');
|
bb_putchar_stderr('\n');
|
||||||
bb_progress_free(p);
|
bb_progress_free(&G.pmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
Loading…
Reference in New Issue
Block a user