Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2008-01-12 01:13:52 -0600
committerDan McGee <dan@archlinux.org>2008-03-23 14:51:51 -0500
commitbf8670036907b3ede18d37b7a3f0f7e14542a5ac (patch)
tree8352859ea5c9f2b40fe1c091f1f23c3651db153a /lib
parent90a48c771d727e3bd231eeb1611dfcbecb88490c (diff)
Switch pmgrp_t to dynamic allocation, general group cleanup
Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib')
-rw-r--r--lib/libalpm/alpm.h2
-rw-r--r--lib/libalpm/cache.c50
-rw-r--r--lib/libalpm/group.c9
-rw-r--r--lib/libalpm/group.h11
4 files changed, 33 insertions, 39 deletions
diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 0a8812ad..25eb88c5 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -238,7 +238,7 @@ const char *alpm_delta_get_md5sum(pmdelta_t *delta);
* Groups
*/
const char *alpm_grp_get_name(const pmgrp_t *grp);
-const alpm_list_t *alpm_grp_get_pkgs(const pmgrp_t *grp);
+alpm_list_t *alpm_grp_get_pkgs(const pmgrp_t *grp);
/*
* Sync
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;
}
diff --git a/lib/libalpm/group.c b/lib/libalpm/group.c
index 050bcbd5..e9e7d008 100644
--- a/lib/libalpm/group.c
+++ b/lib/libalpm/group.c
@@ -31,13 +31,14 @@
#include "log.h"
#include "alpm.h"
-pmgrp_t *_alpm_grp_new()
+pmgrp_t *_alpm_grp_new(const char *name)
{
pmgrp_t* grp;
ALPM_LOG_FUNC;
CALLOC(grp, 1, sizeof(pmgrp_t), RET_ERR(PM_ERR_MEMORY, NULL));
+ STRDUP(grp->name, name, RET_ERR(PM_ERR_MEMORY, NULL));
return(grp);
}
@@ -50,7 +51,9 @@ void _alpm_grp_free(pmgrp_t *grp)
return;
}
- FREELIST(grp->packages);
+ FREE(grp->name);
+ /* do NOT free the contents of the list, just the nodes */
+ alpm_list_free(grp->packages);
FREE(grp);
}
@@ -74,7 +77,7 @@ const char SYMEXPORT *alpm_grp_get_name(const pmgrp_t *grp)
return grp->name;
}
-const alpm_list_t SYMEXPORT *alpm_grp_get_pkgs(const pmgrp_t *grp)
+alpm_list_t SYMEXPORT *alpm_grp_get_pkgs(const pmgrp_t *grp)
{
ALPM_LOG_FUNC;
diff --git a/lib/libalpm/group.h b/lib/libalpm/group.h
index 88fc8b32..5f8fdec4 100644
--- a/lib/libalpm/group.h
+++ b/lib/libalpm/group.h
@@ -19,17 +19,16 @@
#ifndef _ALPM_GROUP_H
#define _ALPM_GROUP_H
-/* Groups */
-#define GRP_NAME_LEN 256
-
#include "alpm.h"
struct __pmgrp_t {
- char name[GRP_NAME_LEN];
- alpm_list_t *packages; /* List of strings */
+ /** group name */
+ char *name;
+ /** list of pmpkg_t packages */
+ alpm_list_t *packages;
};
-pmgrp_t *_alpm_grp_new(void);
+pmgrp_t *_alpm_grp_new(const char *name);
void _alpm_grp_free(pmgrp_t *grp);
int _alpm_grp_cmp(const void *g1, const void *g2);