diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libalpm/alpm.h | 3 | ||||
-rw-r--r-- | lib/libalpm/db.c | 3 | ||||
-rw-r--r-- | lib/libalpm/server.c | 47 | ||||
-rw-r--r-- | lib/libalpm/server.h | 6 | ||||
-rw-r--r-- | lib/libalpm/sync.c | 12 |
5 files changed, 55 insertions, 16 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index f8558e1b..cdece2d3 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -81,7 +81,8 @@ int alpm_logaction(char *fmt, ...); * Downloading */ -typedef void (*alpm_cb_download)(const char *filename, int xfered, int total); +typedef void (*alpm_cb_download)(const char *filename, int file_xfered, + int file_total, int list_xfered, int list_total); /* * Options diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 307b9ef8..599d24d0 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -257,7 +257,8 @@ int SYMEXPORT alpm_db_update(int force, pmdb_t *db) dbpath = alpm_option_get_dbpath(); - ret = _alpm_downloadfiles_forreal(db->servers, dbpath, files, lastupdate, newmtime); + ret = _alpm_downloadfiles_forreal(db->servers, dbpath, files, lastupdate, + newmtime, NULL, 0); FREELIST(files); if(ret == 1) { /* mtimes match, do nothing */ diff --git a/lib/libalpm/server.c b/lib/libalpm/server.c index d4c0a05a..7a3339e1 100644 --- a/lib/libalpm/server.c +++ b/lib/libalpm/server.c @@ -133,13 +133,19 @@ static struct url *url_for_file(pmserver_t *server, const char *filename) /* * Download a list of files from a list of servers * - if one server fails, we try the next one in the list + * - if *dl_total is non-NULL, then it will be used as the starting + * download amount when TotalDownload is set. It will also be + * set to the final download amount for the calling function to use. + * - totalsize is the total download size for use when TotalDownload + * is set. Use 0 if the total download size is not known. * * RETURN: 0 for successful download, 1 on error */ int _alpm_downloadfiles(alpm_list_t *servers, const char *localpath, - alpm_list_t *files) + alpm_list_t *files, int *dl_total, unsigned long totalsize) { - return(_alpm_downloadfiles_forreal(servers, localpath, files, NULL, NULL)); + return(_alpm_downloadfiles_forreal(servers, localpath, files, NULL, NULL, + dl_total, totalsize)); } /* @@ -150,15 +156,21 @@ int _alpm_downloadfiles(alpm_list_t *servers, const char *localpath, * "YYYYMMDDHHMMSS" to match the form of ftplib's FtpModDate() function. * - if *mtime2 is non-NULL, then it will be filled with the mtime * of the remote file (from MDTM FTP cmd or Last-Modified HTTP header). + * - if *dl_total is non-NULL, then it will be used as the starting + * download amount when TotalDownload is set. It will also be + * set to the final download amount for the calling function to use. + * - totalsize is the total download size for use when TotalDownload + * is set. Use 0 if the total download size is not known. * * RETURN: 0 for successful download * 1 if the mtimes are identical * -1 on error */ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath, - alpm_list_t *files, const char *mtime1, char *mtime2) + alpm_list_t *files, const char *mtime1, char *mtime2, int *dl_total, + unsigned long totalsize) { - int dltotal_bytes = 0; + int dl_thisfile = 0; alpm_list_t *lp; int done = 0; alpm_list_t *complete = NULL; @@ -206,12 +218,15 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath, if(stat(output, &st) == 0 && st.st_size > 0) { _alpm_log(PM_LOG_DEBUG, "existing file found, using it\n"); fileurl->offset = (off_t)st.st_size; - dltotal_bytes = st.st_size; + dl_thisfile = st.st_size; + if (dl_total != NULL) { + *dl_total += st.st_size; + } localf = fopen(output, "a"); chk_resume = 1; } else { fileurl->offset = (off_t)0; - dltotal_bytes = 0; + dl_thisfile = 0; } /* libdownload does not reset the error code, reset it in the case of previous errors */ @@ -267,7 +282,7 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath, if(localf == NULL) { _alpm_rmrf(output); fileurl->offset = (off_t)0; - dltotal_bytes = 0; + dl_thisfile = 0; localf = fopen(output, "w"); if(localf == NULL) { /* still null? */ _alpm_log(PM_LOG_ERROR, _("cannot write to file '%s'\n"), output); @@ -280,7 +295,10 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath, } /* Progress 0 - initialize */ - if(handle->dlcb) handle->dlcb(pkgname, 0, ust.size); + if(handle->dlcb) { + handle->dlcb(pkgname, 0, ust.size, dl_total ? *dl_total : 0, + totalsize); + } int nread = 0; char buffer[PM_DLBUF_LEN]; @@ -310,10 +328,17 @@ int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath, if(nwritten != nread) { } - dltotal_bytes += nread; + dl_thisfile += nread; + if (dl_total != NULL) { + *dl_total += nread; + } - if(handle->dlcb) handle->dlcb(pkgname, dltotal_bytes, ust.size); + if(handle->dlcb) { + handle->dlcb(pkgname, dl_thisfile, ust.size, + dl_total ? *dl_total : 0, totalsize); + } } + downloadFreeURL(fileurl); fclose(localf); fclose(dlf); @@ -429,7 +454,7 @@ char SYMEXPORT *alpm_fetch_pkgurl(const char *url) alpm_list_t *files = alpm_list_add(NULL, filename); /* download the file */ - if(_alpm_downloadfiles(servers, cachedir, files)) { + if(_alpm_downloadfiles(servers, cachedir, files, NULL, 0)) { _alpm_log(PM_LOG_WARNING, _("failed to download %s\n"), url); return(NULL); } diff --git a/lib/libalpm/server.h b/lib/libalpm/server.h index 462d9b24..914ee6da 100644 --- a/lib/libalpm/server.h +++ b/lib/libalpm/server.h @@ -37,9 +37,11 @@ struct __pmserver_t { pmserver_t *_alpm_server_new(const char *url); void _alpm_server_free(pmserver_t *server); -int _alpm_downloadfiles(alpm_list_t *servers, const char *localpath, alpm_list_t *files); +int _alpm_downloadfiles(alpm_list_t *servers, const char *localpath, + alpm_list_t *files, int *dl_total, unsigned long totalsize); int _alpm_downloadfiles_forreal(alpm_list_t *servers, const char *localpath, - alpm_list_t *files, const char *mtime1, char *mtime2); + alpm_list_t *files, const char *mtime1, char *mtime2, + int *dl_total, unsigned long totalsize); #endif /* _ALPM_SERVER_H */ diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 10a72a7b..40766914 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -990,6 +990,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data) pmtrans_t *tr = NULL; int replaces = 0, retval = 0; const char *cachedir = NULL; + int dltotal = 0, dl = 0; ALPM_LOG_FUNC; @@ -998,6 +999,15 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data) cachedir = _alpm_filecache_setup(); trans->state = STATE_DOWNLOADING; + + /* Sum up the download sizes. This has to be in its own loop because + * the download loop is grouped by db. */ + for(j = trans->packages; j; j = j->next) { + pmsyncpkg_t *sync = j->data; + pmpkg_t *spkg = sync->pkg; + dltotal += alpm_pkg_download_size(spkg, db_local); + } + /* group sync records by repository and download */ for(i = handle->dbs_sync; i; i = i->next) { pmdb_t *current = i->data; @@ -1061,7 +1071,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data) if(files) { EVENT(trans, PM_TRANS_EVT_RETRIEVE_START, current->treename, NULL); - if(_alpm_downloadfiles(current->servers, cachedir, files)) { + if(_alpm_downloadfiles(current->servers, cachedir, files, &dl, dltotal)) { _alpm_log(PM_LOG_WARNING, _("failed to retrieve some files from %s\n"), current->treename); RET_ERR(PM_ERR_RETRIEVE, -1); |