Hi

Here is a patch to resolve FS#18769. I created a new INFRQ/infolevel to
describe package download size, so that it could be lazily calculated
like most of the other package info. This differs slightly from most of
the other infolevels, which correspond to information actually read by
_alpm_db_read and alpm_pkg_load. However, I felt it better to do it this
way than setting the download size to -1 for invalid, as this would make
it the only field in pmpkg_t that needs to be initialized to something
other than 0.
It is also possible that the download size will be reported incorrectly
if a package download size is read, and then that same package is
downloaded with alpm_fetch_pkgurl. However, this is better than the
present situation where download sizes aren't reported at all, and
furthermore this is unlikely since alpm_fetch_pkgurl would probably not
be used to download a package that is in the repositories.

Thanks for your time,
Jonathan
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..210e08c 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);
 }
@@ -626,14 +628,6 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync
 			goto cleanup;
 		}
 	}
-	for(i = trans->add; i; i = i->next) {
-		/* update download size field */
-		pmpkg_t *spkg = i->data;
-		if(compute_download_size(spkg) != 0) {
-			ret = -1;
-			goto cleanup;
-		}
-	}
 
 cleanup:
 	alpm_list_free(unresolvable);
@@ -649,6 +643,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);
 }
 
@@ -803,7 +800,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
 		/* sum up the download size for each package and store total */
 		for(i = trans->add; i; i = i->next) {
 			pmpkg_t *spkg = i->data;
-			total_size += spkg->download_size;
+			total_size += alpm_pkg_download_size(spkg);
 		}
 		handle->totaldlcb(total_size);
 	}
@@ -839,7 +836,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data)
 
 				} else {
 					/* not using deltas */
-					if(spkg->download_size != 0) {
+					if(alpm_pkg_download_size(spkg) != 0) {
 						/* add the filename to the download list if needed */
 						files = alpm_list_add(files, strdup(fname));
 					}
@@ -850,7 +847,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) {


Reply via email to