summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/libalpm/alpm.c19
-rw-r--r--lib/libalpm/cache.c40
-rw-r--r--lib/libalpm/cache.h2
-rw-r--r--lib/libalpm/remove.c19
4 files changed, 46 insertions, 34 deletions
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index 31cfbc56..6c79c30b 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -193,9 +193,15 @@ pmdb_t *alpm_db_register(char *treename)
return(db);
}
+/* Helper function for comparing databases
+ */
+static int db_cmp(const void *db1, const void *db2)
+{
+ return(strcmp(((pmdb_t *)db1)->treename, ((pmdb_t *)db2)->treename));
+}
+
int alpm_db_unregister(pmdb_t *db)
{
- PMList *i;
int found = 0;
/* Sanity checks */
@@ -207,12 +213,11 @@ int alpm_db_unregister(pmdb_t *db)
handle->db_local = NULL;
found = 1;
} else {
- for(i = handle->dbs_sync; i && !found; i = i->next) {
- if(db == i->data) {
- db_close(i->data);
- handle->dbs_sync = _alpm_list_remove(handle->dbs_sync, i);
- found = 1;
- }
+ void *data;
+ handle->dbs_sync = _alpm_list_remove(handle->dbs_sync, db, db_cmp, &data);
+ if(data) {
+ db_close(data);
+ found = 1;
}
}
diff --git a/lib/libalpm/cache.c b/lib/libalpm/cache.c
index f8942002..31257c08 100644
--- a/lib/libalpm/cache.c
+++ b/lib/libalpm/cache.c
@@ -36,12 +36,20 @@
#include "db.h"
#include "cache.h"
+/* Helper function for comparing packages
+ */
+static int pkg_cmp(const void *p1, const void *p2)
+{
+ return(strcmp(((pmpkg_t *)p1)->name, ((pmpkg_t *)p2)->name));
+}
+
/* Returns a new package cache from db.
* It frees the cache if it already exists.
*/
int db_load_pkgcache(pmdb_t *db)
{
pmpkg_t *info;
+ unsigned char infolevel = INFRQ_DESC|INFRQ_DEPENDS;
if(db == NULL) {
return(-1);
@@ -49,10 +57,11 @@ int db_load_pkgcache(pmdb_t *db)
db_free_pkgcache(db);
- _alpm_log(PM_LOG_DEBUG, "loading package cache for repository \"%s\"", db->treename);
+ _alpm_log(PM_LOG_DEBUG, "loading package cache (infolevel=%#x) for repository '%s'",
+ infolevel, db->treename);
db_rewind(db);
- while((info = db_scan(db, NULL, INFRQ_DESC|INFRQ_DEPENDS)) != NULL) {
+ while((info = db_scan(db, NULL, infolevel)) != NULL) {
info->origin = PKG_FROM_CACHE;
info->data = db;
/* add to the collective */
@@ -100,7 +109,7 @@ int db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg)
if(newpkg == NULL) {
return(-1);
}
- _alpm_log(PM_LOG_DEBUG, "adding entry %s in \"%s\" cache", newpkg->name, db->treename);
+ _alpm_log(PM_LOG_DEBUG, "adding entry %s in '%s' cache", newpkg->name, db->treename);
db->pkgcache = pm_list_add_sorted(db->pkgcache, newpkg, pkg_cmp);
db_free_grpcache(db);
@@ -108,29 +117,24 @@ int db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg)
return(0);
}
-int db_remove_pkgfromcache(pmdb_t *db, char *name)
+int db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg)
{
- PMList *i;
- int found = 0;
+ pmpkg_t *data;
- if(db == NULL || name == NULL || strlen(name) == 0) {
+ if(db == NULL || pkg == NULL) {
return(-1);
}
- for(i = db->pkgcache; i && !found; i = i->next) {
- if(strcmp(((pmpkg_t *)i->data)->name, name) == 0) {
- _alpm_log(PM_LOG_DEBUG, "removing entry %s from \"%s\" cache", name, db->treename);
- db->pkgcache = _alpm_list_remove(db->pkgcache, i);
- /* ORE
- MLK: list_remove() does not free properly an entry from a packages list */
- found = 1;
- }
- }
+ db->pkgcache = _alpm_list_remove(db->pkgcache, pkg, pkg_cmp, (void **)&data);
- if(!found) {
+ if(data == NULL) {
+ /* package not found */
return(-1);
}
+ _alpm_log(PM_LOG_DEBUG, "removing entry %s from '%s' cache", pkg->name, db->treename);
+ FREEPKG(data);
+
db_free_grpcache(db);
return(0);
@@ -170,7 +174,7 @@ int db_load_grpcache(pmdb_t *db)
db_load_pkgcache(db);
}
- _alpm_log(PM_LOG_DEBUG, "loading group cache for repository \"%s\"", db->treename);
+ _alpm_log(PM_LOG_DEBUG, "loading group cache for repository '%s'", db->treename);
for(lp = db->pkgcache; lp; lp = lp->next) {
PMList *i;
diff --git a/lib/libalpm/cache.h b/lib/libalpm/cache.h
index 805d5d30..e187ec93 100644
--- a/lib/libalpm/cache.h
+++ b/lib/libalpm/cache.h
@@ -30,7 +30,7 @@
int db_load_pkgcache(pmdb_t *db);
void db_free_pkgcache(pmdb_t *db);
int db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg);
-int db_remove_pkgfromcache(pmdb_t *db, char *name);
+int db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg);
PMList *db_get_pkgcache(pmdb_t *db);
pmpkg_t *db_get_pkgfromcache(pmdb_t *db, char *target);
/* groups */
diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c
index e42035ee..a4fd59dd 100644
--- a/lib/libalpm/remove.c
+++ b/lib/libalpm/remove.c
@@ -125,6 +125,13 @@ int remove_prepare(pmtrans_t *trans, pmdb_t *db, PMList **data)
return(0);
}
+/* Helper function for comparing strings
+ */
+static int str_cmp(const void *s1, const void *s2)
+{
+ return(strcmp(s1, s2));
+}
+
int remove_commit(pmtrans_t *trans, pmdb_t *db)
{
pmpkg_t *info;
@@ -222,16 +229,16 @@ int remove_commit(pmtrans_t *trans, pmdb_t *db)
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);
}
- if(db_remove_pkgfromcache(db, info->name) == -1) {
+ if(db_remove_pkgfromcache(db, info) == -1) {
_alpm_log(PM_LOG_ERROR, "could not remove entry %s from cache", info->name);
}
/* update dependency packages' REQUIREDBY fields */
_alpm_log(PM_LOG_FLOW2, "updating dependency packages 'requiredby' fields");
for(lp = info->depends; lp; lp = lp->next) {
- PMList *j;
pmpkg_t *depinfo = NULL;
pmdepend_t depend;
+ void *ptr;
if(splitdep((char*)lp->data, &depend)) {
continue;
@@ -257,12 +264,8 @@ int remove_commit(pmtrans_t *trans, pmdb_t *db)
}
}
/* splice out this entry from requiredby */
- for(j = depinfo->requiredby; j; j = j->next) {
- if(!strcmp((char*)j->data, info->name)) {
- depinfo->requiredby = _alpm_list_remove(depinfo->requiredby, j);
- break;
- }
- }
+ depinfo->requiredby = _alpm_list_remove(depinfo->requiredby, info->name, str_cmp, &ptr);
+ FREE(ptr);
_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);