-Qu rework
From now on -Qu is an "outdated package" filter on local database. (This is a behaviour change.) This patch fixes some memleaks and makes the code cleaner, for details see my comment on FS#7884. FS#11868 is implemented. Signed-off-by: Nagy Gabor <ngaba@bibl.u-szeged.hu> Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
c4b9991258
commit
314b4462d2
7 changed files with 19 additions and 82 deletions
|
@ -254,8 +254,6 @@ alpm_list_t *alpm_grp_get_pkgs(const pmgrp_t *grp);
|
||||||
pmpkg_t *alpm_sync_get_pkg(const pmsyncpkg_t *sync);
|
pmpkg_t *alpm_sync_get_pkg(const pmsyncpkg_t *sync);
|
||||||
alpm_list_t *alpm_sync_get_removes(const pmsyncpkg_t *sync);
|
alpm_list_t *alpm_sync_get_removes(const pmsyncpkg_t *sync);
|
||||||
pmpkg_t *alpm_sync_newversion(pmpkg_t *pkg, alpm_list_t *dbs_sync);
|
pmpkg_t *alpm_sync_newversion(pmpkg_t *pkg, alpm_list_t *dbs_sync);
|
||||||
int alpm_sync_sysupgrade(pmdb_t *db_local,
|
|
||||||
alpm_list_t *dbs_sync, alpm_list_t **syncpkgs);
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Transactions
|
* Transactions
|
||||||
|
|
|
@ -77,17 +77,12 @@ void _alpm_sync_free(pmsyncpkg_t *sync)
|
||||||
|
|
||||||
/* Find recommended replacements for packages during a sync.
|
/* Find recommended replacements for packages during a sync.
|
||||||
*/
|
*/
|
||||||
static int find_replacements(pmtrans_t *trans, pmdb_t *db_local,
|
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_list_t *i, *j, *k; /* wow */
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
if(syncpkgs == NULL) {
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* check for "recommended" package replacements */
|
/* check for "recommended" package replacements */
|
||||||
_alpm_log(PM_LOG_DEBUG, "checking for package replacements\n");
|
_alpm_log(PM_LOG_DEBUG, "checking for package replacements\n");
|
||||||
for(i = dbs_sync; i; i = i->next) {
|
for(i = dbs_sync; i; i = i->next) {
|
||||||
|
@ -113,14 +108,11 @@ static int find_replacements(pmtrans_t *trans, pmdb_t *db_local,
|
||||||
alpm_pkg_get_name(lpkg), alpm_pkg_get_version(lpkg),
|
alpm_pkg_get_name(lpkg), alpm_pkg_get_version(lpkg),
|
||||||
alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg));
|
alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg));
|
||||||
} else {
|
} else {
|
||||||
/* get confirmation for the replacement */
|
|
||||||
if(trans) {
|
|
||||||
int doreplace = 0;
|
int doreplace = 0;
|
||||||
QUESTION(trans, PM_TRANS_CONV_REPLACE_PKG, lpkg, spkg, db->treename, &doreplace);
|
QUESTION(trans, PM_TRANS_CONV_REPLACE_PKG, lpkg, spkg, db->treename, &doreplace);
|
||||||
if(!doreplace) {
|
if(!doreplace) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/* if confirmed, add this to the 'final' list, designating 'lpkg' as
|
/* if confirmed, add this to the 'final' list, designating 'lpkg' as
|
||||||
* the package to replace.
|
* the package to replace.
|
||||||
|
@ -129,7 +121,7 @@ static int find_replacements(pmtrans_t *trans, pmdb_t *db_local,
|
||||||
|
|
||||||
/* check if spkg->name is already in the packages list. */
|
/* check if spkg->name is already in the packages list. */
|
||||||
/* TODO: same package name doesn't mean same package */
|
/* TODO: same package name doesn't mean same package */
|
||||||
sync = _alpm_sync_find(*syncpkgs, alpm_pkg_get_name(spkg));
|
sync = _alpm_sync_find(trans->packages, alpm_pkg_get_name(spkg));
|
||||||
if(sync) {
|
if(sync) {
|
||||||
/* found it -- just append to the removes list */
|
/* found it -- just append to the removes list */
|
||||||
sync->removes = alpm_list_add(sync->removes, lpkg);
|
sync->removes = alpm_list_add(sync->removes, lpkg);
|
||||||
|
@ -143,15 +135,12 @@ static int find_replacements(pmtrans_t *trans, pmdb_t *db_local,
|
||||||
sync = _alpm_sync_new(alpm_pkg_get_reason(lpkg), spkg, NULL);
|
sync = _alpm_sync_new(alpm_pkg_get_reason(lpkg), spkg, NULL);
|
||||||
if(sync == NULL) {
|
if(sync == NULL) {
|
||||||
pm_errno = PM_ERR_MEMORY;
|
pm_errno = PM_ERR_MEMORY;
|
||||||
alpm_list_free_inner(*syncpkgs, (alpm_list_fn_free)_alpm_sync_free);
|
|
||||||
alpm_list_free(*syncpkgs);
|
|
||||||
*syncpkgs = NULL;
|
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
sync->removes = alpm_list_add(NULL, lpkg);
|
sync->removes = alpm_list_add(NULL, lpkg);
|
||||||
_alpm_log(PM_LOG_DEBUG, "adding package %s-%s to the transaction targets\n",
|
_alpm_log(PM_LOG_DEBUG, "adding package %s-%s to the transaction targets\n",
|
||||||
alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg));
|
alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg));
|
||||||
*syncpkgs = alpm_list_add(*syncpkgs, sync);
|
trans->packages = alpm_list_add(trans->packages, sync);
|
||||||
}
|
}
|
||||||
_alpm_log(PM_LOG_DEBUG, "%s-%s elected for removal (to be replaced by %s-%s)\n",
|
_alpm_log(PM_LOG_DEBUG, "%s-%s elected for removal (to be replaced by %s-%s)\n",
|
||||||
alpm_pkg_get_name(lpkg), alpm_pkg_get_version(lpkg),
|
alpm_pkg_get_name(lpkg), alpm_pkg_get_version(lpkg),
|
||||||
|
@ -199,33 +188,19 @@ pmpkg_t SYMEXPORT *alpm_sync_newversion(pmpkg_t *pkg, alpm_list_t *dbs_sync)
|
||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get a list of upgradable packages on the current system
|
int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync)
|
||||||
* 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, *replaced = NULL;
|
alpm_list_t *i, *j, *replaced = NULL;
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
if(syncpkgs == NULL) {
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
/* check for "recommended" package replacements */
|
/* check for "recommended" package replacements */
|
||||||
if(find_replacements(trans, db_local, dbs_sync, syncpkgs)) {
|
if(find_replacements(trans, db_local, dbs_sync)) {
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* compute the to-be-replaced packages for efficiency */
|
/* compute the to-be-replaced packages for efficiency */
|
||||||
for(i = *syncpkgs; i; i = i->next) {
|
for(i = trans->packages; i; i = i->next) {
|
||||||
pmsyncpkg_t *sync = i->data;
|
pmsyncpkg_t *sync = i->data;
|
||||||
for(j = sync->removes; j; j = j->next) {
|
for(j = sync->removes; j; j = j->next) {
|
||||||
replaced = alpm_list_add(replaced, j->data);
|
replaced = alpm_list_add(replaced, j->data);
|
||||||
|
@ -255,22 +230,19 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans,
|
||||||
}
|
}
|
||||||
|
|
||||||
/* add the upgrade package to our pmsyncpkg_t list */
|
/* add the upgrade package to our pmsyncpkg_t list */
|
||||||
if(_alpm_sync_find(*syncpkgs, alpm_pkg_get_name(spkg))) {
|
if(_alpm_sync_find(trans->packages, alpm_pkg_get_name(spkg))) {
|
||||||
/* avoid duplicated targets */
|
/* avoid duplicated targets */
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
/* we can set any reason here, it will be overridden by add_commit */
|
/* we can set any reason here, it will be overridden by add_commit */
|
||||||
pmsyncpkg_t *sync = _alpm_sync_new(PM_PKG_REASON_EXPLICIT, spkg, NULL);
|
pmsyncpkg_t *sync = _alpm_sync_new(PM_PKG_REASON_EXPLICIT, spkg, NULL);
|
||||||
if(sync == NULL) {
|
if(sync == NULL) {
|
||||||
alpm_list_free_inner(*syncpkgs, (alpm_list_fn_free)_alpm_sync_free);
|
|
||||||
alpm_list_free(*syncpkgs);
|
|
||||||
*syncpkgs = NULL;
|
|
||||||
alpm_list_free(replaced);
|
alpm_list_free(replaced);
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
_alpm_log(PM_LOG_DEBUG, "adding package %s-%s to the transaction targets\n",
|
_alpm_log(PM_LOG_DEBUG, "adding package %s-%s to the transaction targets\n",
|
||||||
alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg));
|
alpm_pkg_get_name(spkg), alpm_pkg_get_version(spkg));
|
||||||
*syncpkgs = alpm_list_add(*syncpkgs, sync);
|
trans->packages = alpm_list_add(trans->packages, sync);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -33,8 +33,7 @@ struct __pmsyncpkg_t {
|
||||||
pmsyncpkg_t *_alpm_sync_new(pmpkgreason_t newreason, pmpkg_t *spkg, alpm_list_t *removes);
|
pmsyncpkg_t *_alpm_sync_new(pmpkgreason_t newreason, pmpkg_t *spkg, alpm_list_t *removes);
|
||||||
void _alpm_sync_free(pmsyncpkg_t *data);
|
void _alpm_sync_free(pmsyncpkg_t *data);
|
||||||
|
|
||||||
int _alpm_sync_sysupgrade(pmtrans_t *trans,
|
int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync);
|
||||||
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_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_prepare(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, alpm_list_t **data);
|
||||||
|
|
|
@ -100,7 +100,7 @@ int SYMEXPORT alpm_trans_sysupgrade()
|
||||||
ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
|
ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
|
||||||
ASSERT(trans->type == PM_TRANS_TYPE_SYNC, RET_ERR(PM_ERR_TRANS_TYPE, -1));
|
ASSERT(trans->type == PM_TRANS_TYPE_SYNC, RET_ERR(PM_ERR_TRANS_TYPE, -1));
|
||||||
|
|
||||||
return(_alpm_trans_sysupgrade(trans));
|
return(_alpm_sync_sysupgrade(trans, handle->db_local, handle->dbs_sync));
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Add a target to the transaction.
|
/** Add a target to the transaction.
|
||||||
|
@ -271,17 +271,6 @@ int _alpm_trans_init(pmtrans_t *trans, pmtranstype_t type, pmtransflag_t flags,
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int _alpm_trans_sysupgrade(pmtrans_t *trans)
|
|
||||||
{
|
|
||||||
ALPM_LOG_FUNC;
|
|
||||||
|
|
||||||
/* Sanity checks */
|
|
||||||
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
|
||||||
|
|
||||||
return(_alpm_sync_sysupgrade(trans, handle->db_local, handle->dbs_sync,
|
|
||||||
&(trans->packages)));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Add a target to the transaction.
|
/** Add a target to the transaction.
|
||||||
* @param trans the current transaction
|
* @param trans the current transaction
|
||||||
* @param target the name of the target to add
|
* @param target the name of the target to add
|
||||||
|
|
|
@ -71,7 +71,6 @@ void _alpm_trans_free(pmtrans_t *trans);
|
||||||
int _alpm_trans_init(pmtrans_t *trans, pmtranstype_t type, pmtransflag_t flags,
|
int _alpm_trans_init(pmtrans_t *trans, pmtranstype_t type, pmtransflag_t flags,
|
||||||
alpm_trans_cb_event event, alpm_trans_cb_conv conv,
|
alpm_trans_cb_event event, alpm_trans_cb_conv conv,
|
||||||
alpm_trans_cb_progress progress);
|
alpm_trans_cb_progress progress);
|
||||||
int _alpm_trans_sysupgrade(pmtrans_t *trans);
|
|
||||||
int _alpm_trans_addtarget(pmtrans_t *trans, char *target);
|
int _alpm_trans_addtarget(pmtrans_t *trans, char *target);
|
||||||
int _alpm_trans_prepare(pmtrans_t *trans, alpm_list_t **data);
|
int _alpm_trans_prepare(pmtrans_t *trans, alpm_list_t **data);
|
||||||
int _alpm_trans_commit(pmtrans_t *trans, alpm_list_t **data);
|
int _alpm_trans_commit(pmtrans_t *trans, alpm_list_t **data);
|
||||||
|
|
|
@ -113,7 +113,7 @@ static void usage(int op, const char * const myname)
|
||||||
printf(_(" -p, --file <package> query a package file instead of the database\n"));
|
printf(_(" -p, --file <package> query a package file instead of the database\n"));
|
||||||
printf(_(" -s, --search <regex> search locally-installed packages for matching strings\n"));
|
printf(_(" -s, --search <regex> search locally-installed packages for matching strings\n"));
|
||||||
printf(_(" -t, --unrequired list all packages not required by any package\n"));
|
printf(_(" -t, --unrequired list all packages not required by any package\n"));
|
||||||
printf(_(" -u, --upgrades list all packages that can be upgraded\n"));
|
printf(_(" -u, --upgrades list all outdated packages\n"));
|
||||||
printf(_(" -q, --quiet show less information for query and search\n"));
|
printf(_(" -q, --quiet show less information for query and search\n"));
|
||||||
} else if(op == PM_OP_SYNC) {
|
} else if(op == PM_OP_SYNC) {
|
||||||
printf("%s: %s {-S --sync} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg);
|
printf("%s: %s {-S --sync} [%s] [%s]\n", str_usg, myname, str_opt, str_pkg);
|
||||||
|
|
|
@ -251,24 +251,6 @@ static int query_group(alpm_list_t *targets)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int query_upgrades(void)
|
|
||||||
{
|
|
||||||
alpm_list_t *syncpkgs = NULL;
|
|
||||||
printf(_("Checking for package upgrades... \n"));
|
|
||||||
|
|
||||||
alpm_list_t *syncdbs = alpm_option_get_syncdbs();
|
|
||||||
if(alpm_sync_sysupgrade(db_local, syncdbs, &syncpkgs) == -1) {
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
if(syncpkgs) {
|
|
||||||
display_synctargets(syncpkgs);
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
printf(_("no upgrades found.\n"));
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
static int is_foreign(pmpkg_t *pkg)
|
static int is_foreign(pmpkg_t *pkg)
|
||||||
{
|
{
|
||||||
const char *pkgname = alpm_pkg_get_name(pkg);
|
const char *pkgname = alpm_pkg_get_name(pkg);
|
||||||
|
@ -320,6 +302,10 @@ static int filter(pmpkg_t *pkg)
|
||||||
if(config->op_q_unrequired && !is_unrequired(pkg)) {
|
if(config->op_q_unrequired && !is_unrequired(pkg)) {
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
/* check if this pkg is outdated */
|
||||||
|
if(config->op_q_upgrade && (alpm_sync_newversion(pkg, alpm_option_get_syncdbs()) == NULL)) {
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
return(1);
|
return(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -361,12 +347,6 @@ int pacman_query(alpm_list_t *targets)
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* check for package upgrades */
|
|
||||||
if(config->op_q_upgrade) {
|
|
||||||
ret = query_upgrades();
|
|
||||||
return(ret);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* looking for groups */
|
/* looking for groups */
|
||||||
if(config->group) {
|
if(config->group) {
|
||||||
ret = query_group(targets);
|
ret = query_group(targets);
|
||||||
|
|
Loading…
Add table
Reference in a new issue