summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Chantry <shiningxc@gmail.com>2009-09-26 02:42:27 +0200
committerDan McGee <dan@archlinux.org>2009-10-04 09:32:02 -0500
commit44a57c890b2ecba85dbd8364594883439634f630 (patch)
tree71a9cb8f2807baa27b22789a15c9c624d1103b56
parent20392c0a025d01128eb78c6656db7c15b3fbcd89 (diff)
downloadpacman-44a57c890b2ecba85dbd8364594883439634f630.tar.xz
callback.c : fallback to normal download with bogus size
When using totaldownload, we might get into some weird situations where xfered>total because of bogus CSIZE database entries. This code adds a sanity check and fallbacks to normal download progress if needed. Here is an example using totaldownload on a database with wrong CSIZE, for a total download of ~26 MB. Before : gnome-desktop-2.28.... 1144,3K 678,3K/s 00:00:02 [#################] 4% gnome-panel-2.28.0-... 4,2M 887,7K/s 00:00:05 [#################] 16% gnome-applets-2.28.... 13,6M 1083,0K/s 00:00:13 [#################] 52% gnome-backgrounds-2... 22,9M 964,0K/s 00:00:24 [#################] 87% gnome-settings-daem... 23,6M 938,5K/s 00:00:26 [#################] 90% gnome-control-cente... 26,1M 946,1K/s 00:00:28 [#################] 100% gnome-icon-theme-2.... 27,7M 1465,0K/s 1193046:28:15 [#######----------] gnome-icon-theme-2.... 28,0M 1502,2K/s 1193046:28:15 [########---------] gnome-icon-theme-2.... 28,4M 1582,2K/s 1193046:28:15 [##########-------] gnome-icon-theme-2.... 28,7M 1603,4K/s 1193046:28:15 [############-----] gnome-icon-theme-2.... 29,0M 1604,5K/s 1193046:28:15 [##############---] gnome-icon-theme-2.... 29,3M 1621,0K/s 1193046:28:14 [################-] gnome-icon-theme-2.... 29,6M 1434,8K/s 1193046:28:14 [#################] gnome-icon-theme-2.... 29,6M 974,2K/s 00:00:31 [#################] 113% After : gnome-desktop-2.28.... 1144,3K 1038,7K/s 00:00:01 [#################] 4% gnome-panel-2.28.0-... 4,2M 988,4K/s 00:00:04 [#################] 16% gnome-applets-2.28.... 13,6M 1190,4K/s 00:00:12 [#################] 52% gnome-backgrounds-2... 22,9M 1242,9K/s 00:00:19 [#################] 87% gnome-settings-daem... 23,6M 1193,9K/s 00:00:20 [#################] 90% gnome-control-cente... 2,5M 1347,4K/s 00:00:02 [#################] 100% gnome-icon-theme-2.... 3,5M 1205,4K/s 00:00:03 [#################] 100% Note that gnome-control-center resetted to normal progress mode (2,5M is the package size, not the total size) Signed-off-by: Xavier Chantry <shiningxc@gmail.com> Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r--src/pacman/callback.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index e83a97d2..1cdb1153 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -439,7 +439,7 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
int len, wclen, wcwid, padwid;
wchar_t *wcfname;
- int totaldownload;
+ int totaldownload = 0;
off_t xfered, total;
float rate = 0.0, timediff = 0.0, f_xfered = 0.0;
unsigned int eta_h = 0, eta_m = 0, eta_s = 0;
@@ -456,9 +456,14 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
/* only use TotalDownload if enabled and we have a callback value */
if(config->totaldownload && list_total) {
- totaldownload = 1;
- } else {
- totaldownload = 0;
+ /* sanity check */
+ if(list_xfered + file_total <= list_total) {
+ totaldownload = 1;
+ } else {
+ /* bogus values : don't enable totaldownload and reset */
+ list_xfered = 0;
+ list_total = 0;
+ }
}
if(totaldownload) {
@@ -469,6 +474,11 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
total = file_total;
}
+ /* bogus values : stop here */
+ if(xfered > total) {
+ return;
+ }
+
/* this is basically a switch on xfered: 0, total, and
* anything else */
if(file_xfered == 0) {