diff options
author | morganamilo <morganamilo@archlinux.org> | 2021-05-09 15:23:57 +0200 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2021-05-09 15:28:04 +0200 |
commit | 8bf17b29a24802c587afda0e96d93b22c5f5caeb (patch) | |
tree | de6ac814ba133f7d04036b8c7d22d3e776353d85 /src | |
parent | 4fead44e3ce97d3a83ca6bab393d480746ba9227 (diff) | |
download | pacman-8bf17b29a24802c587afda0e96d93b22c5f5caeb.tar.gz pacman-8bf17b29a24802c587afda0e96d93b22c5f5caeb.tar.xz |
libalpm: fix download rates becoming negative
When a download fails on one mirror a new download is started on the
next mirror. This causes the ammount downloaded to reset, confusing the
rate math and making it display a negative rate.
This is further complicated by the fact that a download may be resumed
from where it is or started over.
To account for this we alert the frontend that the download was
restarted. Pacman then starts the progress bar over.
Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/pacman/callback.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c index 98d8c5cf..99ad716e 100644 --- a/src/pacman/callback.c +++ b/src/pacman/callback.c @@ -994,6 +994,34 @@ static void dload_progress_event(const char *filename, alpm_download_event_progr fflush(stdout); } +/* download retried */ +static void dload_retry_event(const char *filename, alpm_download_event_retry_t *data) { + if(!dload_progressbar_enabled()) { + return; + } + + int index; + struct pacman_progress_bar *bar; + bool ok = find_bar_for_filename(filename, &index, &bar); + assert(ok); + + if(!data->resume) { + if(total_enabled) { + /* note total download does not reflect partial downloads that are restarted */ + totalbar->xfered -= bar->xfered; + } + } + + bar->xfered = 0; + bar->total_size = 0; + bar->init_time = get_time_ms(); + bar->sync_time = 0; + bar->sync_xfered = 0; + bar->rate = 0.0; + bar->eta = 0.0; +} + + /* download completed */ static void dload_complete_event(const char *filename, alpm_download_event_completed_t *data) { @@ -1090,6 +1118,8 @@ void cb_download(void *ctx, const char *filename, alpm_download_event_type_t eve dload_init_event(filename, data); } else if(event == ALPM_DOWNLOAD_PROGRESS) { dload_progress_event(filename, data); + } else if(event == ALPM_DOWNLOAD_RETRY) { + dload_retry_event(filename, data); } else if(event == ALPM_DOWNLOAD_COMPLETED) { dload_complete_event(filename, data); } else { |