[pacman-dev] crappy version of -Qu (query upgrades)
See http://projects.archlinux.org/git/?p=pacman.git;a=commit;h=63000584b6442412d... TODO: move the implementation to upgrades.c, and reimplement the sync_sysupgrade function in terms of this: trans->packages = alpm_get_upgrades(); I took a slightly different approach : change sync_sysupgrade slightly to also return a list of sync packages. So sync_sysupgrade might still ask questions to the user, but this can be disabled by passing a NULL trans argument. In case trans is not null, sync_sysupgrade will set trans->packages to the list of upgrades. In both cases, it'll return the list of upgrades.
From ddbfb04293e28738d859da53ad09192889afbb6d Mon Sep 17 00:00:00 2001 From: Chantry Xavier <shiningxc@gmail.com> Date: Sat, 25 Aug 2007 00:10:40 +0200 Subject: [PATCH] Remove duplicated get_upgrades function, use sysupgrade instead.
The alpm_get_upgrades was exactly the same as _alpm_sync_sysupgrade, except that it didn't ask for confirmation. There are two kind of questions asked : %s is in IgnorePkg. Install anyway? [Y/n] Replace %s with %s/%s? [Y/n] The first question was actually never asked, because alpm_pkg_compare_versions already ignored the packages in IgnorePkg. I removed the IgnorePkg handling from alpm_pkg_compare_versions, but kept the same behavior with _alpm_sync_sysupgrade, that is ignore packages automatically, without confirmation. The replace question is asked in _alpm_find_replacements. This question can be skipped by using a NULL trans argument, so that we get the same behavior as with alpm_get_upgrades. alpm_db_get_upgrades() can now be replaced by : alpm_sync_sysupgrade(NULL, db_local, syncdbs). Signed-off-by: Chantry Xavier <shiningxc@gmail.com> --- lib/libalpm/alpm.h | 3 +- lib/libalpm/db.c | 141 -------------------------------- lib/libalpm/package.c | 10 --- lib/libalpm/sync.c | 213 +++++++++++++++++++++++++++---------------------- lib/libalpm/sync.h | 1 - lib/libalpm/trans.c | 3 +- src/pacman/query.c | 4 +- 7 files changed, 124 insertions(+), 251 deletions(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 844d9bf..62de9a1 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -163,8 +163,6 @@ alpm_list_t *alpm_db_getgrpcache(pmdb_t *db); alpm_list_t *alpm_db_test(pmdb_t *db); alpm_list_t *alpm_db_search(pmdb_t *db, const alpm_list_t* needles); -alpm_list_t *alpm_db_get_upgrades(void); - /* * Packages */ @@ -237,6 +235,7 @@ typedef enum _pmsynctype_t { pmsynctype_t alpm_sync_get_type(const pmsyncpkg_t *sync); pmpkg_t *alpm_sync_get_pkg(const pmsyncpkg_t *sync); void *alpm_sync_get_data(const pmsyncpkg_t *sync); +alpm_list_t *alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync); /* * Transactions diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index 0cb375d..0da935e 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -46,8 +46,6 @@ #include "cache.h" #include "alpm.h" -#include "sync.h" /* alpm_db_get_upgrades() */ - /** \addtogroup alpm_databases Database Functions * @brief Functions to query and manipulate the database of libalpm * @{ @@ -440,145 +438,6 @@ alpm_list_t SYMEXPORT *alpm_db_search(pmdb_t *db, const alpm_list_t* needles) return(_alpm_db_search(db, needles)); } -/* This function is mostly the same as sync.c find_replacements and sysupgrade - * functions, and we should be able to combine them - this is an interim - * solution made for -Qu operation */ -/** Get a list of upgradable packages on the current system - * @return a pmsyncpkg_t list of packages that are out of date - */ -alpm_list_t SYMEXPORT *alpm_db_get_upgrades(void) -{ - alpm_list_t *syncpkgs = NULL; - const alpm_list_t *i, *j, *k, *m; - - ALPM_LOG_FUNC; - - /* TODO holy nested loops, Batman! */ - /* check for "recommended" package replacements */ - _alpm_log(PM_LOG_DEBUG, "checking for package replacements"); - for(i = handle->dbs_sync; i; i = i->next) { - for(j = _alpm_db_get_pkgcache(i->data); j; j = j->next) { - pmpkg_t *spkg = j->data; - - for(k = alpm_pkg_get_replaces(spkg); k; k = k->next) { - - for(m = _alpm_db_get_pkgcache(handle->db_local); m; m = m->next) { - pmpkg_t *lpkg = m->data; - - if(strcmp(k->data, alpm_pkg_get_name(lpkg)) == 0) { - _alpm_log(PM_LOG_DEBUG, "checking replacement '%s' for package '%s'", - k->data, alpm_pkg_get_name(spkg)); - if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(lpkg))) { - _alpm_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (to be replaced by %s-%s)"), - alpm_pkg_get_name(lpkg), alpm_pkg_get_version(lpkg), - alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); - } else { - /* assume all replaces=() packages are accepted */ - pmsyncpkg_t *sync = NULL; - pmpkg_t *dummy = _alpm_pkg_new(alpm_pkg_get_name(lpkg), NULL); - if(dummy == NULL) { - pm_errno = PM_ERR_MEMORY; - goto error; - } - dummy->requiredby = alpm_list_strdup(alpm_pkg_get_requiredby(lpkg)); - - pmsyncpkg_t *syncpkg; - syncpkg = _alpm_sync_find(syncpkgs, alpm_pkg_get_name(spkg)); - - if(syncpkg) { - /* found it -- just append to the replaces list */ - sync->data = alpm_list_add(sync->data, dummy); - } else { - /* none found -- enter pkg into the final sync list */ - sync = _alpm_sync_new(PM_SYNC_TYPE_REPLACE, spkg, NULL); - if(sync == NULL) { - _alpm_pkg_free(dummy); - pm_errno = PM_ERR_MEMORY; - goto error; - } - sync->data = alpm_list_add(NULL, dummy); - syncpkgs = alpm_list_add(syncpkgs, sync); - } - _alpm_log(PM_LOG_DEBUG, "%s-%s elected for upgrade (to be replaced by %s-%s)", - alpm_pkg_get_name(lpkg), alpm_pkg_get_version(lpkg), - alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); - } - break; - } - } - } - } - } - - /* now do normal upgrades */ - for(i = _alpm_db_get_pkgcache(handle->db_local); i; i = i->next) { - int replace=0; - pmpkg_t *local = i->data; - pmpkg_t *spkg = NULL; - pmsyncpkg_t *sync; - - for(j = handle->dbs_sync; !spkg && j; j = j->next) { - spkg = _alpm_db_get_pkgfromcache(j->data, alpm_pkg_get_name(local)); - } - if(spkg == NULL) { - _alpm_log(PM_LOG_DEBUG, "'%s' not found in sync db -- skipping", - alpm_pkg_get_name(local)); - continue; - } - - /* we don't care about a to-be-replaced package's newer version */ - for(j = syncpkgs; j && !replace; j=j->next) { - sync = j->data; - if(sync->type == PM_SYNC_TYPE_REPLACE) { - if(_alpm_pkg_find(alpm_pkg_get_name(spkg), sync->data)) { - replace=1; - } - } - } - if(replace) { - _alpm_log(PM_LOG_DEBUG, "'%s' is already elected for removal -- skipping", - alpm_pkg_get_name(local)); - continue; - } - - if(alpm_pkg_compare_versions(local, spkg)) { - _alpm_log(PM_LOG_DEBUG, "%s elected for upgrade (%s => %s)", - alpm_pkg_get_name(local), alpm_pkg_get_version(local), - alpm_pkg_get_version(spkg)); - - pmsyncpkg_t *syncpkg; - syncpkg = _alpm_sync_find(syncpkgs, alpm_pkg_get_name(local)); - - if(!syncpkg) { - pmpkg_t *dummy = _alpm_pkg_new(alpm_pkg_get_name(local), - alpm_pkg_get_version(local)); - if(dummy == NULL) { - goto error; - } - sync = _alpm_sync_new(PM_SYNC_TYPE_UPGRADE, spkg, dummy); - if(sync == NULL) { - _alpm_pkg_free(dummy); - goto error; - } - syncpkgs = alpm_list_add(syncpkgs, sync); - } - } - } - - return(syncpkgs); -error: - if(syncpkgs) { - alpm_list_t *tmp; - for(tmp = syncpkgs; tmp; tmp = alpm_list_next(tmp)) { - if(tmp->data) { - _alpm_sync_free(tmp->data); - } - } - alpm_list_free(syncpkgs); - } - return(NULL); -} - /** @} */ pmdb_t *_alpm_db_new(const char *dbpath, const char *treename) diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index 86c19d3..b630102 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -727,16 +727,6 @@ int alpm_pkg_compare_versions(pmpkg_t *local_pkg, pmpkg_t *pkg) /* compare versions and see if we need to upgrade */ cmp = _alpm_versioncmp(alpm_pkg_get_version(pkg), alpm_pkg_get_version(local_pkg)); - if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(pkg))) { - /* package should be ignored (IgnorePkg) */ - if(cmp > 0) { - _alpm_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (%s)"), - alpm_pkg_get_name(local_pkg), alpm_pkg_get_version(local_pkg), - alpm_pkg_get_version(pkg)); - } - return(0); - } - if(cmp != 0 && pkg->force) { cmp = 1; _alpm_log(PM_LOG_WARNING, _("%s: forcing upgrade to version %s"), diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 8aabcdb..edb406f 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -90,13 +90,27 @@ void _alpm_sync_free(pmsyncpkg_t *sync) FREE(sync); } +void _alpm_synclist_free(alpm_list_t *syncpkgs) +{ + if(syncpkgs) { + alpm_list_t *tmp; + for(tmp = syncpkgs; tmp; tmp = alpm_list_next(tmp)) { + if(tmp->data) { + _alpm_sync_free(tmp->data); + } + } + alpm_list_free(syncpkgs); + } + +} + /* Find recommended replacements for packages during a sync. - * (refactored from _alpm_sync_prepare) */ -static int find_replacements(pmtrans_t *trans, pmdb_t *db_local, +static alpm_list_t *_alpm_find_replacements(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync) { alpm_list_t *i, *j, *k; /* wow */ + alpm_list_t *syncpkgs = NULL; ALPM_LOG_FUNC; @@ -127,124 +141,133 @@ static int find_replacements(pmtrans_t *trans, pmdb_t *db_local, alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); } else { /* get confirmation for the replacement */ - int doreplace = 0; - QUESTION(trans, PM_TRANS_CONV_REPLACE_PKG, lpkg, spkg, db->treename, &doreplace); + if(trans) { + int doreplace = 0; + QUESTION(trans, PM_TRANS_CONV_REPLACE_PKG, lpkg, spkg, db->treename, &doreplace); + if(!doreplace) { + continue; + } + } - if(doreplace) { - /* if confirmed, add this to the 'final' list, designating 'lpkg' as - * the package to replace. - */ - pmsyncpkg_t *sync; - pmpkg_t *dummy = _alpm_pkg_new(alpm_pkg_get_name(lpkg), NULL); - if(dummy == NULL) { + /* if confirmed, add this to the 'final' list, designating 'lpkg' as + * the package to replace. + */ + pmsyncpkg_t *sync; + pmpkg_t *dummy = _alpm_pkg_new(alpm_pkg_get_name(lpkg), NULL); + if(dummy == NULL) { + pm_errno = PM_ERR_MEMORY; + _alpm_synclist_free(syncpkgs); + return(NULL); + } + dummy->requiredby = alpm_list_strdup(alpm_pkg_get_requiredby(lpkg)); + /* check if spkg->name is already in the packages list. */ + sync = _alpm_sync_find(syncpkgs, alpm_pkg_get_name(spkg)); + if(sync) { + /* found it -- just append to the replaces list */ + sync->data = alpm_list_add(sync->data, dummy); + } else { + /* none found -- enter pkg into the final sync list */ + sync = _alpm_sync_new(PM_SYNC_TYPE_REPLACE, spkg, NULL); + if(sync == NULL) { + _alpm_pkg_free(dummy); pm_errno = PM_ERR_MEMORY; - goto error; + _alpm_synclist_free(syncpkgs); + return(NULL); } - dummy->requiredby = alpm_list_strdup(alpm_pkg_get_requiredby(lpkg)); - /* check if spkg->name is already in the packages list. */ - sync = _alpm_sync_find(trans->packages, alpm_pkg_get_name(spkg)); - if(sync) { - /* found it -- just append to the replaces list */ - sync->data = alpm_list_add(sync->data, dummy); - } else { - /* none found -- enter pkg into the final sync list */ - sync = _alpm_sync_new(PM_SYNC_TYPE_REPLACE, spkg, NULL); - if(sync == NULL) { - _alpm_pkg_free(dummy); - pm_errno = PM_ERR_MEMORY; - goto error; - } - sync->data = alpm_list_add(NULL, dummy); - trans->packages = alpm_list_add(trans->packages, sync); - } - _alpm_log(PM_LOG_DEBUG, "%s-%s elected for upgrade (to be replaced by %s-%s)", - alpm_pkg_get_name(lpkg), alpm_pkg_get_version(lpkg), - alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); + sync->data = alpm_list_add(NULL, dummy); + syncpkgs = alpm_list_add(syncpkgs, sync); } + _alpm_log(PM_LOG_DEBUG, "%s-%s elected for upgrade (to be replaced by %s-%s)", + alpm_pkg_get_name(lpkg), alpm_pkg_get_version(lpkg), + alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); } } } } - return(0); -error: - return(-1); + return(syncpkgs); } -/* TODO reimplement this in terms of alpm_get_upgrades */ -int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync) +/** Get a list of upgradable packages on the current system + * @return a pmsyncpkg_t list of packages that are out of date + */ +alpm_list_t SYMEXPORT *alpm_sync_sysupgrade(pmtrans_t *trans, + pmdb_t *db_local, alpm_list_t *dbs_sync) { + alpm_list_t *syncpkgs = NULL; alpm_list_t *i, *j; ALPM_LOG_FUNC; /* check for "recommended" package replacements */ - if(find_replacements(trans, db_local, dbs_sync) == 0) { - /* match installed packages with the sync dbs and compare versions */ - _alpm_log(PM_LOG_DEBUG, "checking for package upgrades"); - for(i = _alpm_db_get_pkgcache(db_local); i; i = i->next) { - int replace=0; - pmpkg_t *local = i->data; - pmpkg_t *spkg = NULL; - pmsyncpkg_t *sync; - - for(j = dbs_sync; !spkg && j; j = j->next) { - spkg = _alpm_db_get_pkgfromcache(j->data, alpm_pkg_get_name(local)); - } - if(spkg == NULL) { - _alpm_log(PM_LOG_DEBUG, "'%s' not found in sync db -- skipping", - alpm_pkg_get_name(local)); - continue; - } + syncpkgs = _alpm_find_replacements(trans, db_local, dbs_sync); + + /* match installed packages with the sync dbs and compare versions */ + _alpm_log(PM_LOG_DEBUG, "checking for package upgrades"); + for(i = _alpm_db_get_pkgcache(db_local); i; i = i->next) { + int replace=0; + pmpkg_t *local = i->data; + pmpkg_t *spkg = NULL; + pmsyncpkg_t *sync; + + for(j = dbs_sync; !spkg && j; j = j->next) { + spkg = _alpm_db_get_pkgfromcache(j->data, alpm_pkg_get_name(local)); + } + if(spkg == NULL) { + _alpm_log(PM_LOG_DEBUG, "'%s' not found in sync db -- skipping", + alpm_pkg_get_name(local)); + continue; + } - /* we don't care about a to-be-replaced package's newer version */ - for(j = trans->packages; j && !replace; j=j->next) { - sync = j->data; - if(sync->type == PM_SYNC_TYPE_REPLACE) { - if(_alpm_pkg_find(alpm_pkg_get_name(spkg), sync->data)) { - replace=1; - } + /* we don't care about a to-be-replaced package's newer version */ + for(j = syncpkgs; j && !replace; j=j->next) { + sync = j->data; + if(sync->type == PM_SYNC_TYPE_REPLACE) { + if(_alpm_pkg_find(alpm_pkg_get_name(spkg), sync->data)) { + replace=1; } } - if(replace) { - _alpm_log(PM_LOG_DEBUG, "'%s' is already elected for removal -- skipping", - alpm_pkg_get_name(local)); - continue; - } + } + if(replace) { + _alpm_log(PM_LOG_DEBUG, "'%s' is already elected for removal -- skipping", + alpm_pkg_get_name(local)); + continue; + } - /* compare versions and see if we need to upgrade */ - if(alpm_pkg_compare_versions(local, spkg)) { - _alpm_log(PM_LOG_DEBUG, "%s-%s elected for upgrade (%s => %s)", - alpm_pkg_get_name(local), alpm_pkg_get_version(local), - alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); - if(!_alpm_sync_find(trans->packages, alpm_pkg_get_name(spkg))) { - /* If package is in the ignorepkg list, ask before we add it to - * the transaction */ - if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(local))) { - int resp = 0; - QUESTION(trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, local, NULL, NULL, &resp); - if(!resp) { - continue; - } - } - pmpkg_t *tmp = _alpm_pkg_dup(local); - if(tmp == NULL) { - goto error; - } - sync = _alpm_sync_new(PM_SYNC_TYPE_UPGRADE, spkg, tmp); - if(sync == NULL) { - _alpm_pkg_free(tmp); - goto error; - } - trans->packages = alpm_list_add(trans->packages, sync); + /* compare versions and see if we need to upgrade */ + if(alpm_pkg_compare_versions(local, spkg)) { + _alpm_log(PM_LOG_DEBUG, "%s-%s elected for upgrade (%s => %s)", + alpm_pkg_get_name(local), alpm_pkg_get_version(local), + alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); + if(!_alpm_sync_find(syncpkgs, alpm_pkg_get_name(spkg))) { + /* If package is in the ignorepkg list, skip it */ + if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(local))) { + _alpm_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (%s)"), + alpm_pkg_get_name(local), alpm_pkg_get_version(local), + alpm_pkg_get_version(spkg)); + continue; + } + + pmpkg_t *tmp = _alpm_pkg_dup(local); + if(tmp == NULL) { + _alpm_synclist_free(syncpkgs); + return(NULL); + } + sync = _alpm_sync_new(PM_SYNC_TYPE_UPGRADE, spkg, tmp); + if(sync == NULL) { + _alpm_pkg_free(tmp); + _alpm_synclist_free(syncpkgs); + return(NULL); } + syncpkgs = alpm_list_add(syncpkgs, sync); } } + } - return(0); + if(trans) { + trans->packages = syncpkgs; } -error: - /* if we're here, it's an error */ - return(-1); + + return(syncpkgs); } int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, char *name) diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h index ef094b5..0d91d25 100644 --- a/lib/libalpm/sync.h +++ b/lib/libalpm/sync.h @@ -35,7 +35,6 @@ struct __pmsyncpkg_t { pmsyncpkg_t *_alpm_sync_new(int type, pmpkg_t *spkg, void *data); void _alpm_sync_free(pmsyncpkg_t *data); -int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync); int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, char *name); int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, alpm_list_t **data); int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data); diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c index 5382014..c0d4b3d 100644 --- a/lib/libalpm/trans.c +++ b/lib/libalpm/trans.c @@ -292,7 +292,8 @@ int _alpm_trans_sysupgrade(pmtrans_t *trans) /* Sanity checks */ ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1)); - return(_alpm_sync_sysupgrade(trans, handle->db_local, handle->dbs_sync)); + alpm_sync_sysupgrade(trans, handle->db_local, handle->dbs_sync); + return(0); } /** Add a target to the transaction. diff --git a/src/pacman/query.c b/src/pacman/query.c index 8ef47e6..7849e84 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -239,7 +239,9 @@ static int query_upgrades(void) printf(_("Checking for package upgrades... \n")); alpm_list_t *syncpkgs; - if((syncpkgs = alpm_db_get_upgrades()) != NULL) { + alpm_list_t *syncdbs = alpm_option_get_syncdbs(); + if((syncpkgs = alpm_sync_sysupgrade(NULL, + db_local, syncdbs)) != NULL) { display_targets(syncpkgs); return(0); } -- 1.5.2.5
From ddbfb04293e28738d859da53ad09192889afbb6d Mon Sep 17 00:00:00 2001 From: Chantry Xavier <shiningxc@gmail.com> Date: Sat, 25 Aug 2007 00:10:40 +0200 Subject: [PATCH] Remove duplicated get_upgrades function, use sysupgrade instead.
The alpm_get_upgrades was exactly the same as _alpm_sync_sysupgrade, except that it didn't ask for confirmation. There are two kind of questions asked : %s is in IgnorePkg. Install anyway? [Y/n] Replace %s with %s/%s? [Y/n]
The first question was actually never asked, because alpm_pkg_compare_versions already ignored the packages in IgnorePkg. I removed the IgnorePkg handling from alpm_pkg_compare_versions, but kept the same behavior with _alpm_sync_sysupgrade, that is ignore packages automatically, without confirmation.
The replace question is asked in _alpm_find_replacements. This question can be skipped by using a NULL trans argument, so that we get the same behavior as with alpm_get_upgrades.
alpm_db_get_upgrades() can now be replaced by : alpm_sync_sysupgrade(NULL, db_local, syncdbs).
Signed-off-by: Chantry Xavier <shiningxc@gmail.com> --- diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index 8aabcdb..edb406f 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -90,13 +90,27 @@ void _alpm_sync_free(pmsyncpkg_t *sync) FREE(sync); }
+void _alpm_synclist_free(alpm_list_t *syncpkgs) Can't this be static, and thus not have the _alpm prefix? (static = only use is in this file, _alpm = only use is internal to the
On 8/24/07, Xavier <shiningxc@gmail.com> wrote: library).
+{ + if(syncpkgs) { + alpm_list_t *tmp; + for(tmp = syncpkgs; tmp; tmp = alpm_list_next(tmp)) { + if(tmp->data) { + _alpm_sync_free(tmp->data); + } + } + alpm_list_free(syncpkgs); + } + +} + /* Find recommended replacements for packages during a sync. - * (refactored from _alpm_sync_prepare) */ -static int find_replacements(pmtrans_t *trans, pmdb_t *db_local, +static alpm_list_t *_alpm_find_replacements(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync) { alpm_list_t *i, *j, *k; /* wow */ + alpm_list_t *syncpkgs = NULL;
ALPM_LOG_FUNC;
@@ -127,124 +141,133 @@ static int find_replacements(pmtrans_t *trans, pmdb_t *db_local, alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); } else { /* get confirmation for the replacement */ - int doreplace = 0; - QUESTION(trans, PM_TRANS_CONV_REPLACE_PKG, lpkg, spkg, db->treename, &doreplace); + if(trans) { + int doreplace = 0; + QUESTION(trans, PM_TRANS_CONV_REPLACE_PKG, lpkg, spkg, db->treename, &doreplace); + if(!doreplace) { + continue; + } + }
- if(doreplace) { - /* if confirmed, add this to the 'final' list, designating 'lpkg' as - * the package to replace. - */ - pmsyncpkg_t *sync; - pmpkg_t *dummy = _alpm_pkg_new(alpm_pkg_get_name(lpkg), NULL); - if(dummy == NULL) { + /* if confirmed, add this to the 'final' list, designating 'lpkg' as + * the package to replace. + */ + pmsyncpkg_t *sync; + pmpkg_t *dummy = _alpm_pkg_new(alpm_pkg_get_name(lpkg), NULL); + if(dummy == NULL) { + pm_errno = PM_ERR_MEMORY; + _alpm_synclist_free(syncpkgs); + return(NULL); + } + dummy->requiredby = alpm_list_strdup(alpm_pkg_get_requiredby(lpkg)); + /* check if spkg->name is already in the packages list. */ + sync = _alpm_sync_find(syncpkgs, alpm_pkg_get_name(spkg)); + if(sync) { + /* found it -- just append to the replaces list */ + sync->data = alpm_list_add(sync->data, dummy); + } else { + /* none found -- enter pkg into the final sync list */ + sync = _alpm_sync_new(PM_SYNC_TYPE_REPLACE, spkg, NULL); + if(sync == NULL) { + _alpm_pkg_free(dummy); pm_errno = PM_ERR_MEMORY; - goto error; + _alpm_synclist_free(syncpkgs); + return(NULL); } - dummy->requiredby = alpm_list_strdup(alpm_pkg_get_requiredby(lpkg)); - /* check if spkg->name is already in the packages list. */ - sync = _alpm_sync_find(trans->packages, alpm_pkg_get_name(spkg)); - if(sync) { - /* found it -- just append to the replaces list */ - sync->data = alpm_list_add(sync->data, dummy); - } else { - /* none found -- enter pkg into the final sync list */ - sync = _alpm_sync_new(PM_SYNC_TYPE_REPLACE, spkg, NULL); - if(sync == NULL) { - _alpm_pkg_free(dummy); - pm_errno = PM_ERR_MEMORY; - goto error; - } - sync->data = alpm_list_add(NULL, dummy); - trans->packages = alpm_list_add(trans->packages, sync); - } - _alpm_log(PM_LOG_DEBUG, "%s-%s elected for upgrade (to be replaced by %s-%s)", - alpm_pkg_get_name(lpkg), alpm_pkg_get_version(lpkg), - alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); + sync->data = alpm_list_add(NULL, dummy); + syncpkgs = alpm_list_add(syncpkgs, sync); } + _alpm_log(PM_LOG_DEBUG, "%s-%s elected for upgrade (to be replaced by %s-%s)", + alpm_pkg_get_name(lpkg), alpm_pkg_get_version(lpkg), + alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); } } } } - return(0); -error: - return(-1); + return(syncpkgs); }
-/* TODO reimplement this in terms of alpm_get_upgrades */ -int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync) +/** Get a list of upgradable packages on the current system + * @return a pmsyncpkg_t list of packages that are out of date + */ +alpm_list_t SYMEXPORT *alpm_sync_sysupgrade(pmtrans_t *trans, + pmdb_t *db_local, alpm_list_t *dbs_sync) I don't know why, but I seem reluctant to change the return type here, unless we can no longer really error in this function.
{ + alpm_list_t *syncpkgs = NULL; alpm_list_t *i, *j;
ALPM_LOG_FUNC;
/* check for "recommended" package replacements */ - if(find_replacements(trans, db_local, dbs_sync) == 0) { - /* match installed packages with the sync dbs and compare versions */ - _alpm_log(PM_LOG_DEBUG, "checking for package upgrades"); - for(i = _alpm_db_get_pkgcache(db_local); i; i = i->next) { - int replace=0; - pmpkg_t *local = i->data; - pmpkg_t *spkg = NULL; - pmsyncpkg_t *sync; - - for(j = dbs_sync; !spkg && j; j = j->next) { - spkg = _alpm_db_get_pkgfromcache(j->data, alpm_pkg_get_name(local)); - } - if(spkg == NULL) { - _alpm_log(PM_LOG_DEBUG, "'%s' not found in sync db -- skipping", - alpm_pkg_get_name(local)); - continue; - } + syncpkgs = _alpm_find_replacements(trans, db_local, dbs_sync); Same here- can _alpm_find_replacements never fail anymore?
+ + /* match installed packages with the sync dbs and compare versions */ + _alpm_log(PM_LOG_DEBUG, "checking for package upgrades"); + for(i = _alpm_db_get_pkgcache(db_local); i; i = i->next) { + int replace=0; + pmpkg_t *local = i->data; + pmpkg_t *spkg = NULL; + pmsyncpkg_t *sync; + + for(j = dbs_sync; !spkg && j; j = j->next) { + spkg = _alpm_db_get_pkgfromcache(j->data, alpm_pkg_get_name(local)); + } + if(spkg == NULL) { + _alpm_log(PM_LOG_DEBUG, "'%s' not found in sync db -- skipping", + alpm_pkg_get_name(local)); + continue; + }
- /* we don't care about a to-be-replaced package's newer version */ - for(j = trans->packages; j && !replace; j=j->next) { - sync = j->data; - if(sync->type == PM_SYNC_TYPE_REPLACE) { - if(_alpm_pkg_find(alpm_pkg_get_name(spkg), sync->data)) { - replace=1; - } + /* we don't care about a to-be-replaced package's newer version */ + for(j = syncpkgs; j && !replace; j=j->next) { + sync = j->data; + if(sync->type == PM_SYNC_TYPE_REPLACE) { + if(_alpm_pkg_find(alpm_pkg_get_name(spkg), sync->data)) { + replace=1; } } - if(replace) { - _alpm_log(PM_LOG_DEBUG, "'%s' is already elected for removal -- skipping", - alpm_pkg_get_name(local)); - continue; - } + } + if(replace) { + _alpm_log(PM_LOG_DEBUG, "'%s' is already elected for removal -- skipping", + alpm_pkg_get_name(local)); + continue; + }
- /* compare versions and see if we need to upgrade */ - if(alpm_pkg_compare_versions(local, spkg)) { - _alpm_log(PM_LOG_DEBUG, "%s-%s elected for upgrade (%s => %s)", - alpm_pkg_get_name(local), alpm_pkg_get_version(local), - alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); - if(!_alpm_sync_find(trans->packages, alpm_pkg_get_name(spkg))) { - /* If package is in the ignorepkg list, ask before we add it to - * the transaction */ - if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(local))) { - int resp = 0; - QUESTION(trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, local, NULL, NULL, &resp); - if(!resp) { - continue; - } - } - pmpkg_t *tmp = _alpm_pkg_dup(local); - if(tmp == NULL) { - goto error; - } - sync = _alpm_sync_new(PM_SYNC_TYPE_UPGRADE, spkg, tmp); - if(sync == NULL) { - _alpm_pkg_free(tmp); - goto error; - } - trans->packages = alpm_list_add(trans->packages, sync); + /* compare versions and see if we need to upgrade */ + if(alpm_pkg_compare_versions(local, spkg)) { + _alpm_log(PM_LOG_DEBUG, "%s-%s elected for upgrade (%s => %s)", + alpm_pkg_get_name(local), alpm_pkg_get_version(local), + alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); + if(!_alpm_sync_find(syncpkgs, alpm_pkg_get_name(spkg))) { + /* If package is in the ignorepkg list, skip it */ + if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(local))) { + _alpm_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (%s)"), + alpm_pkg_get_name(local), alpm_pkg_get_version(local), + alpm_pkg_get_version(spkg)); + continue; + } + + pmpkg_t *tmp = _alpm_pkg_dup(local); + if(tmp == NULL) { + _alpm_synclist_free(syncpkgs); + return(NULL); + } + sync = _alpm_sync_new(PM_SYNC_TYPE_UPGRADE, spkg, tmp); + if(sync == NULL) { + _alpm_pkg_free(tmp); + _alpm_synclist_free(syncpkgs); + return(NULL); } + syncpkgs = alpm_list_add(syncpkgs, sync); } } + }
- return(0); + if(trans) { + trans->packages = syncpkgs; } -error: - /* if we're here, it's an error */ - return(-1); + + return(syncpkgs); }
int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, char *name) diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h index ef094b5..0d91d25 100644 --- a/lib/libalpm/sync.h +++ b/lib/libalpm/sync.h @@ -35,7 +35,6 @@ struct __pmsyncpkg_t { pmsyncpkg_t *_alpm_sync_new(int type, pmpkg_t *spkg, void *data); void _alpm_sync_free(pmsyncpkg_t *data);
-int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync); Not sure why we should move something that is sync specific out of the sync header.
int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, char *name); int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, alpm_list_t **data); int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data); diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c index 5382014..c0d4b3d 100644 --- a/lib/libalpm/trans.c +++ b/lib/libalpm/trans.c @@ -292,7 +292,8 @@ int _alpm_trans_sysupgrade(pmtrans_t *trans) /* Sanity checks */ ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
- return(_alpm_sync_sysupgrade(trans, handle->db_local, handle->dbs_sync)); + alpm_sync_sysupgrade(trans, handle->db_local, handle->dbs_sync); + return(0); }
/** Add a target to the transaction. diff --git a/src/pacman/query.c b/src/pacman/query.c index 8ef47e6..7849e84 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -239,7 +239,9 @@ static int query_upgrades(void) printf(_("Checking for package upgrades... \n")); alpm_list_t *syncpkgs;
- if((syncpkgs = alpm_db_get_upgrades()) != NULL) { + alpm_list_t *syncdbs = alpm_option_get_syncdbs(); + if((syncpkgs = alpm_sync_sysupgrade(NULL, + db_local, syncdbs)) != NULL) { You know I don't like fun syntax like this. :) Break it into two lines for clarity. Obviously it was already like it before, but this will clean it up for the future. foo = (alpm_sync_sysupgrade(); if(foo) { ...
display_targets(syncpkgs); return(0); } -- 1.5.2.5
_______________________________________________ pacman-dev mailing list pacman-dev@archlinux.org http://archlinux.org/mailman/listinfo/pacman-dev
On Mon, Aug 27, 2007 at 09:55:02AM -0400, Dan McGee wrote:
Can't this be static, and thus not have the _alpm prefix? (static = only use is in this file, _alpm = only use is internal to the library).
Ah right, I wasn't 100% sure about that :)
-/* TODO reimplement this in terms of alpm_get_upgrades */ -int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync) +/** Get a list of upgradable packages on the current system + * @return a pmsyncpkg_t list of packages that are out of date + */ +alpm_list_t SYMEXPORT *alpm_sync_sysupgrade(pmtrans_t *trans, + pmdb_t *db_local, alpm_list_t *dbs_sync) I don't know why, but I seem reluctant to change the return type here, unless we can no longer really error in this function.
Should I add an extra argument for the return list then, to both sysupgrade and find_replacements ? An alpm_list_t **list ?
+ syncpkgs = _alpm_find_replacements(trans, db_local, dbs_sync); Same here- can _alpm_find_replacements never fail anymore?
Indeed, I thought about this problem. See my question above :)
diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h index ef094b5..0d91d25 100644 --- a/lib/libalpm/sync.h +++ b/lib/libalpm/sync.h @@ -35,7 +35,6 @@ struct __pmsyncpkg_t { pmsyncpkg_t *_alpm_sync_new(int type, pmpkg_t *spkg, void *data); void _alpm_sync_free(pmsyncpkg_t *data);
-int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync); Not sure why we should move something that is sync specific out of the sync header.
I thought public functions should be in alpm.h , and private functions in other headers. Maybe I should keep _alpm_sync_sysupgrade private then, and add a public wrapper as alpm_sync_sysupgrade ?
On 8/27/07, Xavier <shiningxc@gmail.com> wrote:
-/* TODO reimplement this in terms of alpm_get_upgrades */ -int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync) +/** Get a list of upgradable packages on the current system + * @return a pmsyncpkg_t list of packages that are out of date + */ +alpm_list_t SYMEXPORT *alpm_sync_sysupgrade(pmtrans_t *trans, + pmdb_t *db_local, alpm_list_t *dbs_sync) I don't know why, but I seem reluctant to change the return type here, unless we can no longer really error in this function.
Should I add an extra argument for the return list then, to both sysupgrade and find_replacements ? An alpm_list_t **list ?
+ syncpkgs = _alpm_find_replacements(trans, db_local, dbs_sync); Same here- can _alpm_find_replacements never fail anymore?
Indeed, I thought about this problem. See my question above :)
That might be the best solution, and then ensure you set the error value as necessary. Of course, if an error can be specified well enough by simply having a NULL return instead of syncpkgs being set, then I guess there isn't too much of a problem there. Basically I'm indecisive.
diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h index ef094b5..0d91d25 100644 --- a/lib/libalpm/sync.h +++ b/lib/libalpm/sync.h @@ -35,7 +35,6 @@ struct __pmsyncpkg_t { pmsyncpkg_t *_alpm_sync_new(int type, pmpkg_t *spkg, void *data); void _alpm_sync_free(pmsyncpkg_t *data);
-int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync); Not sure why we should move something that is sync specific out of the sync header.
I thought public functions should be in alpm.h , and private functions in other headers. Maybe I should keep _alpm_sync_sysupgrade private then, and add a public wrapper as alpm_sync_sysupgrade ?
Well actually ignore my original comment. Now I see it is trans.c that has always been weird with its alpm_trans_sysupgrade function. Perhaps that should change (probably post-3.1). A wrapper function might be best for now, and that way we don't have to deal with the NULL trans argument (just leave that out of the wrapper). -Dan
On Mon, Aug 27, 2007 at 10:20:13AM -0400, Dan McGee wrote:
On 8/27/07, Xavier <shiningxc@gmail.com> wrote:
That might be the best solution, and then ensure you set the error value as necessary. Of course, if an error can be specified well enough by simply having a NULL return instead of syncpkgs being set, then I guess there isn't too much of a problem there. Basically I'm indecisive.
I don't think we can make the distinction between an empty list of packages (ie no upgrade), and an error, so I'll go with the **list argument :)
Well actually ignore my original comment. Now I see it is trans.c that has always been weird with its alpm_trans_sysupgrade function. Perhaps that should change (probably post-3.1).
A wrapper function might be best for now, and that way we don't have to deal with the NULL trans argument (just leave that out of the wrapper).
Ok, sounds good.
On Mon, Aug 27, 2007 at 04:30:49PM +0200, Xavier wrote: Here is an updated patch, with all the suggestions :
From 135d7facdd491d314960ba45a4c393dadebdd522 Mon Sep 17 00:00:00 2001 From: Chantry Xavier <shiningxc@gmail.com> Date: Sat, 25 Aug 2007 00:10:40 +0200 Subject: [PATCH] Remove duplicated get_upgrades function, use sysupgrade instead.
The alpm_get_upgrades was exactly the same as _alpm_sync_sysupgrade, except that it didn't ask for confirmation. There are two kind of questions asked : %s is in IgnorePkg. Install anyway? [Y/n] Replace %s with %s/%s? [Y/n] The first question was actually never asked, because alpm_pkg_compare_versions already ignored the packages in IgnorePkg. I removed the IgnorePkg handling from alpm_pkg_compare_versions, but kept the same behavior with _alpm_sync_sysupgrade, that is ignore packages automatically, without confirmation. The replace question is asked in find_replacements. This question can be skipped by using a NULL trans argument, so that we get the same behavior as with alpm_get_upgrades. alpm_db_get_upgrades() can now be replaced by : alpm_sync_sysupgrade(db_local, syncdbs). Signed-off-by: Chantry Xavier <shiningxc@gmail.com> --- lib/libalpm/alpm.h | 4 +- lib/libalpm/db.c | 141 ------------------------------- lib/libalpm/package.c | 10 -- lib/libalpm/sync.c | 225 ++++++++++++++++++++++++++++--------------------- lib/libalpm/sync.h | 4 +- lib/libalpm/trans.c | 3 +- src/pacman/query.c | 8 ++- 7 files changed, 143 insertions(+), 252 deletions(-) diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h index 844d9bf..54bc44c 100644 --- a/lib/libalpm/alpm.h +++ b/lib/libalpm/alpm.h @@ -163,8 +163,6 @@ alpm_list_t *alpm_db_getgrpcache(pmdb_t *db); alpm_list_t *alpm_db_test(pmdb_t *db); alpm_list_t *alpm_db_search(pmdb_t *db, const alpm_list_t* needles); -alpm_list_t *alpm_db_get_upgrades(void); - /* * Packages */ @@ -237,6 +235,8 @@ typedef enum _pmsynctype_t { pmsynctype_t alpm_sync_get_type(const pmsyncpkg_t *sync); pmpkg_t *alpm_sync_get_pkg(const pmsyncpkg_t *sync); void *alpm_sync_get_data(const pmsyncpkg_t *sync); +int alpm_sync_sysupgrade(pmdb_t *db_local, + alpm_list_t *dbs_sync, alpm_list_t **syncpkgs); /* * Transactions diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c index e79aad8..90c5f0b 100644 --- a/lib/libalpm/db.c +++ b/lib/libalpm/db.c @@ -46,8 +46,6 @@ #include "cache.h" #include "alpm.h" -#include "sync.h" /* alpm_db_get_upgrades() */ - /** \addtogroup alpm_databases Database Functions * @brief Functions to query and manipulate the database of libalpm * @{ @@ -440,145 +438,6 @@ alpm_list_t SYMEXPORT *alpm_db_search(pmdb_t *db, const alpm_list_t* needles) return(_alpm_db_search(db, needles)); } -/* This function is mostly the same as sync.c find_replacements and sysupgrade - * functions, and we should be able to combine them - this is an interim - * solution made for -Qu operation */ -/** Get a list of upgradable packages on the current system - * @return a pmsyncpkg_t list of packages that are out of date - */ -alpm_list_t SYMEXPORT *alpm_db_get_upgrades(void) -{ - alpm_list_t *syncpkgs = NULL; - const alpm_list_t *i, *j, *k, *m; - - ALPM_LOG_FUNC; - - /* TODO holy nested loops, Batman! */ - /* check for "recommended" package replacements */ - _alpm_log(PM_LOG_DEBUG, "checking for package replacements\n"); - for(i = handle->dbs_sync; i; i = i->next) { - for(j = _alpm_db_get_pkgcache(i->data); j; j = j->next) { - pmpkg_t *spkg = j->data; - - for(k = alpm_pkg_get_replaces(spkg); k; k = k->next) { - - for(m = _alpm_db_get_pkgcache(handle->db_local); m; m = m->next) { - pmpkg_t *lpkg = m->data; - - if(strcmp(k->data, alpm_pkg_get_name(lpkg)) == 0) { - _alpm_log(PM_LOG_DEBUG, "checking replacement '%s' for package '%s'\n", - k->data, alpm_pkg_get_name(spkg)); - if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(lpkg))) { - _alpm_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (to be replaced by %s-%s)\n"), - alpm_pkg_get_name(lpkg), alpm_pkg_get_version(lpkg), - alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); - } else { - /* assume all replaces=() packages are accepted */ - pmsyncpkg_t *sync = NULL; - pmpkg_t *dummy = _alpm_pkg_new(alpm_pkg_get_name(lpkg), NULL); - if(dummy == NULL) { - pm_errno = PM_ERR_MEMORY; - goto error; - } - dummy->requiredby = alpm_list_strdup(alpm_pkg_get_requiredby(lpkg)); - - pmsyncpkg_t *syncpkg; - syncpkg = _alpm_sync_find(syncpkgs, alpm_pkg_get_name(spkg)); - - if(syncpkg) { - /* found it -- just append to the replaces list */ - sync->data = alpm_list_add(sync->data, dummy); - } else { - /* none found -- enter pkg into the final sync list */ - sync = _alpm_sync_new(PM_SYNC_TYPE_REPLACE, spkg, NULL); - if(sync == NULL) { - _alpm_pkg_free(dummy); - pm_errno = PM_ERR_MEMORY; - goto error; - } - sync->data = alpm_list_add(NULL, dummy); - syncpkgs = alpm_list_add(syncpkgs, sync); - } - _alpm_log(PM_LOG_DEBUG, "%s-%s elected for upgrade (to be replaced by %s-%s)\n", - alpm_pkg_get_name(lpkg), alpm_pkg_get_version(lpkg), - alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); - } - break; - } - } - } - } - } - - /* now do normal upgrades */ - for(i = _alpm_db_get_pkgcache(handle->db_local); i; i = i->next) { - int replace=0; - pmpkg_t *local = i->data; - pmpkg_t *spkg = NULL; - pmsyncpkg_t *sync; - - for(j = handle->dbs_sync; !spkg && j; j = j->next) { - spkg = _alpm_db_get_pkgfromcache(j->data, alpm_pkg_get_name(local)); - } - if(spkg == NULL) { - _alpm_log(PM_LOG_DEBUG, "'%s' not found in sync db -- skipping\n", - alpm_pkg_get_name(local)); - continue; - } - - /* we don't care about a to-be-replaced package's newer version */ - for(j = syncpkgs; j && !replace; j=j->next) { - sync = j->data; - if(sync->type == PM_SYNC_TYPE_REPLACE) { - if(_alpm_pkg_find(alpm_pkg_get_name(spkg), sync->data)) { - replace=1; - } - } - } - if(replace) { - _alpm_log(PM_LOG_DEBUG, "'%s' is already elected for removal -- skipping\n", - alpm_pkg_get_name(local)); - continue; - } - - if(alpm_pkg_compare_versions(local, spkg)) { - _alpm_log(PM_LOG_DEBUG, "%s elected for upgrade (%s => %s)\n", - alpm_pkg_get_name(local), alpm_pkg_get_version(local), - alpm_pkg_get_version(spkg)); - - pmsyncpkg_t *syncpkg; - syncpkg = _alpm_sync_find(syncpkgs, alpm_pkg_get_name(local)); - - if(!syncpkg) { - pmpkg_t *dummy = _alpm_pkg_new(alpm_pkg_get_name(local), - alpm_pkg_get_version(local)); - if(dummy == NULL) { - goto error; - } - sync = _alpm_sync_new(PM_SYNC_TYPE_UPGRADE, spkg, dummy); - if(sync == NULL) { - _alpm_pkg_free(dummy); - goto error; - } - syncpkgs = alpm_list_add(syncpkgs, sync); - } - } - } - - return(syncpkgs); -error: - if(syncpkgs) { - alpm_list_t *tmp; - for(tmp = syncpkgs; tmp; tmp = alpm_list_next(tmp)) { - if(tmp->data) { - _alpm_sync_free(tmp->data); - } - } - alpm_list_free(syncpkgs); - } - return(NULL); -} - /** @} */ pmdb_t *_alpm_db_new(const char *dbpath, const char *treename) diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index e171d69..395504d 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -727,16 +727,6 @@ int alpm_pkg_compare_versions(pmpkg_t *local_pkg, pmpkg_t *pkg) /* compare versions and see if we need to upgrade */ cmp = _alpm_versioncmp(alpm_pkg_get_version(pkg), alpm_pkg_get_version(local_pkg)); - if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(pkg))) { - /* package should be ignored (IgnorePkg) */ - if(cmp > 0) { - _alpm_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (%s)\n"), - alpm_pkg_get_name(local_pkg), alpm_pkg_get_version(local_pkg), - alpm_pkg_get_version(pkg)); - } - return(0); - } - if(cmp != 0 && pkg->force) { cmp = 1; _alpm_log(PM_LOG_WARNING, _("%s: forcing upgrade to version %s\n"), diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c index f21f7d3..9ca29d6 100644 --- a/lib/libalpm/sync.c +++ b/lib/libalpm/sync.c @@ -90,16 +90,33 @@ void _alpm_sync_free(pmsyncpkg_t *sync) FREE(sync); } +static void synclist_free(alpm_list_t *syncpkgs) +{ + if(syncpkgs) { + alpm_list_t *tmp; + for(tmp = syncpkgs; tmp; tmp = alpm_list_next(tmp)) { + if(tmp->data) { + _alpm_sync_free(tmp->data); + } + } + alpm_list_free(syncpkgs); + } + +} + /* Find recommended replacements for packages during a sync. - * (refactored from _alpm_sync_prepare) */ static int find_replacements(pmtrans_t *trans, pmdb_t *db_local, - alpm_list_t *dbs_sync) + alpm_list_t *dbs_sync, alpm_list_t **syncpkgs) { alpm_list_t *i, *j, *k; /* wow */ ALPM_LOG_FUNC; + if(syncpkgs == NULL) { + return(-1); + } + /* check for "recommended" package replacements */ _alpm_log(PM_LOG_DEBUG, "checking for package replacements\n"); for(i = dbs_sync; i; i = i->next) { @@ -127,124 +144,142 @@ static int find_replacements(pmtrans_t *trans, pmdb_t *db_local, alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); } else { /* get confirmation for the replacement */ - int doreplace = 0; - QUESTION(trans, PM_TRANS_CONV_REPLACE_PKG, lpkg, spkg, db->treename, &doreplace); + if(trans) { + int doreplace = 0; + QUESTION(trans, PM_TRANS_CONV_REPLACE_PKG, lpkg, spkg, db->treename, &doreplace); + if(!doreplace) { + continue; + } + } - if(doreplace) { - /* if confirmed, add this to the 'final' list, designating 'lpkg' as - * the package to replace. - */ - pmsyncpkg_t *sync; - pmpkg_t *dummy = _alpm_pkg_new(alpm_pkg_get_name(lpkg), NULL); - if(dummy == NULL) { + /* if confirmed, add this to the 'final' list, designating 'lpkg' as + * the package to replace. + */ + pmsyncpkg_t *sync; + pmpkg_t *dummy = _alpm_pkg_new(alpm_pkg_get_name(lpkg), NULL); + if(dummy == NULL) { + pm_errno = PM_ERR_MEMORY; + synclist_free(*syncpkgs); + return(-1); + } + dummy->requiredby = alpm_list_strdup(alpm_pkg_get_requiredby(lpkg)); + /* check if spkg->name is already in the packages list. */ + sync = _alpm_sync_find(*syncpkgs, alpm_pkg_get_name(spkg)); + if(sync) { + /* found it -- just append to the replaces list */ + sync->data = alpm_list_add(sync->data, dummy); + } else { + /* none found -- enter pkg into the final sync list */ + sync = _alpm_sync_new(PM_SYNC_TYPE_REPLACE, spkg, NULL); + if(sync == NULL) { + _alpm_pkg_free(dummy); pm_errno = PM_ERR_MEMORY; - goto error; + synclist_free(*syncpkgs); + return(-1); } - dummy->requiredby = alpm_list_strdup(alpm_pkg_get_requiredby(lpkg)); - /* check if spkg->name is already in the packages list. */ - sync = _alpm_sync_find(trans->packages, alpm_pkg_get_name(spkg)); - if(sync) { - /* found it -- just append to the replaces list */ - sync->data = alpm_list_add(sync->data, dummy); - } else { - /* none found -- enter pkg into the final sync list */ - sync = _alpm_sync_new(PM_SYNC_TYPE_REPLACE, spkg, NULL); - if(sync == NULL) { - _alpm_pkg_free(dummy); - pm_errno = PM_ERR_MEMORY; - goto error; - } - sync->data = alpm_list_add(NULL, dummy); - trans->packages = alpm_list_add(trans->packages, sync); - } - _alpm_log(PM_LOG_DEBUG, "%s-%s elected for upgrade (to be replaced by %s-%s)\n", - alpm_pkg_get_name(lpkg), alpm_pkg_get_version(lpkg), - alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); + sync->data = alpm_list_add(NULL, dummy); + *syncpkgs = alpm_list_add(*syncpkgs, sync); } + _alpm_log(PM_LOG_DEBUG, "%s-%s elected for upgrade (to be replaced by %s-%s)\n", + alpm_pkg_get_name(lpkg), alpm_pkg_get_version(lpkg), + alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); } } } } return(0); -error: - return(-1); } -/* TODO reimplement this in terms of alpm_get_upgrades */ -int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync) +/** Get a list of upgradable packages on the current system + * Adds out of date packages to *list. + * @arg list pointer to a list of pmsyncpkg_t. + */ +int SYMEXPORT alpm_sync_sysupgrade(pmdb_t *db_local, + alpm_list_t *dbs_sync, alpm_list_t **syncpkgs) +{ + return(_alpm_sync_sysupgrade(NULL, db_local, dbs_sync, syncpkgs)); +} + +int _alpm_sync_sysupgrade(pmtrans_t *trans, + pmdb_t *db_local, alpm_list_t *dbs_sync, alpm_list_t **syncpkgs) { alpm_list_t *i, *j; ALPM_LOG_FUNC; + if(syncpkgs == NULL) { + return(-1); + } /* check for "recommended" package replacements */ - if(find_replacements(trans, db_local, dbs_sync) == 0) { - /* match installed packages with the sync dbs and compare versions */ - _alpm_log(PM_LOG_DEBUG, "checking for package upgrades\n"); - for(i = _alpm_db_get_pkgcache(db_local); i; i = i->next) { - int replace=0; - pmpkg_t *local = i->data; - pmpkg_t *spkg = NULL; - pmsyncpkg_t *sync; - - for(j = dbs_sync; !spkg && j; j = j->next) { - spkg = _alpm_db_get_pkgfromcache(j->data, alpm_pkg_get_name(local)); - } - if(spkg == NULL) { - _alpm_log(PM_LOG_DEBUG, "'%s' not found in sync db -- skipping\n", - alpm_pkg_get_name(local)); - continue; - } + if(find_replacements(trans, db_local, dbs_sync, syncpkgs)) { + return(-1); + } - /* we don't care about a to-be-replaced package's newer version */ - for(j = trans->packages; j && !replace; j=j->next) { - sync = j->data; - if(sync->type == PM_SYNC_TYPE_REPLACE) { - if(_alpm_pkg_find(alpm_pkg_get_name(spkg), sync->data)) { - replace=1; - } + /* match installed packages with the sync dbs and compare versions */ + _alpm_log(PM_LOG_DEBUG, "checking for package upgrades\n"); + for(i = _alpm_db_get_pkgcache(db_local); i; i = i->next) { + int replace = 0; + pmpkg_t *local = i->data; + pmpkg_t *spkg = NULL; + pmsyncpkg_t *sync; + + for(j = dbs_sync; !spkg && j; j = j->next) { + spkg = _alpm_db_get_pkgfromcache(j->data, alpm_pkg_get_name(local)); + } + if(spkg == NULL) { + _alpm_log(PM_LOG_DEBUG, "'%s' not found in sync db -- skipping\n", + alpm_pkg_get_name(local)); + continue; + } + + /* we don't care about a to-be-replaced package's newer version */ + for(j = *syncpkgs; j && !replace; j=j->next) { + sync = j->data; + if(sync->type == PM_SYNC_TYPE_REPLACE) { + if(_alpm_pkg_find(alpm_pkg_get_name(spkg), sync->data)) { + replace = 1; } } - if(replace) { - _alpm_log(PM_LOG_DEBUG, "'%s' is already elected for removal -- skipping\n", - alpm_pkg_get_name(local)); - continue; - } + } + if(replace) { + _alpm_log(PM_LOG_DEBUG, "'%s' is already elected for removal -- skipping\n", + alpm_pkg_get_name(local)); + continue; + } - /* compare versions and see if we need to upgrade */ - if(alpm_pkg_compare_versions(local, spkg)) { - _alpm_log(PM_LOG_DEBUG, "%s-%s elected for upgrade (%s => %s)\n", - alpm_pkg_get_name(local), alpm_pkg_get_version(local), - alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); - if(!_alpm_sync_find(trans->packages, alpm_pkg_get_name(spkg))) { - /* If package is in the ignorepkg list, ask before we add it to - * the transaction */ - if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(local))) { - int resp = 0; - QUESTION(trans, PM_TRANS_CONV_INSTALL_IGNOREPKG, local, NULL, NULL, &resp); - if(!resp) { - continue; - } - } - pmpkg_t *tmp = _alpm_pkg_dup(local); - if(tmp == NULL) { - goto error; - } - sync = _alpm_sync_new(PM_SYNC_TYPE_UPGRADE, spkg, tmp); - if(sync == NULL) { - _alpm_pkg_free(tmp); - goto error; - } - trans->packages = alpm_list_add(trans->packages, sync); + /* compare versions and see if we need to upgrade */ + if(alpm_pkg_compare_versions(local, spkg)) { + _alpm_log(PM_LOG_DEBUG, "%s-%s elected for upgrade (%s => %s)\n", + alpm_pkg_get_name(local), alpm_pkg_get_version(local), + alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg)); + if(!_alpm_sync_find(*syncpkgs, alpm_pkg_get_name(spkg))) { + /* If package is in the ignorepkg list, skip it */ + if(alpm_list_find_str(handle->ignorepkg, alpm_pkg_get_name(local))) { + _alpm_log(PM_LOG_WARNING, _("%s-%s: ignoring package upgrade (%s)\n"), + alpm_pkg_get_name(local), alpm_pkg_get_version(local), + alpm_pkg_get_version(spkg)); + continue; + } + + pmpkg_t *tmp = _alpm_pkg_dup(local); + if(tmp == NULL) { + pm_errno = PM_ERR_MEMORY; + synclist_free(*syncpkgs); + return(-1); + } + sync = _alpm_sync_new(PM_SYNC_TYPE_UPGRADE, spkg, tmp); + if(sync == NULL) { + _alpm_pkg_free(tmp); + pm_errno = PM_ERR_MEMORY; + synclist_free(*syncpkgs); + return(-1); } + *syncpkgs = alpm_list_add(*syncpkgs, sync); } } - - return(0); } -error: - /* if we're here, it's an error */ - return(-1); + + return(0); } int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, char *name) diff --git a/lib/libalpm/sync.h b/lib/libalpm/sync.h index ef094b5..6e4d009 100644 --- a/lib/libalpm/sync.h +++ b/lib/libalpm/sync.h @@ -35,7 +35,9 @@ struct __pmsyncpkg_t { pmsyncpkg_t *_alpm_sync_new(int type, pmpkg_t *spkg, void *data); void _alpm_sync_free(pmsyncpkg_t *data); -int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync); +int _alpm_sync_sysupgrade(pmtrans_t *trans, + pmdb_t *db_local, alpm_list_t *dbs_sync, alpm_list_t **syncpkgs); + int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, char *name); int _alpm_sync_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, alpm_list_t **data); int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data); diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c index c0e38c7..25c7439 100644 --- a/lib/libalpm/trans.c +++ b/lib/libalpm/trans.c @@ -292,7 +292,8 @@ int _alpm_trans_sysupgrade(pmtrans_t *trans) /* Sanity checks */ ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1)); - return(_alpm_sync_sysupgrade(trans, handle->db_local, handle->dbs_sync)); + return(_alpm_sync_sysupgrade(trans, handle->db_local, handle->dbs_sync, + &(trans->packages))); } /** Add a target to the transaction. diff --git a/src/pacman/query.c b/src/pacman/query.c index 8ef47e6..f89ccf2 100644 --- a/src/pacman/query.c +++ b/src/pacman/query.c @@ -237,9 +237,13 @@ static int query_test(void) static int query_upgrades(void) { printf(_("Checking for package upgrades... \n")); - alpm_list_t *syncpkgs; + alpm_list_t *syncpkgs = NULL; - if((syncpkgs = alpm_db_get_upgrades()) != NULL) { + alpm_list_t *syncdbs = alpm_option_get_syncdbs(); + if(alpm_sync_sysupgrade(db_local, syncdbs, &syncpkgs) == -1) { + return(-1); + } + if(syncpkgs) { display_targets(syncpkgs); return(0); } -- 1.5.2.5
participants (2)
-
Dan McGee
-
Xavier