[pacman-dev] [PATCH] compute package download size outside _alpm_sync_prepare

Jonathan Conder j at skurvy.no-ip.org
Thu May 6 00:07:37 CEST 2010


Thanks to Dan for pointing out a mistake I made.
---
 lib/libalpm/db.h   |    3 ++-
 lib/libalpm/sync.c |   14 +++++++++++++-
 2 files changed, 15 insertions(+), 2 deletions(-)

diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index 9b78ad4..1851b5c 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -34,7 +34,8 @@ typedef enum _pmdbinfrq_t {
 	INFRQ_FILES = (1 << 3),
 	INFRQ_SCRIPTLET = (1 << 4),
 	INFRQ_DELTAS = (1 << 5),
-	/* ALL should be sum of all above */
+	INFRQ_DSIZE = (1 << 6),
+	/* ALL should be info stored in the package or database */
 	INFRQ_ALL = 0x3F
 } pmdbinfrq_t;
 
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index 4996920..13d39aa 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -356,6 +356,7 @@ static int compute_download_size(pmpkg_t *newpkg)
 	off_t size = 0;
 
 	if(newpkg->origin == PKG_FROM_FILE) {
+		newpkg->infolevel |= INFRQ_DSIZE;
 		newpkg->download_size = 0;
 		return(0);
 	}
@@ -392,6 +393,7 @@ static int compute_download_size(pmpkg_t *newpkg)
 	_alpm_log(PM_LOG_DEBUG, "setting download size %jd for pkg %s\n",
 			(intmax_t)size, alpm_pkg_get_name(newpkg));
 
+	newpkg->infolevel |= INFRQ_DSIZE;
 	newpkg->download_size = size;
 	return(0);
 }
@@ -649,6 +651,9 @@ cleanup:
  */
 off_t SYMEXPORT alpm_pkg_download_size(pmpkg_t *newpkg)
 {
+	if(!(newpkg->infolevel & INFRQ_DSIZE)) {
+		compute_download_size(newpkg);
+	}
 	return(newpkg->download_size);
 }
 
@@ -850,7 +855,14 @@ 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_download_files(files, current->servers, cachedir)) {
+			errors = _alpm_download_files(files, current->servers, cachedir);
+
+			for(j = trans->add; j; j = j->next) {
+				j->infolevel &= ~INFRQ_DSIZE;
+				j->download_size = 0;
+			}
+
+			if (errors) {
 				_alpm_log(PM_LOG_WARNING, _("failed to retrieve some files from %s\n"),
 						current->treename);
 				if(pm_errno == 0) {
-- 
1.7.1




More information about the pacman-dev mailing list