summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2006-01-16 23:27:09 +0100
committerAurelien Foret <aurelien@archlinux.org>2006-01-16 23:27:09 +0100
commit6e5a62dd128b6036eaa35f9b010a35120548e3db (patch)
tree1d419961d1eb80c57aa771756f41e59da145e8db
parent9b2f0607d566bf95bbe14da6747771f7314bbbdc (diff)
downloadpacman-6e5a62dd128b6036eaa35f9b010a35120548e3db.tar.gz
pacman-6e5a62dd128b6036eaa35f9b010a35120548e3db.tar.xz
more code cleanup
-rw-r--r--lib/libalpm/add.c20
-rw-r--r--lib/libalpm/cache.c4
-rw-r--r--lib/libalpm/group.c2
-rw-r--r--lib/libalpm/remove.c37
-rw-r--r--lib/libalpm/sync.c26
5 files changed, 39 insertions, 50 deletions
diff --git a/lib/libalpm/add.c b/lib/libalpm/add.c
index d38eed7b..0e0bd899 100644
--- a/lib/libalpm/add.c
+++ b/lib/libalpm/add.c
@@ -108,13 +108,13 @@ int add_loadtarget(pmtrans_t *trans, pmdb_t *db, char *name)
return(0);
}
+ _alpm_log(PM_LOG_FLOW2, "loading target %s", name);
+
if(stat(name, &buf)) {
pm_errno = PM_ERR_NOT_A_FILE;
goto error;
}
- _alpm_log(PM_LOG_FLOW2, "loading target %s", name);
-
if(pkg_splitname(name, pkgname, pkgver) == -1) {
pm_errno = PM_ERR_PKG_INVALID_NAME;
goto error;
@@ -256,10 +256,7 @@ int add_prepare(pmtrans_t *trans, pmdb_t *db, PMList **data)
}
/* copy the file skiplist into the transaction */
- for(lp = skiplist; lp; lp = lp->next) {
- trans->skiplist = pm_list_add(trans->skiplist, lp->data);
- }
- FREELISTPTR(skiplist);
+ trans->skiplist = skiplist;
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 */
depinfo = db_get_pkgfromcache(db, ((pmpkg_t *)provides->data)->name);
FREELISTPTR(provides);
- if(depinfo == NULL) {
- /* wtf */
- continue;
- }
- } else {
+ }
+ if(depinfo == NULL) {
+ /* wtf */
continue;
}
}
depinfo->requiredby = pm_list_add(depinfo->requiredby, strdup(info->name));
_alpm_log(PM_LOG_DEBUG, "updating 'requiredby' field for package %s", depinfo->name);
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);
}
}
diff --git a/lib/libalpm/cache.c b/lib/libalpm/cache.c
index 20d3ed5b..8c8e7669 100644
--- a/lib/libalpm/cache.c
+++ b/lib/libalpm/cache.c
@@ -74,7 +74,7 @@ int db_load_pkgcache(pmdb_t *db)
void db_free_pkgcache(pmdb_t *db)
{
- if(db == NULL) {
+ if(db == NULL || db->pkgcache == NULL) {
return;
}
@@ -213,7 +213,7 @@ void db_free_grpcache(pmdb_t *db)
{
PMList *lg;
- if(db == NULL) {
+ if(db == NULL || db->grpcache == NULL) {
return;
}
diff --git a/lib/libalpm/group.c b/lib/libalpm/group.c
index 8d4a6eb1..6d24597f 100644
--- a/lib/libalpm/group.c
+++ b/lib/libalpm/group.c
@@ -29,7 +29,7 @@
pmgrp_t *grp_new()
{
- pmgrp_t* grp = NULL;
+ pmgrp_t* grp;
grp = (pmgrp_t *)malloc(sizeof(pmgrp_t));
if(grp == NULL) {
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index 3e810203..b519cdc4 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -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(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) {
_alpm_log(PM_LOG_ERROR, "could not find %s in database", name);
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);
}
+ _alpm_log(PM_LOG_FLOW2, "adding %s in the targets list", info->name);
trans->packages = pm_list_add(trans->packages, info);
return(0);
@@ -87,13 +87,16 @@ int remove_prepare(pmtrans_t *trans, pmdb_t *db, PMList **data)
if(lp != NULL) {
if(trans->flags & PM_TRANS_FLAG_CASCADE) {
while(lp) {
- PMList *j;
- for(j = lp; j; j = j->next) {
- pmdepmissing_t* miss = (pmdepmissing_t*)j->data;
- pmpkg_t *info = db_get_pkgfromcache(db, miss->depend.name);
- if(!pkg_isin(info, trans->packages)) {
- info = db_scan(db, miss->depend.name, INFRQ_ALL);
+ PMList *i;
+ for(i = lp; i; i = i->next) {
+ pmdepmissing_t *miss = (pmdepmissing_t *)i->data;
+ pmpkg_t *info = db_scan(db, miss->depend.name, INFRQ_ALL);
+ if(info) {
+ _alpm_log(PM_LOG_FLOW2, "pulling %s in the targets list", info->name);
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);
@@ -166,7 +169,7 @@ int remove_commit(pmtrans_t *trans, pmdb_t *db)
for(lp = _alpm_list_last(info->files); lp; lp = lp->prev) {
int nb = 0;
char *file = lp->data;
- char *md5 =_alpm_needbackup(lp->data, info->backup);
+ char *md5 = _alpm_needbackup(lp->data, info->backup);
if(md5) {
nb = 1;
free(md5);
@@ -201,7 +204,8 @@ int remove_commit(pmtrans_t *trans, pmdb_t *db)
}
}
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 {
/* if the file is flagged, back it up to .pacsave */
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_FLOW2, "removing database entry %s", info->name);
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) {
_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;
pmdepend_t depend;
char *data;
-
if(splitdep((char*)lp->data, &depend)) {
continue;
}
-
depinfo = db_get_pkgfromcache(db, depend.name);
if(depinfo == NULL) {
/* look for a provides package */
@@ -273,11 +275,9 @@ int remove_commit(pmtrans_t *trans, pmdb_t *db)
/* use the first one */
depinfo = db_get_pkgfromcache(db, ((pmpkg_t *)provides->data)->name);
FREELISTPTR(provides);
- if(depinfo == NULL) {
- /* wtf */
- continue;
- }
- } else {
+ }
+ if(depinfo == NULL) {
+ /* wtf */
continue;
}
}
@@ -286,7 +286,8 @@ int remove_commit(pmtrans_t *trans, pmdb_t *db)
FREE(data);
_alpm_log(PM_LOG_DEBUG, "updating 'requiredby' field for package %s", depinfo->name);
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);
}
}
diff --git a/lib/libalpm/sync.c b/lib/libalpm/sync.c
index d9df821f..45a02f2b 100644
--- a/lib/libalpm/sync.c
+++ b/lib/libalpm/sync.c
@@ -206,12 +206,7 @@ int sync_sysupgrade(pmtrans_t *trans, pmdb_t *db_local, PMList *dbs_sync)
pmsyncpkg_t *sync;
for(j = dbs_sync; !spkg && j; j = j->next) {
- for(k = db_get_pkgcache(j->data); !spkg && k; k = k->next) {
- pmpkg_t *sp = k->data;
- if(!strcmp(local->name, sp->name)) {
- spkg = sp;
- }
- }
+ spkg = db_get_pkgfromcache(j->data, local->name);
}
if(spkg == NULL) {
_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;
if(!find_pkginsync(spkg->name, trans->packages)) {
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);
_alpm_log(PM_LOG_FLOW2, "adding package %s-%s to the transaction targets",
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;
if(!strcmp(s->pkg->name, miss->target)) {
pmpkg_t *q = pkg_new(miss->depend.name, NULL);
- if(s->type == PM_SYNC_TYPE_REPLACE) {
- /* append to the replaces list */
- s->data = pm_list_add(s->data, q);
- } else {
+ if(s->type != PM_SYNC_TYPE_REPLACE) {
/* switch this sync type to REPLACE */
s->type = PM_SYNC_TYPE_REPLACE;
- /* add miss->depend.name to the replaces list */
- /* ORE - isn't the next line overwriting s->data? */
- s->data = pm_list_add(NULL, q);
+ FREEPKG(s->data);
}
+ /* append to the replaces list */
+ s->data = pm_list_add(s->data, q);
}
}
} 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) {
- _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 */
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) {
- _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);
}
}
}