1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-11-13 12:55:08 -05:00

added a add_faketarget function

reworked logs
This commit is contained in:
Aurelien Foret 2006-02-12 09:43:10 +00:00
parent 3997c31ff1
commit 2e94c34b05

View File

@ -51,31 +51,19 @@
extern pmhandle_t *handle; extern pmhandle_t *handle;
int add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name) static int add_faketarget(pmtrans_t *trans, char *name)
{ {
pmpkg_t *info = NULL; char *ptr, *p;
pmpkg_t *dummy; char *str = NULL;
char pkgname[PKG_NAME_LEN], pkgver[PKG_VERSION_LEN]; pmpkg_t *dummy = NULL;
PMList *i;
struct stat buf;
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1)); if((dummy = pkg_new(NULL, NULL)) == NULL) {
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_NULL, -1)); RET_ERR(PM_ERR_MEMORY, -1);
ASSERT(name != NULL && strlen(name) != 0, RET_ERR(PM_ERR_WRONG_ARGS, -1));
/* Check if we need to add a fake target to the transaction.
* format: field1=value1|field2=value2|...
* Supported fields are "name", "version", "depend"
* A fake package is created with the given tokens (name and version are
* required).
*/
if(strchr(name, '|')) {
char *str, *ptr, *p;
dummy = pkg_new(NULL, NULL);
if(dummy == NULL) {
pm_errno = PM_ERR_MEMORY;
goto error;
} }
/* Format: field1=value1|field2=value2|...
* Valid fields are "name", "version" and "depend"
*/
str = strdup(name); str = strdup(name);
ptr = str; ptr = str;
while((p = strsep(&ptr, "|")) != NULL) { while((p = strsep(&ptr, "|")) != NULL) {
@ -99,15 +87,33 @@ int add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
} }
FREE(str); FREE(str);
if(dummy->name[0] == 0 || dummy->version[0] == 0) { if(dummy->name[0] == 0 || dummy->version[0] == 0) {
pm_errno = PM_ERR_PKG_INVALID_NAME;
FREEPKG(dummy); FREEPKG(dummy);
goto error; RET_ERR(PM_ERR_PKG_INVALID_NAME, -1);
} }
/* add the package to the transaction */ /* add the package to the transaction */
trans->packages = pm_list_add(trans->packages, dummy); trans->packages = pm_list_add(trans->packages, dummy);
return(0); return(0);
} }
int add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
{
pmpkg_t *info = NULL;
pmpkg_t *dummy;
char pkgname[PKG_NAME_LEN], pkgver[PKG_VERSION_LEN];
PMList *i;
struct stat buf;
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));
/* Check if we need to add a fake target to the transaction. */
if(strchr(name, '|')) {
return(add_faketarget(trans, name));
}
_alpm_log(PM_LOG_FLOW2, "loading target '%s'", name); _alpm_log(PM_LOG_FLOW2, "loading target '%s'", name);
if(stat(name, &buf)) { if(stat(name, &buf)) {
@ -128,8 +134,7 @@ int add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
if(trans->type != PM_TRANS_TYPE_UPGRADE) { if(trans->type != PM_TRANS_TYPE_UPGRADE) {
/* only install this package if it is not already installed */ /* only install this package if it is not already installed */
dummy = db_get_pkgfromcache(db, pkgname); if(db_get_pkgfromcache(db, pkgname)) {
if(dummy) {
pm_errno = PM_ERR_PKG_INSTALLED; pm_errno = PM_ERR_PKG_INSTALLED;
goto error; goto error;
} }
@ -151,14 +156,17 @@ int add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
if(strcmp(pkg->name, pkgname) == 0) { if(strcmp(pkg->name, pkgname) == 0) {
if(versioncmp(pkg->version, pkgver) < 0) { if(versioncmp(pkg->version, pkgver) < 0) {
pmpkg_t *newpkg; pmpkg_t *newpkg;
_alpm_log(PM_LOG_WARNING, "replacing older version of %s-%s by %s in target list", pkg->name, pkg->version, pkgver); _alpm_log(PM_LOG_WARNING, "replacing older version %s-%s by %s in target list",
newpkg = pkg_load(name); pkg->name, pkg->version, pkgver);
if(newpkg == NULL) { if((newpkg = pkg_load(name)) == NULL) {
/* pm_errno is already set by pkg_load() */ /* pm_errno is already set by pkg_load() */
goto error; goto error;
} }
FREEPKG(i->data); FREEPKG(i->data);
i->data = newpkg; i->data = newpkg;
} else {
_alpm_log(PM_LOG_WARNING, "newer version %s-%s is in the target list -- skipping",
pkg->name, pkg->version, pkgver);
} }
return(0); return(0);
} }