code cleanup

This commit is contained in:
Aurelien Foret 2006-01-02 20:28:46 +00:00
parent 96de3501ab
commit 5839652c41
3 changed files with 36 additions and 30 deletions

View File

@ -224,7 +224,7 @@ int alpm_db_unregister(pmdb_t *db)
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
ASSERT(db != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1)); ASSERT(db != NULL, RET_ERR(PM_ERR_WRONG_ARGS, -1));
/* Do not unregister a database if a transaction is on-going */ /* Do not unregister a database if a transaction is on-going */
ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, NULL)); ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, -1));
if(db == handle->db_local) { if(db == handle->db_local) {
db_close(handle->db_local); db_close(handle->db_local);
@ -272,7 +272,7 @@ int alpm_db_update(PM_DB *db, char *archive, char *ts)
ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1)); ASSERT(handle != NULL, RET_ERR(PM_ERR_HANDLE_NULL, -1));
ASSERT(db != NULL && db != handle->db_local, RET_ERR(PM_ERR_WRONG_ARGS, -1)); ASSERT(db != NULL && db != handle->db_local, RET_ERR(PM_ERR_WRONG_ARGS, -1));
/* Do not update a database if a transaction is on-going */ /* Do not update a database if a transaction is on-going */
ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, NULL)); ASSERT(handle->trans == NULL, RET_ERR(PM_ERR_TRANS_NOT_NULL, -1));
if(!pm_list_is_in(db, handle->dbs_sync)) { if(!pm_list_is_in(db, handle->dbs_sync)) {
RET_ERR(PM_ERR_DB_NOT_FOUND, -1); RET_ERR(PM_ERR_DB_NOT_FOUND, -1);

View File

@ -130,7 +130,6 @@ int db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg)
} }
db->pkgcache = _alpm_list_remove(db->pkgcache, pkg, pkg_cmp, (void **)&data); db->pkgcache = _alpm_list_remove(db->pkgcache, pkg, pkg_cmp, (void **)&data);
if(data == NULL) { if(data == NULL) {
/* package not found */ /* package not found */
return(-1); return(-1);

View File

@ -286,7 +286,7 @@ int sync_addtarget(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, char *n
local = db_get_pkgfromcache(db_local, name); local = db_get_pkgfromcache(db_local, name);
if(local) { if(local) {
cmp = alpm_pkg_vercmp(local->version, spkg->version); cmp = versioncmp(local->version, spkg->version);
if(cmp > 0) { if(cmp > 0) {
/* local version is newer -- get confirmation before adding */ /* local version is newer -- get confirmation before adding */
int resp = 0; int resp = 0;
@ -340,6 +340,7 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
PMList *deps = NULL; PMList *deps = NULL;
PMList *list = NULL; PMList *list = NULL;
PMList *trail = NULL; PMList *trail = NULL;
PMList *asked = NULL;
PMList *i; PMList *i;
ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1)); ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
@ -359,8 +360,7 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
EVENT(trans, PM_TRANS_EVT_RESOLVEDEPS_START, NULL, NULL); EVENT(trans, PM_TRANS_EVT_RESOLVEDEPS_START, NULL, NULL);
_alpm_log(PM_LOG_FLOW1, "resolving targets dependencies"); _alpm_log(PM_LOG_FLOW1, "resolving targets dependencies");
for(i = trans->packages; i; i = i->next) { for(i = trans->packages; i; i = i->next) {
pmsyncpkg_t *sync = i->data; pmpkg_t *spkg = ((pmsyncpkg_t *)i->data)->pkg;
pmpkg_t *spkg = sync->pkg;
_alpm_log(PM_LOG_FLOW1, "resolving dependencies for package %s", spkg->name); _alpm_log(PM_LOG_FLOW1, "resolving dependencies for package %s", spkg->name);
if(resolvedeps(db_local, dbs_sync, spkg, list, trail, trans) == -1) { if(resolvedeps(db_local, dbs_sync, spkg, list, trail, trans) == -1) {
/* pm_errno is set by resolvedeps */ /* pm_errno is set by resolvedeps */
@ -368,6 +368,7 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
} }
} }
for(i = list; i; i = i->next) { for(i = list; i; i = i->next) {
/* add the dependencies found by resolvedeps to the transaction set */
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);
@ -382,8 +383,9 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
deps = checkdeps(db_local, PM_TRANS_TYPE_UPGRADE, list); deps = checkdeps(db_local, PM_TRANS_TYPE_UPGRADE, list);
if(deps) { if(deps) {
int found; int found;
PMList *j, *k, *asked = NULL; PMList *j, *k;
int errorout = 0; int errorout = 0;
_alpm_log(PM_LOG_FLOW1, "looking for unresolvable dependencies"); _alpm_log(PM_LOG_FLOW1, "looking for unresolvable dependencies");
for(i = deps; i; i = i->next) { for(i = deps; i; i = i->next) {
pmdepmissing_t *miss = i->data; pmdepmissing_t *miss = i->data;
@ -392,21 +394,20 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
errorout = 1; errorout = 1;
} }
if((miss = (pmdepmissing_t *)malloc(sizeof(pmdepmissing_t))) == NULL) { if((miss = (pmdepmissing_t *)malloc(sizeof(pmdepmissing_t))) == NULL) {
FREELIST(deps);
FREELIST(*data); FREELIST(*data);
RET_ERR(PM_ERR_MEMORY, -1); pm_errno = PM_ERR_MEMORY;
goto error;
} }
*miss = *(pmdepmissing_t *)i->data; *miss = *(pmdepmissing_t *)i->data;
*data = pm_list_add(*data, miss); *data = pm_list_add(*data, miss);
} }
} }
if(errorout) { if(errorout) {
FREELIST(deps); pm_errno = PM_ERR_UNSATISFIED_DEPS;
RET_ERR(PM_ERR_UNSATISFIED_DEPS, -1); goto error;
} }
/* no unresolvable deps, so look for conflicts */ /* no unresolvable deps, so look for conflicts */
errorout = 0;
_alpm_log(PM_LOG_FLOW1, "looking for conflicts"); _alpm_log(PM_LOG_FLOW1, "looking for conflicts");
for(i = deps; i && !errorout; i = i->next) { for(i = deps; i && !errorout; i = i->next) {
pmdepmissing_t *miss = i->data; pmdepmissing_t *miss = i->data;
@ -482,6 +483,7 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
trans->packages = _alpm_list_remove(trans->packages, sync, ptr_cmp, (void **)&data); trans->packages = _alpm_list_remove(trans->packages, sync, ptr_cmp, (void **)&data);
} }
solved = 1; solved = 1;
FREE(rmpkg);
} }
} }
} }
@ -518,8 +520,7 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
/* 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 */ /* add miss->depend.name to the replaces list */
k = pm_list_new(); k = pm_list_add(NULL, q);
k = pm_list_add(k, q);
s->data = k; s->data = k;
} }
} }
@ -537,22 +538,22 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
} }
} }
} }
FREELIST(deps);
if(errorout) { if(errorout) {
FREELIST(deps); pm_errno = PM_ERR_CONFLICTING_DEPS;
RET_ERR(PM_ERR_CONFLICTING_DEPS, -1); goto error;
} }
} }
EVENT(trans, PM_TRANS_EVT_INTERCONFLICTS_DONE, NULL, NULL); EVENT(trans, PM_TRANS_EVT_INTERCONFLICTS_DONE, NULL, NULL);
FREELISTPTR(list); FREELISTPTR(list);
FREELISTPTR(trail); FREELISTPTR(trail);
FREELIST(asked);
} }
/* ORE /* any packages in rmtargs need to be removed from final. */
any packages in rmtargs need to be removed from final. /* rather than ripping out nodes from final, we just copy over */
rather than ripping out nodes from final, we just copy over /* our "good" nodes to a new list and reassign. */
our "good" nodes to a new list and reassign. */
/* XXX: this fails for cases where a requested package wants /* XXX: this fails for cases where a requested package wants
* a dependency that conflicts with an older version of * a dependency that conflicts with an older version of
@ -574,6 +575,7 @@ int sync_prepare(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync, PMList **
error: error:
FREELISTPTR(list); FREELISTPTR(list);
FREELISTPTR(trail); FREELISTPTR(trail);
FREELIST(asked);
FREELIST(deps); FREELIST(deps);
return(-1); return(-1);
} }
@ -584,14 +586,12 @@ int sync_commit(pmtrans_t *trans, pmdb_t *db_local)
PMList *data; PMList *data;
pmtrans_t *tr = NULL; pmtrans_t *tr = NULL;
int replaces = 0; int replaces = 0;
int removal = 0;
ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1)); ASSERT(db_local != NULL, RET_ERR(PM_ERR_DB_NULL, -1));
ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1)); ASSERT(trans != NULL, RET_ERR(PM_ERR_TRANS_NULL, -1));
/* ORE /* remove conflicting and to-be-replaced packages */
remove any conflicting packages (WITHOUT dep checks) */
/* remove to-be-replaced packages */
tr = trans_new(); tr = trans_new();
if(tr == NULL) { if(tr == NULL) {
_alpm_log(PM_LOG_ERROR, "could not create removal transaction"); _alpm_log(PM_LOG_ERROR, "could not create removal transaction");
@ -604,21 +604,28 @@ int sync_commit(pmtrans_t *trans, pmdb_t *db_local)
for(i = trans->packages; i; i = i->next) { for(i = trans->packages; i; i = i->next) {
pmsyncpkg_t *sync = i->data; pmsyncpkg_t *sync = i->data;
if(sync->type == PM_SYNC_TYPE_REPLACE) { if(sync->type == PM_SYNC_TYPE_REPLACE) {
PMList *pkgs = sync->data;
PMList *j; PMList *j;
for(j = pkgs; j; j = j->next) { for(j = sync->data; j; j = j->next) {
pmpkg_t *pkg = j->data; pmpkg_t *pkg = j->data;
if(!pkg_isin(pkg, tr->packages)) { if(!pkg_isin(pkg, tr->packages)) {
if(trans_addtarget(tr, pkg->name) == -1) { if(trans_addtarget(tr, pkg->name) == -1) {
goto error; goto error;
} }
replaces++;
} }
} }
replaces++; } else if(sync->type == PM_SYNC_TYPE_REMOVE) {
pmpkg_t *pkg = sync->data;
if(!pkg_isin(pkg, tr->packages)) {
if(trans_addtarget(tr, pkg->name) == -1) {
goto error;
}
removal++;
}
} }
} }
if(replaces) { if(replaces+removal != 0) {
_alpm_log(PM_LOG_FLOW1, "removing to-be-replaced packages"); _alpm_log(PM_LOG_FLOW1, "removing conflicting and to-be-replaced packages");
if(trans_prepare(tr, &data) == -1) { if(trans_prepare(tr, &data) == -1) {
_alpm_log(PM_LOG_ERROR, "could not prepare removal transaction"); _alpm_log(PM_LOG_ERROR, "could not prepare removal transaction");
goto error; goto error;