diff options
author | Dan McGee <dan@archlinux.org> | 2008-06-01 23:10:30 -0500 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2008-06-04 15:38:53 -0500 |
commit | fe781e4ce4ace4410bbc8bec441140cfc323d262 (patch) | |
tree | cdb570aeb1e475bf3c5543d6548fd4ea26e871db /lib | |
parent | 0669c9bfac7aead01f1400444e691d542f7645c2 (diff) | |
download | pacman-fe781e4ce4ace4410bbc8bec441140cfc323d262.tar.xz |
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 <dan@archlinux.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libalpm/alpm.h | 6 | ||||
-rw-r--r-- | lib/libalpm/handle.c | 18 | ||||
-rw-r--r-- | lib/libalpm/handle.h | 1 | ||||
-rw-r--r-- | lib/libalpm/sync.c | 20 |
4 files changed, 42 insertions, 3 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index fd3be0d3..9ed2c676 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -82,19 +82,21 @@ int alpm_logaction(char *fmt, ...); typedef void (*alpm_cb_download)(const char *filename, off_t xfered, off_t total); +typedef void (*alpm_cb_totaldl)(off_t total); /* * Options */ -#define PM_DLFNM_LEN 22 - alpm_cb_log alpm_option_get_logcb(); void alpm_option_set_logcb(alpm_cb_log cb); alpm_cb_download alpm_option_get_dlcb(); void alpm_option_set_dlcb(alpm_cb_download cb); +alpm_cb_totaldl alpm_option_get_totaldlcb(); +void alpm_option_set_totaldlcb(alpm_cb_totaldl cb); + const char *alpm_option_get_root(); int alpm_option_set_root(const char *root); diff --git a/lib/libalpm/handle.c b/lib/libalpm/handle.c index c01dd551..af1cc78b 100644 --- a/lib/libalpm/handle.c +++ b/lib/libalpm/handle.c @@ -115,6 +115,15 @@ alpm_cb_download SYMEXPORT alpm_option_get_dlcb() return handle->dlcb; } +alpm_cb_totaldl SYMEXPORT alpm_option_get_totaldlcb() +{ + if (handle == NULL) { + pm_errno = PM_ERR_HANDLE_NULL; + return NULL; + } + return handle->totaldlcb; +} + const char SYMEXPORT *alpm_option_get_root() { if (handle == NULL) { @@ -268,6 +277,15 @@ void SYMEXPORT alpm_option_set_dlcb(alpm_cb_download cb) handle->dlcb = cb; } +void SYMEXPORT alpm_option_set_totaldlcb(alpm_cb_totaldl cb) +{ + if (handle == NULL) { + pm_errno = PM_ERR_HANDLE_NULL; + return; + } + handle->totaldlcb = cb; +} + int SYMEXPORT alpm_option_set_root(const char *root) { struct stat st; diff --git a/lib/libalpm/handle.h b/lib/libalpm/handle.h index 9c537b14..bec0a6f1 100644 --- a/lib/libalpm/handle.h +++ b/lib/libalpm/handle.h @@ -39,6 +39,7 @@ typedef struct _pmhandle_t { /* callback functions */ alpm_cb_log logcb; /* Log callback function */ alpm_cb_download dlcb; /* Download callback function */ + alpm_cb_totaldl totaldlcb; /* Total download callback function */ /* filesystem paths */ char *root; /* Root path, default '/' */ 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; |