more code cleanup

This commit is contained in:
Aurelien Foret 2006-01-16 22:27:09 +00:00
parent 9b2f0607d5
commit 6e5a62dd12
5 changed files with 39 additions and 50 deletions

View File

@ -108,13 +108,13 @@ int add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
return(0); return(0);
} }
_alpm_log(PM_LOG_FLOW2, "loading target %s", name);
if(stat(name, &buf)) { if(stat(name, &buf)) {
pm_errno = PM_ERR_NOT_A_FILE; pm_errno = PM_ERR_NOT_A_FILE;
goto error; goto error;
} }
_alpm_log(PM_LOG_FLOW2, "loading target %s", name);
if(pkg_splitname(name, pkgname, pkgver) == -1) { if(pkg_splitname(name, pkgname, pkgver) == -1) {
pm_errno = PM_ERR_PKG_INVALID_NAME; pm_errno = PM_ERR_PKG_INVALID_NAME;
goto error; goto error;
@ -256,10 +256,7 @@ int add_prepare(pmtrans_t *trans, pmdb_t *db, PMList **data)
} }
/* copy the file skiplist into the transaction */ /* copy the file skiplist into the transaction */
for(lp = skiplist; lp; lp = lp->next) { trans->skiplist = skiplist;
trans->skiplist = pm_list_add(trans->skiplist, lp->data);
}
FREELISTPTR(skiplist);
EVENT(trans, PM_TRANS_EVT_FILECONFLICTS_DONE, NULL, NULL); EVENT(trans, PM_TRANS_EVT_FILECONFLICTS_DONE, NULL, NULL);
} }
@ -646,18 +643,17 @@ int add_commit(pmtrans_t *trans, pmdb_t *db)
/* use the first one */ /* use the first one */
depinfo = db_get_pkgfromcache(db, ((pmpkg_t *)provides->data)->name); depinfo = db_get_pkgfromcache(db, ((pmpkg_t *)provides->data)->name);
FREELISTPTR(provides); FREELISTPTR(provides);
if(depinfo == NULL) { }
/* wtf */ if(depinfo == NULL) {
continue; /* wtf */
}
} else {
continue; continue;
} }
} }
depinfo->requiredby = pm_list_add(depinfo->requiredby, strdup(info->name)); depinfo->requiredby = pm_list_add(depinfo->requiredby, strdup(info->name));
_alpm_log(PM_LOG_DEBUG, "updating 'requiredby' field for package %s", depinfo->name); _alpm_log(PM_LOG_DEBUG, "updating 'requiredby' field for package %s", depinfo->name);
if(db_write(db, depinfo, INFRQ_DEPENDS)) { if(db_write(db, depinfo, INFRQ_DEPENDS)) {
_alpm_log(PM_LOG_ERROR, "could not update 'requiredby' database entry %s/%s-%s", db->treename, depinfo->name, depinfo->version); _alpm_log(PM_LOG_ERROR, "could not update 'requiredby' database entry %s-%s",
depinfo->name, depinfo->version);
} }
} }

View File

@ -74,7 +74,7 @@ int db_load_pkgcache(pmdb_t *db)
void db_free_pkgcache(pmdb_t *db) void db_free_pkgcache(pmdb_t *db)
{ {
if(db == NULL) { if(db == NULL || db->pkgcache == NULL) {
return; return;
} }
@ -213,7 +213,7 @@ void db_free_grpcache(pmdb_t *db)
{ {
PMList *lg; PMList *lg;
if(db == NULL) { if(db == NULL || db->grpcache == NULL) {
return; return;
} }

View File

@ -29,7 +29,7 @@
pmgrp_t *grp_new() pmgrp_t *grp_new()
{ {
pmgrp_t* grp = NULL; pmgrp_t* grp;
grp = (pmgrp_t *)malloc(sizeof(pmgrp_t)); grp = (pmgrp_t *)malloc(sizeof(pmgrp_t));
if(grp == NULL) { if(grp == NULL) {

View File

@ -56,7 +56,6 @@ int remove_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
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(name != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
_alpm_log(PM_LOG_FLOW2, "loading target %s", name);
if((info = db_scan(db, name, INFRQ_ALL)) == NULL) { if((info = db_scan(db, name, INFRQ_ALL)) == NULL) {
_alpm_log(PM_LOG_ERROR, "could not find %s in database", name); _alpm_log(PM_LOG_ERROR, "could not find %s in database", name);
RET_ERR(PM_ERR_PKG_NOT_FOUND, -1); RET_ERR(PM_ERR_PKG_NOT_FOUND, -1);
@ -67,6 +66,7 @@ int remove_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1); RET_ERR(PM_ERR_TRANS_DUP_TARGET, -1);
} }
_alpm_log(PM_LOG_FLOW2, "adding %s in the targets list", info->name);
trans->packages = pm_list_add(trans->packages, info); trans->packages = pm_list_add(trans->packages, info);
return(0); return(0);
@ -87,13 +87,16 @@ int remove_prepare(pmtrans_t *trans, pmdb_t *db, PMList **data)
if(lp != NULL) { if(lp != NULL) {
if(trans->flags & PM_TRANS_FLAG_CASCADE) { if(trans->flags & PM_TRANS_FLAG_CASCADE) {
while(lp) { while(lp) {
PMList *j; PMList *i;
for(j = lp; j; j = j->next) { for(i = lp; i; i = i->next) {
pmdepmissing_t* miss = (pmdepmissing_t*)j->data; pmdepmissing_t *miss = (pmdepmissing_t *)i->data;
pmpkg_t *info = db_get_pkgfromcache(db, miss->depend.name); pmpkg_t *info = db_scan(db, miss->depend.name, INFRQ_ALL);
if(!pkg_isin(info, trans->packages)) { if(info) {
info = db_scan(db, miss->depend.name, INFRQ_ALL); _alpm_log(PM_LOG_FLOW2, "pulling %s in the targets list", info->name);
trans->packages = pm_list_add(trans->packages, info); trans->packages = pm_list_add(trans->packages, info);
} else {
_alpm_log(PM_LOG_ERROR, "could not find %s in database -- skipping",
miss->depend.name);
} }
} }
FREELIST(lp); FREELIST(lp);
@ -166,7 +169,7 @@ int remove_commit(pmtrans_t *trans, pmdb_t *db)
for(lp = _alpm_list_last(info->files); lp; lp = lp->prev) { for(lp = _alpm_list_last(info->files); lp; lp = lp->prev) {
int nb = 0; int nb = 0;
char *file = lp->data; char *file = lp->data;
char *md5 =_alpm_needbackup(lp->data, info->backup); char *md5 = _alpm_needbackup(lp->data, info->backup);
if(md5) { if(md5) {
nb = 1; nb = 1;
free(md5); free(md5);
@ -201,7 +204,8 @@ int remove_commit(pmtrans_t *trans, pmdb_t *db)
} }
} }
if(skipit) { if(skipit) {
_alpm_log(PM_LOG_FLOW2, "skipping removal of %s as it has moved to another package\n", file); _alpm_log(PM_LOG_FLOW2, "skipping removal of %s as it has moved to another package",
file);
} else { } else {
/* if the file is flagged, back it up to .pacsave */ /* if the file is flagged, back it up to .pacsave */
if(nb) { if(nb) {
@ -245,7 +249,7 @@ int remove_commit(pmtrans_t *trans, pmdb_t *db)
_alpm_log(PM_LOG_FLOW1, "updating database"); _alpm_log(PM_LOG_FLOW1, "updating database");
_alpm_log(PM_LOG_FLOW2, "removing database entry %s", info->name); _alpm_log(PM_LOG_FLOW2, "removing database entry %s", info->name);
if(db_remove(db, info) == -1) { if(db_remove(db, info) == -1) {
_alpm_log(PM_LOG_ERROR, "could not remove database entry %s/%s-%s", db->treename, info->name, info->version); _alpm_log(PM_LOG_ERROR, "could not remove database entry %s-%s", info->name, info->version);
} }
if(db_remove_pkgfromcache(db, info) == -1) { if(db_remove_pkgfromcache(db, info) == -1) {
_alpm_log(PM_LOG_ERROR, "could not remove entry %s from cache", info->name); _alpm_log(PM_LOG_ERROR, "could not remove entry %s from cache", info->name);
@ -257,11 +261,9 @@ int remove_commit(pmtrans_t *trans, pmdb_t *db)
pmpkg_t *depinfo = NULL; pmpkg_t *depinfo = NULL;
pmdepend_t depend; pmdepend_t depend;
char *data; char *data;
if(splitdep((char*)lp->data, &depend)) { if(splitdep((char*)lp->data, &depend)) {
continue; continue;
} }
depinfo = db_get_pkgfromcache(db, depend.name); depinfo = db_get_pkgfromcache(db, depend.name);
if(depinfo == NULL) { if(depinfo == NULL) {
/* look for a provides package */ /* look for a provides package */
@ -273,11 +275,9 @@ int remove_commit(pmtrans_t *trans, pmdb_t *db)
/* use the first one */ /* use the first one */
depinfo = db_get_pkgfromcache(db, ((pmpkg_t *)provides->data)->name); depinfo = db_get_pkgfromcache(db, ((pmpkg_t *)provides->data)->name);
FREELISTPTR(provides); FREELISTPTR(provides);
if(depinfo == NULL) { }
/* wtf */ if(depinfo == NULL) {
continue; /* wtf */
}
} else {
continue; continue;
} }
} }
@ -286,7 +286,8 @@ int remove_commit(pmtrans_t *trans, pmdb_t *db)
FREE(data); FREE(data);
_alpm_log(PM_LOG_DEBUG, "updating 'requiredby' field for package %s", depinfo->name); _alpm_log(PM_LOG_DEBUG, "updating 'requiredby' field for package %s", depinfo->name);
if(db_write(db, depinfo, INFRQ_DEPENDS)) { if(db_write(db, depinfo, INFRQ_DEPENDS)) {
_alpm_log(PM_LOG_ERROR, "could not update 'requiredby' database entry %s/%s-%s", db->treename, depinfo->name, depinfo->version); _alpm_log(PM_LOG_ERROR, "could not update 'requiredby' database entry %s-%s",
depinfo->name, depinfo->version);
} }
} }

View File

@ -206,12 +206,7 @@ int sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync)
pmsyncpkg_t *sync; pmsyncpkg_t *sync;
for(j = dbs_sync; !spkg && j; j = j->next) { for(j = dbs_sync; !spkg && j; j = j->next) {
for(k = db_get_pkgcache(j->data); !spkg && k; k = k->next) { spkg = db_get_pkgfromcache(j->data, local->name);
pmpkg_t *sp = k->data;
if(!strcmp(local->name, sp->name)) {
spkg = sp;
}
}
} }
if(spkg == NULL) { if(spkg == NULL) {
_alpm_log(PM_LOG_DEBUG, "%s: not found in sync db -- skipping.", local->name); _alpm_log(PM_LOG_DEBUG, "%s: not found in sync db -- skipping.", local->name);
@ -393,8 +388,6 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
pmpkg_t *spkg = i->data; pmpkg_t *spkg = i->data;
if(!find_pkginsync(spkg->name, trans->packages)) { if(!find_pkginsync(spkg->name, trans->packages)) {
pmsyncpkg_t *sync = sync_new(PM_SYNC_TYPE_DEPEND, spkg, NULL); pmsyncpkg_t *sync = sync_new(PM_SYNC_TYPE_DEPEND, spkg, NULL);
/* ORE - the trans->packages list should be sorted to stay compatible with
* pacman 2.x */
trans->packages = pm_list_add(trans->packages, sync); trans->packages = pm_list_add(trans->packages, sync);
_alpm_log(PM_LOG_FLOW2, "adding package %s-%s to the transaction targets", _alpm_log(PM_LOG_FLOW2, "adding package %s-%s to the transaction targets",
spkg->name, spkg->version); spkg->name, spkg->version);
@ -517,16 +510,13 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
pmsyncpkg_t *s = k->data; pmsyncpkg_t *s = k->data;
if(!strcmp(s->pkg->name, miss->target)) { if(!strcmp(s->pkg->name, miss->target)) {
pmpkg_t *q = pkg_new(miss->depend.name, NULL); pmpkg_t *q = pkg_new(miss->depend.name, NULL);
if(s->type == PM_SYNC_TYPE_REPLACE) { if(s->type != PM_SYNC_TYPE_REPLACE) {
/* append to the replaces list */
s->data = pm_list_add(s->data, q);
} else {
/* switch this sync type to REPLACE */ /* switch this sync type to REPLACE */
s->type = PM_SYNC_TYPE_REPLACE; s->type = PM_SYNC_TYPE_REPLACE;
/* add miss->depend.name to the replaces list */ FREEPKG(s->data);
/* ORE - isn't the next line overwriting s->data? */
s->data = pm_list_add(NULL, q);
} }
/* append to the replaces list */
s->data = pm_list_add(s->data, q);
} }
} }
} else { } else {
@ -760,7 +750,8 @@ int sync_commit(pmtrans_t *trans, pmdb_t *db_local, PMList **data)
} }
} }
if(db_write(db_local, depender, INFRQ_DEPENDS) == -1) { if(db_write(db_local, depender, INFRQ_DEPENDS) == -1) {
_alpm_log(PM_LOG_ERROR, "could not update 'requiredby' database entry %s/%s-%s", db_local->treename, new->name, new->version); _alpm_log(PM_LOG_ERROR, "could not update 'requiredby' database entry %s-%s",
new->name, new->version);
} }
/* add the new requiredby */ /* add the new requiredby */
new->requiredby = pm_list_add(new->requiredby, strdup(k->data)); new->requiredby = pm_list_add(new->requiredby, strdup(k->data));
@ -768,7 +759,8 @@ int sync_commit(pmtrans_t *trans, pmdb_t *db_local, PMList **data)
} }
} }
if(db_write(db_local, new, INFRQ_DEPENDS) == -1) { if(db_write(db_local, new, INFRQ_DEPENDS) == -1) {
_alpm_log(PM_LOG_ERROR, "could not update new database entry %s/%s-%s", db_local->treename, new->name, new->version); _alpm_log(PM_LOG_ERROR, "could not update new database entry %s-%s",
new->name, new->version);
} }
} }
} }