Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnatol Pomozov <anatol.pomozov@gmail.com>2020-05-05 19:50:51 -0700
committerAllan McRae <allan@archlinux.org>2020-05-09 11:58:21 +1000
commitc78eb48d915dc22146073162dda08ddf73c4a508 (patch)
tree9daffa23a059dc690cb2d43a0d234f79932b0dab /src
parent64c4669f579dc5ad8d05329abffbd752ad0ed8f2 (diff)
Extend download callback interface with start/complete events
With the previous download interface the callback uses the first progress event as 'download has started' signal. Unfortunately it does not work with up-to-date files that never receive 'download progress' events. Up-to-date database messages are currently handled in sync_syncdbs() after the sequential download is completed and a result from ALPM is received. But this is not going to work with multiplexed download interface that returns the result only after all files are completed. Another problem with 'first progress event is the beginning of the download' is that such events time are unpredictable. Thus the UI progress bar order might differ from what has been passed by client to alpm_dbs_update() function. We actually want to keep the dbs progress bars in a strict order. To help to solve the given problems extend the download callback to allow 2 more events - download started and completed. 'Download started' events appear in the same order as in the list given by a client. Signed-off-by: Anatol Pomozov <anatol.pomozov@gmail.com> Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/callback.c10
-rw-r--r--src/pacman/callback.h3
-rw-r--r--src/pacman/conf.c2
3 files changed, 12 insertions, 3 deletions
diff --git a/src/pacman/callback.c b/src/pacman/callback.c
index a129758b..613d59d4 100644
--- a/src/pacman/callback.c
+++ b/src/pacman/callback.c
@@ -648,7 +648,7 @@ void cb_dl_total(off_t total)
}
/* callback to handle display of download progress */
-void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
+static void dload_progress_event(const char *filename, off_t file_xfered, off_t file_total)
{
static double rate_last;
static off_t xfered_last;
@@ -858,6 +858,14 @@ void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total)
return;
}
+void cb_download(const char *filename, alpm_download_event_type_t event, void *data)
+{
+ if(event == ALPM_DOWNLOAD_PROGRESS) {
+ alpm_download_event_progress_t *progress = data;
+ dload_progress_event(filename, progress->downloaded, progress->total);
+ }
+}
+
/* Callback to handle notifications from the library */
void cb_log(alpm_loglevel_t level, const char *fmt, va_list args)
{
diff --git a/src/pacman/callback.h b/src/pacman/callback.h
index b4bde5f2..6d92e86b 100644
--- a/src/pacman/callback.h
+++ b/src/pacman/callback.h
@@ -37,7 +37,8 @@ void cb_progress(alpm_progress_t event, const char *pkgname, int percent,
/* callback to handle receipt of total download value */
void cb_dl_total(off_t total);
/* callback to handle display of download progress */
-void cb_dl_progress(const char *filename, off_t file_xfered, off_t file_total);
+void cb_download(const char *filename, alpm_download_event_type_t event,
+ void *data);
/* callback to handle messages/notifications from pacman library */
__attribute__((format(printf, 2, 0)))
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index 7390d741..ac5a5329 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -837,7 +837,7 @@ static int setup_libalpm(void)
config->handle = handle;
alpm_option_set_logcb(handle, cb_log);
- alpm_option_set_dlcb(handle, cb_dl_progress);
+ alpm_option_set_dlcb(handle, cb_download);
alpm_option_set_eventcb(handle, cb_event);
alpm_option_set_questioncb(handle, cb_question);
alpm_option_set_progresscb(handle, cb_progress);