1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-08-13 17:03:46 -04:00

make use of the new list_remove implementation

This commit is contained in:
Aurelien Foret 2005-05-03 17:43:02 +00:00
parent 00b97ee35f
commit 54f6a1cb12
4 changed files with 46 additions and 34 deletions

View File

@ -193,9 +193,15 @@ pmdb_t *alpm_db_register(char *treename)
return(db); 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) int alpm_db_unregister(pmdb_t *db)
{ {
PMList *i;
int found = 0; int found = 0;
/* Sanity checks */ /* Sanity checks */
@ -207,14 +213,13 @@ int alpm_db_unregister(pmdb_t *db)
handle->db_local = NULL; handle->db_local = NULL;
found = 1; found = 1;
} else { } else {
for(i = handle->dbs_sync; i && !found; i = i->next) { void *data;
if(db == i->data) { handle->dbs_sync = _alpm_list_remove(handle->dbs_sync, db, db_cmp, &data);
db_close(i->data); if(data) {
handle->dbs_sync = _alpm_list_remove(handle->dbs_sync, i); db_close(data);
found = 1; found = 1;
} }
} }
}
if(!found) { if(!found) {
RET_ERR(PM_ERR_DB_NOT_FOUND, -1); RET_ERR(PM_ERR_DB_NOT_FOUND, -1);

View File

@ -36,12 +36,20 @@
#include "db.h" #include "db.h"
#include "cache.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. /* Returns a new package cache from db.
* It frees the cache if it already exists. * It frees the cache if it already exists.
*/ */
int db_load_pkgcache(pmdb_t *db) int db_load_pkgcache(pmdb_t *db)
{ {
pmpkg_t *info; pmpkg_t *info;
unsigned char infolevel = INFRQ_DESC|INFRQ_DEPENDS;
if(db == NULL) { if(db == NULL) {
return(-1); return(-1);
@ -49,10 +57,11 @@ int db_load_pkgcache(pmdb_t *db)
db_free_pkgcache(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); 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->origin = PKG_FROM_CACHE;
info->data = db; info->data = db;
/* add to the collective */ /* add to the collective */
@ -100,7 +109,7 @@ int db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg)
if(newpkg == NULL) { if(newpkg == NULL) {
return(-1); 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->pkgcache = pm_list_add_sorted(db->pkgcache, newpkg, pkg_cmp);
db_free_grpcache(db); db_free_grpcache(db);
@ -108,29 +117,24 @@ int db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg)
return(0); return(0);
} }
int db_remove_pkgfromcache(pmdb_t *db, char *name) int db_remove_pkgfromcache(pmdb_t *db, pmpkg_t *pkg)
{ {
PMList *i; pmpkg_t *data;
int found = 0;
if(db == NULL || name == NULL || strlen(name) == 0) { if(db == NULL || pkg == NULL) {
return(-1); return(-1);
} }
for(i = db->pkgcache; i && !found; i = i->next) { db->pkgcache = _alpm_list_remove(db->pkgcache, pkg, pkg_cmp, (void **)&data);
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;
}
}
if(!found) { if(data == NULL) {
/* package not found */
return(-1); return(-1);
} }
_alpm_log(PM_LOG_DEBUG, "removing entry %s from '%s' cache", pkg->name, db->treename);
FREEPKG(data);
db_free_grpcache(db); db_free_grpcache(db);
return(0); return(0);
@ -170,7 +174,7 @@ int db_load_grpcache(pmdb_t *db)
db_load_pkgcache(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) { for(lp = db->pkgcache; lp; lp = lp->next) {
PMList *i; PMList *i;

View File

@ -30,7 +30,7 @@
int db_load_pkgcache(pmdb_t *db); int db_load_pkgcache(pmdb_t *db);
void db_free_pkgcache(pmdb_t *db); void db_free_pkgcache(pmdb_t *db);
int db_add_pkgincache(pmdb_t *db, pmpkg_t *pkg); 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); PMList *db_get_pkgcache(pmdb_t *db);
pmpkg_t *db_get_pkgfromcache(pmdb_t *db, char *target); pmpkg_t *db_get_pkgfromcache(pmdb_t *db, char *target);
/* groups */ /* groups */

View File

@ -125,6 +125,13 @@ int remove_prepare(pmtrans_t *trans, pmdb_t *db, PMList **data)
return(0); 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) int remove_commit(pmtrans_t *trans, pmdb_t *db)
{ {
pmpkg_t *info; pmpkg_t *info;
@ -222,16 +229,16 @@ int remove_commit(pmtrans_t *trans, pmdb_t *db)
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-%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); _alpm_log(PM_LOG_ERROR, "could not remove entry %s from cache", info->name);
} }
/* update dependency packages' REQUIREDBY fields */ /* update dependency packages' REQUIREDBY fields */
_alpm_log(PM_LOG_FLOW2, "updating dependency packages 'requiredby' fields"); _alpm_log(PM_LOG_FLOW2, "updating dependency packages 'requiredby' fields");
for(lp = info->depends; lp; lp = lp->next) { for(lp = info->depends; lp; lp = lp->next) {
PMList *j;
pmpkg_t *depinfo = NULL; pmpkg_t *depinfo = NULL;
pmdepend_t depend; pmdepend_t depend;
void *ptr;
if(splitdep((char*)lp->data, &depend)) { if(splitdep((char*)lp->data, &depend)) {
continue; continue;
@ -257,12 +264,8 @@ int remove_commit(pmtrans_t *trans, pmdb_t *db)
} }
} }
/* splice out this entry from requiredby */ /* splice out this entry from requiredby */
for(j = depinfo->requiredby; j; j = j->next) { depinfo->requiredby = _alpm_list_remove(depinfo->requiredby, info->name, str_cmp, &ptr);
if(!strcmp((char*)j->data, info->name)) { FREE(ptr);
depinfo->requiredby = _alpm_list_remove(depinfo->requiredby, j);
break;
}
}
_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-%s", db->treename, depinfo->name, depinfo->version);