mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-22 15:58:50 -05:00
Change the interface for target loading
-int alpm_trans_sysupgrade(int enable_downgrade); -int alpm_trans_sync(char *target); -int alpm_trans_add(char *target); -int alpm_trans_remove(char *target); +int alpm_sync_sysupgrade(int enable_downgrade); +int alpm_sync_target(char *target); +int alpm_sync_dbtarget(char *db, char *target); +int alpm_add_target(char *target); +int alpm_remove_target(char *target); * functions renaming * add new sync_dbtarget which allows to specify the db * repo/ syntax handling is moved to frontend ( should implement FS#15141) * group handling is moved to backend ( see http://www.archlinux.org/pipermail/pacman-dev/2009-June/008847.html )
This commit is contained in:
parent
19e07eb8e8
commit
b4317a740a
@ -50,21 +50,30 @@
|
|||||||
#include "remove.h"
|
#include "remove.h"
|
||||||
#include "handle.h"
|
#include "handle.h"
|
||||||
|
|
||||||
int _alpm_add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
|
/** Add a file target to the transaction.
|
||||||
|
* @param target the name of the file target to add
|
||||||
|
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
||||||
|
*/
|
||||||
|
int SYMEXPORT alpm_add_target(char *target)
|
||||||
{
|
{
|
||||||
pmpkg_t *pkg = NULL;
|
pmpkg_t *pkg = NULL;
|
||||||
const char *pkgname, *pkgver;
|
const char *pkgname, *pkgver;
|
||||||
alpm_list_t *i;
|
alpm_list_t *i;
|
||||||
|
pmtrans_t *trans;
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
|
/* Sanity checks */
|
||||||
|
ASSERT(target != NULL && strlen(target) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
|
||||||
|
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
|
||||||
|
trans = handle->trans;
|
||||||
|
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
||||||
|
ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
|
||||||
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
||||||
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
|
|
||||||
ASSERT(name != NULL && strlen(name) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
|
|
||||||
|
|
||||||
_alpm_log(PM_LOG_DEBUG, "loading target '%s'\n", name);
|
_alpm_log(PM_LOG_DEBUG, "loading target '%s'\n", target);
|
||||||
|
|
||||||
if(alpm_pkg_load(name, 1, &pkg) != 0) {
|
if(alpm_pkg_load(target, 1, &pkg) != 0) {
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
pkgname = alpm_pkg_get_name(pkg);
|
pkgname = alpm_pkg_get_name(pkg);
|
||||||
@ -76,13 +85,15 @@ int _alpm_add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
|
|||||||
pmpkg_t *transpkg = i->data;
|
pmpkg_t *transpkg = i->data;
|
||||||
if(strcmp(transpkg->name, pkgname) == 0) {
|
if(strcmp(transpkg->name, pkgname) == 0) {
|
||||||
if(alpm_pkg_vercmp(transpkg->version, pkgver) < 0) {
|
if(alpm_pkg_vercmp(transpkg->version, pkgver) < 0) {
|
||||||
_alpm_log(PM_LOG_WARNING, _("replacing older version %s-%s by %s in target list\n"),
|
_alpm_log(PM_LOG_WARNING,
|
||||||
transpkg->name, transpkg->version, pkgver);
|
_("replacing older version %s-%s by %s in target list\n"),
|
||||||
|
transpkg->name, transpkg->version, pkgver);
|
||||||
_alpm_pkg_free(i->data);
|
_alpm_pkg_free(i->data);
|
||||||
i->data = pkg;
|
i->data = pkg;
|
||||||
} else {
|
} else {
|
||||||
_alpm_log(PM_LOG_WARNING, _("skipping %s-%s because newer version %s is in the target list\n"),
|
_alpm_log(PM_LOG_WARNING,
|
||||||
pkgname, pkgver, transpkg->version);
|
_("skipping %s-%s because newer version %s is in the target list\n"),
|
||||||
|
pkgname, pkgver, transpkg->version);
|
||||||
_alpm_pkg_free(pkg);
|
_alpm_pkg_free(pkg);
|
||||||
}
|
}
|
||||||
return(0);
|
return(0);
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
#include "alpm_list.h"
|
#include "alpm_list.h"
|
||||||
#include "trans.h"
|
#include "trans.h"
|
||||||
|
|
||||||
int _alpm_add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name);
|
|
||||||
int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db);
|
int _alpm_upgrade_packages(pmtrans_t *trans, pmdb_t *db);
|
||||||
|
|
||||||
#endif /* _ALPM_ADD_H */
|
#endif /* _ALPM_ADD_H */
|
||||||
|
@ -401,15 +401,17 @@ alpm_list_t * alpm_trans_get_remove();
|
|||||||
int alpm_trans_init(pmtransflag_t flags,
|
int alpm_trans_init(pmtransflag_t flags,
|
||||||
alpm_trans_cb_event cb_event, alpm_trans_cb_conv conv,
|
alpm_trans_cb_event cb_event, alpm_trans_cb_conv conv,
|
||||||
alpm_trans_cb_progress cb_progress);
|
alpm_trans_cb_progress cb_progress);
|
||||||
int alpm_trans_sysupgrade(int enable_downgrade);
|
|
||||||
int alpm_trans_sync(char *target);
|
|
||||||
int alpm_trans_add(char *target);
|
|
||||||
int alpm_trans_remove(char *target);
|
|
||||||
int alpm_trans_prepare(alpm_list_t **data);
|
int alpm_trans_prepare(alpm_list_t **data);
|
||||||
int alpm_trans_commit(alpm_list_t **data);
|
int alpm_trans_commit(alpm_list_t **data);
|
||||||
int alpm_trans_interrupt(void);
|
int alpm_trans_interrupt(void);
|
||||||
int alpm_trans_release(void);
|
int alpm_trans_release(void);
|
||||||
|
|
||||||
|
int alpm_sync_sysupgrade(int enable_downgrade);
|
||||||
|
int alpm_sync_target(char *target);
|
||||||
|
int alpm_sync_dbtarget(char *db, char *target);
|
||||||
|
int alpm_add_target(char *target);
|
||||||
|
int alpm_remove_target(char *target);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Dependencies and conflicts
|
* Dependencies and conflicts
|
||||||
*/
|
*/
|
||||||
|
@ -47,35 +47,45 @@
|
|||||||
#include "handle.h"
|
#include "handle.h"
|
||||||
#include "alpm.h"
|
#include "alpm.h"
|
||||||
|
|
||||||
int _alpm_remove_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
|
int SYMEXPORT alpm_remove_target(char *target)
|
||||||
{
|
{
|
||||||
pmpkg_t *info;
|
pmpkg_t *info;
|
||||||
const char *targ;
|
pmtrans_t *trans;
|
||||||
|
pmdb_t *db_local;
|
||||||
|
alpm_list_t *p;
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
|
/* Sanity checks */
|
||||||
|
ASSERT(target != NULL && strlen(target) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
|
||||||
|
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
|
||||||
|
trans = handle->trans;
|
||||||
|
db_local = handle->db_local;
|
||||||
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
||||||
ASSERT(name != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
|
ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
|
||||||
|
ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
|
||||||
|
|
||||||
targ = strchr(name, '/');
|
|
||||||
if(targ && strncmp(name, "local", 5) == 0) {
|
|
||||||
targ++;
|
|
||||||
} else {
|
|
||||||
targ = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(_alpm_pkg_find(trans->remove, targ)) {
|
if(_alpm_pkg_find(trans->remove, target)) {
|
||||||
RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1);
|
RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if((info = _alpm_db_get_pkgfromcache(db, targ)) == NULL) {
|
if((info = _alpm_db_get_pkgfromcache(db_local, target)) != NULL) {
|
||||||
_alpm_log(PM_LOG_DEBUG, "could not find %s in database\n", targ);
|
_alpm_log(PM_LOG_DEBUG, "adding %s in the targets list\n", info->name);
|
||||||
RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
|
trans->remove = alpm_list_add(trans->remove, _alpm_pkg_dup(info));
|
||||||
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
_alpm_log(PM_LOG_DEBUG, "adding %s in the targets list\n", info->name);
|
_alpm_log(PM_LOG_DEBUG, "could not find %s in database\n", target);
|
||||||
trans->remove = alpm_list_add(trans->remove, _alpm_pkg_dup(info));
|
pmgrp_t *grp = alpm_db_readgrp(db_local, target);
|
||||||
|
if(grp == NULL) {
|
||||||
|
RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
|
||||||
|
}
|
||||||
|
for(p = alpm_grp_get_pkgs(grp); p; p = alpm_list_next(p)) {
|
||||||
|
pmpkg_t *pkg = alpm_list_getdata(p);
|
||||||
|
_alpm_log(PM_LOG_DEBUG, "adding %s in the targets list\n", pkg->name);
|
||||||
|
trans->remove = alpm_list_add(trans->remove, _alpm_pkg_dup(pkg));
|
||||||
|
}
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
@ -24,13 +24,11 @@
|
|||||||
#include "alpm_list.h"
|
#include "alpm_list.h"
|
||||||
#include "trans.h"
|
#include "trans.h"
|
||||||
|
|
||||||
int _alpm_remove_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name);
|
|
||||||
int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data);
|
int _alpm_remove_prepare(pmtrans_t *trans, pmdb_t *db, alpm_list_t **data);
|
||||||
int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db);
|
int _alpm_remove_packages(pmtrans_t *trans, pmdb_t *db);
|
||||||
|
|
||||||
int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg, pmtrans_t *trans);
|
int _alpm_upgraderemove_package(pmpkg_t *oldpkg, pmpkg_t *newpkg, pmtrans_t *trans);
|
||||||
|
|
||||||
|
|
||||||
#endif /* _ALPM_REMOVE_H */
|
#endif /* _ALPM_REMOVE_H */
|
||||||
|
|
||||||
/* vim: set ts=2 sw=2 noet: */
|
/* vim: set ts=2 sw=2 noet: */
|
||||||
|
@ -82,12 +82,25 @@ pmpkg_t SYMEXPORT *alpm_sync_newversion(pmpkg_t *pkg, alpm_list_t *dbs_sync)
|
|||||||
return(NULL);
|
return(NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, int enable_downgrade)
|
/** Search for packages to upgrade and add them to the transaction.
|
||||||
|
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
||||||
|
*/
|
||||||
|
int SYMEXPORT alpm_sync_sysupgrade(int enable_downgrade)
|
||||||
{
|
{
|
||||||
alpm_list_t *i, *j, *k;
|
alpm_list_t *i, *j, *k;
|
||||||
|
pmtrans_t *trans;
|
||||||
|
pmdb_t *db_local;
|
||||||
|
alpm_list_t *dbs_sync;
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
|
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
|
||||||
|
trans = handle->trans;
|
||||||
|
db_local = handle->db_local;
|
||||||
|
dbs_sync = handle->dbs_sync;
|
||||||
|
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
||||||
|
ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
|
||||||
|
|
||||||
_alpm_log(PM_LOG_DEBUG, "checking for package upgrades\n");
|
_alpm_log(PM_LOG_DEBUG, "checking for package upgrades\n");
|
||||||
for(i = _alpm_db_get_pkgcache(db_local); i; i = i->next) {
|
for(i = _alpm_db_get_pkgcache(db_local); i; i = i->next) {
|
||||||
pmpkg_t *lpkg = i->data;
|
pmpkg_t *lpkg = i->data;
|
||||||
@ -189,55 +202,16 @@ int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_s
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, char *name)
|
int _alpm_sync_pkg(pmpkg_t *spkg)
|
||||||
{
|
{
|
||||||
char *targline;
|
pmtrans_t *trans;
|
||||||
char *targ;
|
pmdb_t *db_local;
|
||||||
alpm_list_t *j;
|
pmpkg_t *local;
|
||||||
pmpkg_t *local, *spkg;
|
|
||||||
pmdepend_t *dep; /* provisions and dependencies are also allowed */
|
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
|
trans = handle->trans;
|
||||||
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
db_local = handle->db_local;
|
||||||
ASSERT(name != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
|
|
||||||
|
|
||||||
STRDUP(targline, name, RET_ERR(PM_ERR_MEMORY, -1));
|
|
||||||
targ = strchr(targline, '/');
|
|
||||||
if(targ) {
|
|
||||||
/* we are looking for a package in a specific database */
|
|
||||||
alpm_list_t *dbs = NULL;
|
|
||||||
*targ = '\0';
|
|
||||||
targ++;
|
|
||||||
_alpm_log(PM_LOG_DEBUG, "searching for target '%s' in repo '%s'\n", targ, targline);
|
|
||||||
for(j = dbs_sync; j; j = j->next) {
|
|
||||||
pmdb_t *db = j->data;
|
|
||||||
if(strcmp(db->treename, targline) == 0) {
|
|
||||||
dbs = alpm_list_add(NULL, db);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(dbs == NULL) {
|
|
||||||
_alpm_log(PM_LOG_ERROR, _("repository '%s' not found\n"), targline);
|
|
||||||
FREE(targline);
|
|
||||||
RET_ERR(PM_ERR_PKG_REPO_NOT_FOUND, -1);
|
|
||||||
}
|
|
||||||
dep = _alpm_splitdep(targ);
|
|
||||||
spkg = _alpm_resolvedep(dep, dbs, NULL, 1);
|
|
||||||
_alpm_dep_free(dep);
|
|
||||||
alpm_list_free(dbs);
|
|
||||||
} else {
|
|
||||||
dep = _alpm_splitdep(targline);
|
|
||||||
spkg = _alpm_resolvedep(dep, dbs_sync, NULL, 1);
|
|
||||||
_alpm_dep_free(dep);
|
|
||||||
}
|
|
||||||
FREE(targline);
|
|
||||||
|
|
||||||
if(spkg == NULL) {
|
|
||||||
/* pm_errno is set by _alpm_resolvedep */
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(_alpm_pkg_find(trans->add, alpm_pkg_get_name(spkg))) {
|
if(_alpm_pkg_find(trans->add, alpm_pkg_get_name(spkg))) {
|
||||||
RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1);
|
RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1);
|
||||||
@ -274,6 +248,104 @@ int _alpm_sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sy
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int _alpm_sync_target(alpm_list_t *dbs_sync, char *target)
|
||||||
|
{
|
||||||
|
alpm_list_t *i, *j;
|
||||||
|
pmpkg_t *spkg;
|
||||||
|
pmdepend_t *dep; /* provisions and dependencies are also allowed */
|
||||||
|
pmgrp_t *grp;
|
||||||
|
int found = 0;
|
||||||
|
|
||||||
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
|
/* Sanity checks */
|
||||||
|
ASSERT(target != NULL && strlen(target) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
|
||||||
|
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
|
||||||
|
|
||||||
|
dep = _alpm_splitdep(target);
|
||||||
|
spkg = _alpm_resolvedep(dep, dbs_sync, NULL, 1);
|
||||||
|
_alpm_dep_free(dep);
|
||||||
|
|
||||||
|
if(spkg != NULL) {
|
||||||
|
return(_alpm_sync_pkg(spkg));
|
||||||
|
}
|
||||||
|
|
||||||
|
_alpm_log(PM_LOG_DEBUG, "%s package not found, searching for group...\n", target);
|
||||||
|
for(i = dbs_sync; i; i = i->next) {
|
||||||
|
pmdb_t *db = i->data;
|
||||||
|
grp = alpm_db_readgrp(db, target);
|
||||||
|
if(grp) {
|
||||||
|
found = 1;
|
||||||
|
for(j = alpm_grp_get_pkgs(grp); j; j = j->next) {
|
||||||
|
pmpkg_t *pkg = j->data;
|
||||||
|
if(_alpm_sync_pkg(pkg) == -1) {
|
||||||
|
if(pm_errno == PM_ERR_TRANS_DUP_TARGET || pm_errno == PM_ERR_PKG_IGNORED) {
|
||||||
|
/* just skip duplicate or ignored targets */
|
||||||
|
continue;
|
||||||
|
} else {
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!found) {
|
||||||
|
RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Add a sync target to the transaction.
|
||||||
|
* @param target the name of the sync target to add
|
||||||
|
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
||||||
|
*/
|
||||||
|
int SYMEXPORT alpm_sync_dbtarget(char *dbname, char *target)
|
||||||
|
{
|
||||||
|
alpm_list_t *i;
|
||||||
|
alpm_list_t *dbs_sync;
|
||||||
|
|
||||||
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
|
/* Sanity checks */
|
||||||
|
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
|
||||||
|
dbs_sync = handle->dbs_sync;
|
||||||
|
|
||||||
|
/* we are looking for a package in a specific database */
|
||||||
|
alpm_list_t *dbs = NULL;
|
||||||
|
_alpm_log(PM_LOG_DEBUG, "searching for target '%s' in repo '%s'\n", target, dbname);
|
||||||
|
for(i = dbs_sync; i; i = i->next) {
|
||||||
|
pmdb_t *db = i->data;
|
||||||
|
if(strcmp(db->treename, dbname) == 0) {
|
||||||
|
dbs = alpm_list_add(NULL, db);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(dbs == NULL) {
|
||||||
|
_alpm_log(PM_LOG_ERROR, _("repository '%s' not found\n"), dbname);
|
||||||
|
RET_ERR(PM_ERR_PKG_REPO_NOT_FOUND, -1);
|
||||||
|
}
|
||||||
|
return(_alpm_sync_target(dbs, target));
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Add a sync target to the transaction.
|
||||||
|
* @param target the name of the sync target to add
|
||||||
|
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
||||||
|
*/
|
||||||
|
int SYMEXPORT alpm_sync_target(char *target)
|
||||||
|
{
|
||||||
|
alpm_list_t *dbs_sync;
|
||||||
|
|
||||||
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
|
/* Sanity checks */
|
||||||
|
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
|
||||||
|
dbs_sync = handle->dbs_sync;
|
||||||
|
|
||||||
|
return(_alpm_sync_target(dbs_sync,target));
|
||||||
|
}
|
||||||
|
|
||||||
/** Compute the size of the files that will be downloaded to install a
|
/** Compute the size of the files that will be downloaded to install a
|
||||||
* package.
|
* package.
|
||||||
* @param newpkg the new package to upgrade to
|
* @param newpkg the new package to upgrade to
|
||||||
|
@ -24,9 +24,6 @@
|
|||||||
|
|
||||||
#include "alpm.h"
|
#include "alpm.h"
|
||||||
|
|
||||||
int _alpm_sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t *dbs_sync, int enable_downgrade);
|
|
||||||
|
|
||||||
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);
|
||||||
int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data);
|
int _alpm_sync_commit(pmtrans_t *trans, pmdb_t *db_local, alpm_list_t **data);
|
||||||
|
|
||||||
|
@ -95,100 +95,6 @@ int SYMEXPORT alpm_trans_init(pmtransflag_t flags,
|
|||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Search for packages to upgrade and add them to the transaction.
|
|
||||||
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
|
||||||
*/
|
|
||||||
int SYMEXPORT alpm_trans_sysupgrade(int enable_downgrade)
|
|
||||||
{
|
|
||||||
pmtrans_t *trans;
|
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
|
||||||
|
|
||||||
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
|
|
||||||
|
|
||||||
trans = handle->trans;
|
|
||||||
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
|
||||||
ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
|
|
||||||
|
|
||||||
return(_alpm_sync_sysupgrade(trans, handle->db_local, handle->dbs_sync, enable_downgrade));
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Add a file target to the transaction.
|
|
||||||
* @param target the name of the file target to add
|
|
||||||
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
|
||||||
*/
|
|
||||||
int SYMEXPORT alpm_trans_add(char *target)
|
|
||||||
{
|
|
||||||
pmtrans_t *trans;
|
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
|
||||||
|
|
||||||
/* Sanity checks */
|
|
||||||
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
|
|
||||||
ASSERT(target != NULL && strlen(target) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
|
|
||||||
|
|
||||||
trans = handle->trans;
|
|
||||||
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
|
||||||
ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
|
|
||||||
|
|
||||||
if(_alpm_add_loadtarget(trans, handle->db_local, target) == -1) {
|
|
||||||
/* pm_errno is set by _alpm_add_loadtarget() */
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
/** Add a sync target to the transaction.
|
|
||||||
* @param target the name of the sync target to add
|
|
||||||
* @return 0 on success, -1 on error (pm_errno is set accordingly)
|
|
||||||
*/
|
|
||||||
int SYMEXPORT alpm_trans_sync(char *target)
|
|
||||||
{
|
|
||||||
pmtrans_t *trans;
|
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
|
||||||
|
|
||||||
/* Sanity checks */
|
|
||||||
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
|
|
||||||
ASSERT(target != NULL && strlen(target) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
|
|
||||||
|
|
||||||
trans = handle->trans;
|
|
||||||
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
|
||||||
ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
|
|
||||||
|
|
||||||
if(_alpm_sync_addtarget(trans, handle->db_local, handle->dbs_sync, target) == -1) {
|
|
||||||
/* pm_errno is set by _alpm_sync_loadtarget() */
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
int SYMEXPORT alpm_trans_remove(char *target)
|
|
||||||
{
|
|
||||||
ALPM_LOG_FUNC;
|
|
||||||
|
|
||||||
pmtrans_t *trans;
|
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
|
||||||
|
|
||||||
/* Sanity checks */
|
|
||||||
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
|
|
||||||
ASSERT(target != NULL && strlen(target) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
|
|
||||||
|
|
||||||
trans = handle->trans;
|
|
||||||
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
|
|
||||||
ASSERT(trans->state == STATE_INITIALIZED, RET_ERR(PM_ERR_TRANS_NOT_INITIALIZED, -1));
|
|
||||||
|
|
||||||
if(_alpm_remove_loadtarget(trans, handle->db_local, target) == -1) {
|
|
||||||
/* pm_errno is set by _alpm_remove_loadtarget() */
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
return(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
static alpm_list_t *check_arch(alpm_list_t *pkgs)
|
static alpm_list_t *check_arch(alpm_list_t *pkgs)
|
||||||
{
|
{
|
||||||
alpm_list_t *i;
|
alpm_list_t *i;
|
||||||
|
@ -57,44 +57,17 @@ int pacman_remove(alpm_list_t *targets)
|
|||||||
|
|
||||||
/* Step 1: add targets to the created transaction */
|
/* Step 1: add targets to the created transaction */
|
||||||
for(i = targets; i; i = alpm_list_next(i)) {
|
for(i = targets; i; i = alpm_list_next(i)) {
|
||||||
char *targ = alpm_list_getdata(i);
|
char *target = alpm_list_getdata(i);
|
||||||
if(alpm_trans_remove(targ) == -1) {
|
char *targ = strchr(target, '/');
|
||||||
if(pm_errno == PM_ERR_PKG_NOT_FOUND) {
|
if(targ && strncmp(target, "local", 5) == 0) {
|
||||||
printf(_("%s not found, searching for group...\n"), targ);
|
targ++;
|
||||||
pmgrp_t *grp = alpm_db_readgrp(db_local, targ);
|
} else {
|
||||||
if(grp == NULL) {
|
targ = target;
|
||||||
pm_fprintf(stderr, PM_LOG_ERROR, _("'%s': not found in local db\n"), targ);
|
}
|
||||||
retval = 1;
|
if(alpm_remove_target(targ) == -1) {
|
||||||
goto cleanup;
|
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ, alpm_strerrorlast());
|
||||||
} else {
|
retval = 1;
|
||||||
alpm_list_t *p, *pkgnames = NULL;
|
goto cleanup;
|
||||||
/* convert packages to package names */
|
|
||||||
for(p = alpm_grp_get_pkgs(grp); p; p = alpm_list_next(p)) {
|
|
||||||
pmpkg_t *pkg = alpm_list_getdata(p);
|
|
||||||
pkgnames = alpm_list_add(pkgnames, (void *)alpm_pkg_get_name(pkg));
|
|
||||||
}
|
|
||||||
printf(_(":: group %s:\n"), targ);
|
|
||||||
list_display(" ", pkgnames);
|
|
||||||
int all = yesno(_(" Remove whole content?"));
|
|
||||||
for(p = pkgnames; p; p = alpm_list_next(p)) {
|
|
||||||
char *pkgn = alpm_list_getdata(p);
|
|
||||||
if(all || yesno(_(":: Remove %s from group %s?"), pkgn, targ)) {
|
|
||||||
if(alpm_trans_remove(pkgn) == -1) {
|
|
||||||
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ,
|
|
||||||
alpm_strerrorlast());
|
|
||||||
retval = 1;
|
|
||||||
alpm_list_free(pkgnames);
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
alpm_list_free(pkgnames);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n", targ, alpm_strerrorlast());
|
|
||||||
retval = 1;
|
|
||||||
goto cleanup;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -548,64 +548,34 @@ static alpm_list_t *syncfirst() {
|
|||||||
return(res);
|
return(res);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int process_target(char *targ, alpm_list_t *targets)
|
static int process_target(char *target)
|
||||||
{
|
{
|
||||||
alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
|
/* process targets */
|
||||||
|
char *targ = strchr(target, '/');
|
||||||
|
char *db = NULL;
|
||||||
|
int ret;
|
||||||
|
if(targ) {
|
||||||
|
*targ = '\0';
|
||||||
|
targ++;
|
||||||
|
db = target;
|
||||||
|
ret = alpm_sync_dbtarget(db,targ);
|
||||||
|
} else {
|
||||||
|
targ = target;
|
||||||
|
ret = alpm_sync_target(targ);
|
||||||
|
}
|
||||||
|
|
||||||
if(alpm_trans_sync(targ) == -1) {
|
if(ret == -1) {
|
||||||
pmgrp_t *grp = NULL;
|
if(pm_errno == PM_ERR_TRANS_DUP_TARGET
|
||||||
int found = 0;
|
|| pm_errno == PM_ERR_PKG_IGNORED) {
|
||||||
alpm_list_t *j;
|
|
||||||
|
|
||||||
if(pm_errno == PM_ERR_TRANS_DUP_TARGET || pm_errno == PM_ERR_PKG_IGNORED) {
|
|
||||||
/* just skip duplicate or ignored targets */
|
/* just skip duplicate or ignored targets */
|
||||||
pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), targ);
|
pm_printf(PM_LOG_WARNING, _("skipping target: %s\n"), targ);
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
if(pm_errno != PM_ERR_PKG_NOT_FOUND) {
|
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
|
||||||
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
|
targ, alpm_strerrorlast());
|
||||||
targ, alpm_strerrorlast());
|
return(1);
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
/* target not found: check if it's a group */
|
|
||||||
printf(_("%s package not found, searching for group...\n"), targ);
|
|
||||||
for(j = sync_dbs; j; j = alpm_list_next(j)) {
|
|
||||||
pmdb_t *db = alpm_list_getdata(j);
|
|
||||||
grp = alpm_db_readgrp(db, targ);
|
|
||||||
if(grp) {
|
|
||||||
alpm_list_t *k, *pkgnames = NULL;
|
|
||||||
|
|
||||||
found++;
|
|
||||||
printf(_(":: group %s (including ignored packages):\n"), targ);
|
|
||||||
/* remove dupe entries in case a package exists in multiple repos */
|
|
||||||
alpm_list_t *grppkgs = alpm_grp_get_pkgs(grp);
|
|
||||||
alpm_list_t *pkgs = alpm_list_remove_dupes(grppkgs);
|
|
||||||
for(k = pkgs; k; k = alpm_list_next(k)) {
|
|
||||||
pkgnames = alpm_list_add(pkgnames,
|
|
||||||
(char*)alpm_pkg_get_name(k->data));
|
|
||||||
}
|
|
||||||
list_display(" ", pkgnames);
|
|
||||||
if(yesno(_(":: Install whole content?"))) {
|
|
||||||
for(k = pkgnames; k; k = alpm_list_next(k)) {
|
|
||||||
targets = alpm_list_add(targets, strdup(alpm_list_getdata(k)));
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
for(k = pkgnames; k; k = alpm_list_next(k)) {
|
|
||||||
char *pkgname = alpm_list_getdata(k);
|
|
||||||
if(yesno(_(":: Install %s from group %s?"), pkgname, targ)) {
|
|
||||||
targets = alpm_list_add(targets, strdup(pkgname));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
alpm_list_free(pkgnames);
|
|
||||||
alpm_list_free(pkgs);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(!found) {
|
|
||||||
pm_fprintf(stderr, PM_LOG_ERROR, _("'%s': not found in sync db\n"), targ);
|
|
||||||
return(1);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -624,7 +594,7 @@ static int sync_trans(alpm_list_t *targets)
|
|||||||
/* process targets */
|
/* process targets */
|
||||||
for(i = targets; i; i = alpm_list_next(i)) {
|
for(i = targets; i; i = alpm_list_next(i)) {
|
||||||
char *targ = alpm_list_getdata(i);
|
char *targ = alpm_list_getdata(i);
|
||||||
if(process_target(targ, targets) == 1) {
|
if(process_target(targ) == 1) {
|
||||||
retval = 1;
|
retval = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
@ -633,7 +603,7 @@ static int sync_trans(alpm_list_t *targets)
|
|||||||
if(config->op_s_upgrade) {
|
if(config->op_s_upgrade) {
|
||||||
printf(_(":: Starting full system upgrade...\n"));
|
printf(_(":: Starting full system upgrade...\n"));
|
||||||
alpm_logaction("starting full system upgrade\n");
|
alpm_logaction("starting full system upgrade\n");
|
||||||
if(alpm_trans_sysupgrade(config->op_s_upgrade >= 2) == -1) {
|
if(alpm_sync_sysupgrade(config->op_s_upgrade >= 2) == -1) {
|
||||||
pm_fprintf(stderr, PM_LOG_ERROR, "%s\n", alpm_strerrorlast());
|
pm_fprintf(stderr, PM_LOG_ERROR, "%s\n", alpm_strerrorlast());
|
||||||
retval = 1;
|
retval = 1;
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
|
@ -72,7 +72,7 @@ int pacman_upgrade(alpm_list_t *targets)
|
|||||||
printf(_("loading package data...\n"));
|
printf(_("loading package data...\n"));
|
||||||
for(i = targets; i; i = alpm_list_next(i)) {
|
for(i = targets; i; i = alpm_list_next(i)) {
|
||||||
char *targ = alpm_list_getdata(i);
|
char *targ = alpm_list_getdata(i);
|
||||||
if(alpm_trans_add(targ) == -1) {
|
if(alpm_add_target(targ) == -1) {
|
||||||
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
|
pm_fprintf(stderr, PM_LOG_ERROR, "'%s': %s\n",
|
||||||
targ, alpm_strerrorlast());
|
targ, alpm_strerrorlast());
|
||||||
trans_release();
|
trans_release();
|
||||||
|
Loading…
Reference in New Issue
Block a user