From fe781e4ce4ace4410bbc8bec441140cfc323d262 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sun, 1 Jun 2008 23:10:30 -0500 Subject: Reimplement TotalDownload functionality Add a new totaldlcb callback function to libalpm and make pacman utilize it when the TotalDownload option is enabled. This callback function is pretty simple- it is meant to be called once at the beginning of a "list download" action, and once at the end (with value 0 to indicate the list has been finished). The frontend is responsible for keeping track of adding individual file download amounts to the total xfered amount in order to display some sort of overall progress. Signed-off-by: Dan McGee --- lib/libalpm/sync.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) (limited to 'lib/libalpm/sync.c') diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 2dad8bf7..3dc54d0a 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -811,12 +811,25 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data) ALPM_LOG_FUNC; - ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1)); ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1)); cachedir = _alpm_filecache_setup(); trans->state = STATE_DOWNLOADING; + /* Total progress - figure out the total download size if required to + * pass to the callback. This function is called once, and it is up to the + * frontend to compute incremental progress. */ + if(handle->totaldlcb) { + off_t total_size = (off_t)0; + /* sum up the download size for each package and store total */ + for(i = trans->packages; i; i = i->next) { + pmsyncpkg_t *sync = i->data; + pmpkg_t *spkg = sync->pkg; + total_size += spkg->download_size; + } + handle->totaldlcb(total_size); + } + /* group sync records by repository and download */ for(i = handle->dbs_sync; i; i = i->next) { pmdb_t *current = i->data; @@ -877,6 +890,11 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data) return(0); } + /* clear out value to let callback know we are done */ + if(handle->totaldlcb) { + handle->totaldlcb(0); + } + if(handle->usedelta) { int ret = 0; -- cgit v1.2.3-24-g4f1b