From 6d79ba2db0f37f46b925a509ef83724fc0f61184 Mon Sep 17 00:00:00 2001 From: Dan McGee Date: Sat, 26 Apr 2008 13:03:53 -0500 Subject: Fix some fallout from the delta/download changes We removed one too many FREELIST() calls when trying to fix some memleaks, and add a safety/sanity check to ensure filename is set, as packages in old DBs are likely to not have this field. Signed-off-by: Dan McGee --- lib/libalpm/error.c | 2 +- lib/libalpm/sync.c | 18 ++++++++++++++---- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'lib/libalpm') diff --git a/lib/libalpm/error.c b/lib/libalpm/error.c index 7c30cd09..05caf8ec 100644 --- a/lib/libalpm/error.c +++ b/lib/libalpm/error.c @@ -120,7 +120,7 @@ const char SYMEXPORT *alpm_strerror(int err) case PM_ERR_PKG_CANT_REMOVE: return _("cannot remove all files for package"); case PM_ERR_PKG_INVALID_NAME: - return _("package name is not valid"); + return _("package filename is not valid"); case PM_ERR_PKG_REPO_NOT_FOUND: return _("no such repository"); /* Deltas */ diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 9d087d7e..357b01f2 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -384,11 +384,16 @@ static int syncpkg_cmp(const void *s1, const void *s2) * package. * @param newpkg the new package to upgrade to */ -static void compute_download_size(pmpkg_t *newpkg) +static int compute_download_size(pmpkg_t *newpkg) { - char *fpath = _alpm_filecache_find(alpm_pkg_get_filename(newpkg)); + const char *fname; + char *fpath; unsigned long size = 0; + fname = alpm_pkg_get_filename(newpkg); + ASSERT(fname != NULL, RET_ERR(PM_ERR_PKG_INVALID_NAME, -1)); + fpath = _alpm_filecache_find(fname); + if(fpath) { FREE(fpath); size = 0; @@ -415,10 +420,11 @@ static void compute_download_size(pmpkg_t *newpkg) size = alpm_pkg_get_size(newpkg); } - _alpm_log(PM_LOG_DEBUG, "returning size %ld for pkg %s\n", size, + _alpm_log(PM_LOG_DEBUG, "setting download size %ld for pkg %s\n", size, alpm_pkg_get_name(newpkg)); newpkg->download_size = size; + return(0); } int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, alpm_list_t **data) @@ -645,7 +651,10 @@ int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync for(i = list; i; i = i->next) { /* update download size field */ pmpkg_t *spkg = i->data; - compute_download_size(spkg); + if(compute_download_size(spkg) != 0) { + ret = -1; + goto cleanup; + } } cleanup: @@ -859,6 +868,7 @@ int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data) pm_errno = PM_ERR_RETRIEVE; goto error; } + FREELIST(files); } } if(trans->flags & PM_TRANS_FLAG_PRINTURIS) { -- cgit v1.2.3-70-g09d2