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.
+ /* 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;
diff --git a/src/pacman/callback.h b/src/pacman/callback.h
index 28d396e..2961be8 100644
--- a/src/pacman/callback.h
+++ b/src/pacman/callback.h
@@ -34,6 +34,8 @@ void cb_trans_conv(pmtransconv_t event, void *data1, void *data2,
void cb_trans_progress(pmtransprog_t event, const char *pkgname, int percent,
int howmany, int remain);
+/* 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);
+ /* set TotalDownload callback if option enabled */
+ if(config->totaldownload) {
+ alpm_option_set_totaldlcb(cb_dl_total);
+ }
+
#if defined(HAVE_GETEUID) && !defined(CYGWIN)
/* check if we have sufficient permission for the requested operation */
if(myuid > 0 && needs_transaction()) {
--
1.5.5.3
_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev
06-05-2008, 08:42 AM
Xavier
Reimplement TotalDownload functionality
On Mon, Jun 2, 2008 at 6:14 AM, Dan McGee <dan@archlinux.org> wrote:
> 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.
>
I am sorry I was not able to give serious thinking about this, but now
I am wondering why we need a callback at all for this, instead of a
simple accessor for the total download size. Would it even be
possible?
_______________________________________________
pacman-dev mailing list
pacman-dev@archlinux.org
http://archlinux.org/mailman/listinfo/pacman-dev