1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-11-11 20:05:07 -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,6 +51,52 @@
extern pmhandle_t *handle; extern pmhandle_t *handle;
static int add_faketarget(pmtrans_t *trans, char *name)
{
char *ptr, *p;
char *str = NULL;
pmpkg_t *dummy = NULL;
if((dummy = pkg_new(NULL, NULL)) == NULL) {
RET_ERR(PM_ERR_MEMORY, -1);
}
/* Format: field1=value1|field2=value2|...
* Valid fields are "name", "version" and "depend"
*/
str = strdup(name);
ptr = str;
while((p = strsep(&ptr, "|")) != NULL) {
char *q;
if(p[0] == 0) {
continue;
}
q = strchr(p, '=');
if(q == NULL) { /* not a valid token */
continue;
}
if(strncmp("name", p, q-p) == 0) {
STRNCPY(dummy->name, q+1, PKG_NAME_LEN);
} else if(strncmp("version", p, q-p) == 0) {
STRNCPY(dummy->version, q+1, PKG_VERSION_LEN);
} else if(strncmp("depend", p, q-p) == 0) {
dummy->depends = pm_list_add(dummy->depends, strdup(q+1));
} else {
_alpm_log(PM_LOG_ERROR, "could not parse token %s", p);
}
}
FREE(str);
if(dummy->name[0] == 0 || dummy->version[0] == 0) {
FREEPKG(dummy);
RET_ERR(PM_ERR_PKG_INVALID_NAME, -1);
}
/* add the package to the transaction */
trans->packages = pm_list_add(trans->packages, dummy);
return(0);
}
int add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name) int add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
{ {
pmpkg_t *info = NULL; pmpkg_t *info = NULL;
@ -63,49 +109,9 @@ int add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
ASSERT(db != NULL, RET_ERR(PM_ERR_DB_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)); 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. /* 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, '|')) { if(strchr(name, '|')) {
char *str, *ptr, *p; return(add_faketarget(trans, name));
dummy = pkg_new(NULL, NULL);
if(dummy == NULL) {
pm_errno = PM_ERR_MEMORY;
goto error;
}
str = strdup(name);
ptr = str;
while((p = strsep(&ptr, "|")) != NULL) {
char *q;
if(p[0] == 0) {
continue;
}
q = strchr(p, '=');
if(q == NULL) { /* not a valid token */
continue;
}
if(strncmp("name", p, q-p) == 0) {
STRNCPY(dummy->name, q+1, PKG_NAME_LEN);
} else if(strncmp("version", p, q-p) == 0) {
STRNCPY(dummy->version, q+1, PKG_VERSION_LEN);
} else if(strncmp("depend", p, q-p) == 0) {
dummy->depends = pm_list_add(dummy->depends, strdup(q+1));
} else {
_alpm_log(PM_LOG_ERROR, "could not parse token %s", p);
}
}
FREE(str);
if(dummy->name[0] == 0 || dummy->version[0] == 0) {
pm_errno = PM_ERR_PKG_INVALID_NAME;
FREEPKG(dummy);
goto error;
}
/* add the package to the transaction */
trans->packages = pm_list_add(trans->packages, dummy);
return(0);
} }
_alpm_log(PM_LOG_FLOW2, "loading target '%s'", name); _alpm_log(PM_LOG_FLOW2, "loading target '%s'", name);
@ -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);
} }