diff options
author | Dan McGee <dan@archlinux.org> | 2008-01-12 08:13:52 +0100 |
---|---|---|
committer | Dan McGee <dan@archlinux.org> | 2008-03-23 20:51:51 +0100 |
commit | bf8670036907b3ede18d37b7a3f0f7e14542a5ac (patch) | |
tree | 8352859ea5c9f2b40fe1c091f1f23c3651db153a /lib/libalpm/cache.c | |
parent | 90a48c771d727e3bd231eeb1611dfcbecb88490c (diff) | |
download | pacman-bf8670036907b3ede18d37b7a3f0f7e14542a5ac.tar.gz pacman-bf8670036907b3ede18d37b7a3f0f7e14542a5ac.tar.xz |
Switch pmgrp_t to dynamic allocation, general group cleanup
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/cache.c')
-rw-r--r-- | lib/libalpm/cache.c | 50 |
1 files changed, 21 insertions, 29 deletions
diff --git a/lib/libalpm/cache.c b/lib/libalpm/cache.c index 09fa74c2..7fa24052 100644 --- a/lib/libalpm/cache.c +++ b/lib/libalpm/cache.c @@ -199,33 +199,29 @@ int _alpm_db_load_grpcache(pmdb_t *db) pmpkg_t *pkg = lp->data; for(i = alpm_pkg_get_groups(pkg); i; i = i->next) { - if(!alpm_list_find_str(db->grpcache, i->data)) { - pmgrp_t *grp = _alpm_grp_new(); - - strncpy(grp->name, i->data, GRP_NAME_LEN); - grp->name[GRP_NAME_LEN-1] = '\0'; - grp->packages = alpm_list_add_sorted(grp->packages, - /* gross signature forces us to - * discard const */ - (void*)alpm_pkg_get_name(pkg), - _alpm_str_cmp); - db->grpcache = alpm_list_add_sorted(db->grpcache, grp, _alpm_grp_cmp); - } else { - alpm_list_t *j; - - for(j = db->grpcache; j; j = j->next) { - pmgrp_t *grp = j->data; - - if(strcmp(grp->name, i->data) == 0) { - const char *pkgname = alpm_pkg_get_name(pkg); - if(!alpm_list_find_str(grp->packages, pkgname)) { - grp->packages = alpm_list_add_sorted(grp->packages, - (void*)pkgname, - _alpm_str_cmp); - } - } + const char *grpname = i->data; + alpm_list_t *j; + pmgrp_t *grp = NULL; + int found = 0; + + /* first look through the group cache for a group with this name */ + for(j = db->grpcache; j; j = j->next) { + grp = j->data; + + if(strcmp(grp->name, grpname) == 0 + && !alpm_list_find_ptr(grp->packages, pkg)) { + grp->packages = alpm_list_add(grp->packages, pkg); + found = 1; + break; } } + if(found) { + continue; + } + /* we didn't find the group, so create a new one with this name */ + grp = _alpm_grp_new(grpname); + grp->packages = alpm_list_add(grp->packages, pkg); + db->grpcache = alpm_list_add(db->grpcache, grp); } } @@ -243,10 +239,6 @@ void _alpm_db_free_grpcache(pmdb_t *db) } for(lg = db->grpcache; lg; lg = lg->next) { - pmgrp_t *grp = lg->data; - - alpm_list_free(grp->packages); - grp->packages = NULL; _alpm_grp_free(lg->data); lg->data = NULL; } |