mirror of
https://github.com/moparisthebest/pacman
synced 2024-12-23 00:08:50 -05:00
added a add_faketarget function
reworked logs
This commit is contained in:
parent
3997c31ff1
commit
2e94c34b05
@ -51,31 +51,19 @@
|
||||
|
||||
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;
|
||||
pmpkg_t *dummy;
|
||||
char pkgname[PKG_NAME_LEN], pkgver[PKG_VERSION_LEN];
|
||||
PMList *i;
|
||||
struct stat buf;
|
||||
char *ptr, *p;
|
||||
char *str = NULL;
|
||||
pmpkg_t *dummy = NULL;
|
||||
|
||||
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.
|
||||
* 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;
|
||||
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) {
|
||||
@ -99,15 +87,33 @@ int add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
|
||||
}
|
||||
FREE(str);
|
||||
if(dummy->name[0] == 0 || dummy->version[0] == 0) {
|
||||
pm_errno = PM_ERR_PKG_INVALID_NAME;
|
||||
FREEPKG(dummy);
|
||||
goto error;
|
||||
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)
|
||||
{
|
||||
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);
|
||||
|
||||
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) {
|
||||
/* only install this package if it is not already installed */
|
||||
dummy = db_get_pkgfromcache(db, pkgname);
|
||||
if(dummy) {
|
||||
if(db_get_pkgfromcache(db, pkgname)) {
|
||||
pm_errno = PM_ERR_PKG_INSTALLED;
|
||||
goto error;
|
||||
}
|
||||
@ -151,14 +156,17 @@ int add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
|
||||
if(strcmp(pkg->name, pkgname) == 0) {
|
||||
if(versioncmp(pkg->version, pkgver) < 0) {
|
||||
pmpkg_t *newpkg;
|
||||
_alpm_log(PM_LOG_WARNING, "replacing older version of %s-%s by %s in target list", pkg->name, pkg->version, pkgver);
|
||||
newpkg = pkg_load(name);
|
||||
if(newpkg == NULL) {
|
||||
_alpm_log(PM_LOG_WARNING, "replacing older version %s-%s by %s in target list",
|
||||
pkg->name, pkg->version, pkgver);
|
||||
if((newpkg = pkg_load(name)) == NULL) {
|
||||
/* pm_errno is already set by pkg_load() */
|
||||
goto error;
|
||||
}
|
||||
FREEPKG(i->data);
|
||||
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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user