mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-07 11:58:02 -05:00
Replacements refactor: extract check_literal()
This moves code that was inline in alpm_sync_sysupgrade() to its own method. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
5d291d050e
commit
231d6cc1e4
@ -81,6 +81,45 @@ alpm_pkg_t SYMEXPORT *alpm_sync_newversion(alpm_pkg_t *pkg, alpm_list_t *dbs_syn
|
|||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int check_literal(alpm_handle_t *handle, alpm_pkg_t *lpkg,
|
||||||
|
alpm_pkg_t *spkg, int enable_downgrade)
|
||||||
|
{
|
||||||
|
/* 1. literal was found in sdb */
|
||||||
|
int cmp = _alpm_pkg_compare_versions(spkg, lpkg);
|
||||||
|
if(cmp > 0) {
|
||||||
|
_alpm_log(handle, ALPM_LOG_DEBUG, "new version of '%s' found (%s => %s)\n",
|
||||||
|
lpkg->name, lpkg->version, spkg->version);
|
||||||
|
/* check IgnorePkg/IgnoreGroup */
|
||||||
|
if(_alpm_pkg_should_ignore(handle, spkg)
|
||||||
|
|| _alpm_pkg_should_ignore(handle, lpkg)) {
|
||||||
|
_alpm_log(handle, ALPM_LOG_WARNING, _("%s: ignoring package upgrade (%s => %s)\n"),
|
||||||
|
lpkg->name, lpkg->version, spkg->version);
|
||||||
|
} else {
|
||||||
|
_alpm_log(handle, ALPM_LOG_DEBUG, "adding package %s-%s to the transaction targets\n",
|
||||||
|
spkg->name, spkg->version);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else if(cmp < 0) {
|
||||||
|
if(enable_downgrade) {
|
||||||
|
/* check IgnorePkg/IgnoreGroup */
|
||||||
|
if(_alpm_pkg_should_ignore(handle, spkg)
|
||||||
|
|| _alpm_pkg_should_ignore(handle, lpkg)) {
|
||||||
|
_alpm_log(handle, ALPM_LOG_WARNING, _("%s: ignoring package downgrade (%s => %s)\n"),
|
||||||
|
lpkg->name, lpkg->version, spkg->version);
|
||||||
|
} else {
|
||||||
|
_alpm_log(handle, ALPM_LOG_WARNING, _("%s: downgrading from version %s to version %s\n"),
|
||||||
|
lpkg->name, lpkg->version, spkg->version);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
alpm_db_t *sdb = alpm_pkg_get_db(spkg);
|
||||||
|
_alpm_log(handle, ALPM_LOG_WARNING, _("%s: local (%s) is newer than %s (%s)\n"),
|
||||||
|
lpkg->name, lpkg->version, sdb->treename, spkg->version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
/** Search for packages to upgrade and add them to the transaction. */
|
/** Search for packages to upgrade and add them to the transaction. */
|
||||||
int SYMEXPORT alpm_sync_sysupgrade(alpm_handle_t *handle, int enable_downgrade)
|
int SYMEXPORT alpm_sync_sysupgrade(alpm_handle_t *handle, int enable_downgrade)
|
||||||
{
|
{
|
||||||
@ -101,50 +140,24 @@ int SYMEXPORT alpm_sync_sysupgrade(alpm_handle_t *handle, int enable_downgrade)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Search for literal then replacers in each sync database.
|
/* Search for literal then replacers in each sync database. */
|
||||||
* If found, don't check other databases */
|
|
||||||
for(j = handle->dbs_sync; j; j = j->next) {
|
for(j = handle->dbs_sync; j; j = j->next) {
|
||||||
alpm_db_t *sdb = j->data;
|
alpm_db_t *sdb = j->data;
|
||||||
/* Check sdb */
|
/* Check sdb */
|
||||||
alpm_pkg_t *spkg = _alpm_db_get_pkgfromcache(sdb, lpkg->name);
|
alpm_pkg_t *spkg = _alpm_db_get_pkgfromcache(sdb, lpkg->name);
|
||||||
|
int literal_upgrade = 0;
|
||||||
if(spkg) {
|
if(spkg) {
|
||||||
/* 1. literal was found in sdb */
|
literal_upgrade = check_literal(handle, lpkg, spkg, enable_downgrade);
|
||||||
int cmp = _alpm_pkg_compare_versions(spkg, lpkg);
|
if(literal_upgrade) {
|
||||||
if(cmp > 0) {
|
trans->add = alpm_list_add(trans->add, spkg);
|
||||||
_alpm_log(handle, ALPM_LOG_DEBUG, "new version of '%s' found (%s => %s)\n",
|
|
||||||
lpkg->name, lpkg->version, spkg->version);
|
|
||||||
/* check IgnorePkg/IgnoreGroup */
|
|
||||||
if(_alpm_pkg_should_ignore(handle, spkg)
|
|
||||||
|| _alpm_pkg_should_ignore(handle, lpkg)) {
|
|
||||||
_alpm_log(handle, ALPM_LOG_WARNING, _("%s: ignoring package upgrade (%s => %s)\n"),
|
|
||||||
lpkg->name, lpkg->version, spkg->version);
|
|
||||||
} else {
|
|
||||||
_alpm_log(handle, ALPM_LOG_DEBUG, "adding package %s-%s to the transaction targets\n",
|
|
||||||
spkg->name, spkg->version);
|
|
||||||
trans->add = alpm_list_add(trans->add, spkg);
|
|
||||||
}
|
|
||||||
} else if(cmp < 0) {
|
|
||||||
if(enable_downgrade) {
|
|
||||||
/* check IgnorePkg/IgnoreGroup */
|
|
||||||
if(_alpm_pkg_should_ignore(handle, spkg)
|
|
||||||
|| _alpm_pkg_should_ignore(handle, lpkg)) {
|
|
||||||
_alpm_log(handle, ALPM_LOG_WARNING, _("%s: ignoring package downgrade (%s => %s)\n"),
|
|
||||||
lpkg->name, lpkg->version, spkg->version);
|
|
||||||
} else {
|
|
||||||
_alpm_log(handle, ALPM_LOG_WARNING, _("%s: downgrading from version %s to version %s\n"),
|
|
||||||
lpkg->name, lpkg->version, spkg->version);
|
|
||||||
trans->add = alpm_list_add(trans->add, spkg);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
_alpm_log(handle, ALPM_LOG_WARNING, _("%s: local (%s) is newer than %s (%s)\n"),
|
|
||||||
lpkg->name, lpkg->version, sdb->treename, spkg->version);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
/* jump to next local package */
|
/* jump to next local package */
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
/* 2. search for replacers in sdb */
|
/* 2. search for replacers in sdb */
|
||||||
alpm_list_t *k, *l;
|
alpm_list_t *k, *l;
|
||||||
|
_alpm_log(handle, ALPM_LOG_DEBUG,
|
||||||
|
"searching for replacements for %s\n", lpkg->name);
|
||||||
for(k = _alpm_db_get_pkgcache(sdb); k; k = k->next) {
|
for(k = _alpm_db_get_pkgcache(sdb); k; k = k->next) {
|
||||||
int found = 0;
|
int found = 0;
|
||||||
spkg = k->data;
|
spkg = k->data;
|
||||||
|
Loading…
Reference in New Issue
Block a user