mirror of
https://github.com/moparisthebest/pacman
synced 2024-08-13 17:03:46 -04:00
Switch pmgrp_t to dynamic allocation, general group cleanup
Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
90a48c771d
commit
bf86700369
@ -238,7 +238,7 @@ const char *alpm_delta_get_md5sum(pmdelta_t *delta);
|
|||||||
* Groups
|
* Groups
|
||||||
*/
|
*/
|
||||||
const char *alpm_grp_get_name(const pmgrp_t *grp);
|
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
|
* Sync
|
||||||
|
@ -199,33 +199,29 @@ int _alpm_db_load_grpcache(pmdb_t *db)
|
|||||||
pmpkg_t *pkg = lp->data;
|
pmpkg_t *pkg = lp->data;
|
||||||
|
|
||||||
for(i = alpm_pkg_get_groups(pkg); i; i = i->next) {
|
for(i = alpm_pkg_get_groups(pkg); i; i = i->next) {
|
||||||
if(!alpm_list_find_str(db->grpcache, i->data)) {
|
const char *grpname = i->data;
|
||||||
pmgrp_t *grp = _alpm_grp_new();
|
alpm_list_t *j;
|
||||||
|
pmgrp_t *grp = NULL;
|
||||||
|
int found = 0;
|
||||||
|
|
||||||
strncpy(grp->name, i->data, GRP_NAME_LEN);
|
/* first look through the group cache for a group with this name */
|
||||||
grp->name[GRP_NAME_LEN-1] = '\0';
|
for(j = db->grpcache; j; j = j->next) {
|
||||||
grp->packages = alpm_list_add_sorted(grp->packages,
|
grp = j->data;
|
||||||
/* 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) {
|
if(strcmp(grp->name, grpname) == 0
|
||||||
pmgrp_t *grp = j->data;
|
&& !alpm_list_find_ptr(grp->packages, pkg)) {
|
||||||
|
grp->packages = alpm_list_add(grp->packages, pkg);
|
||||||
if(strcmp(grp->name, i->data) == 0) {
|
found = 1;
|
||||||
const char *pkgname = alpm_pkg_get_name(pkg);
|
break;
|
||||||
if(!alpm_list_find_str(grp->packages, pkgname)) {
|
|
||||||
grp->packages = alpm_list_add_sorted(grp->packages,
|
|
||||||
(void*)pkgname,
|
|
||||||
_alpm_str_cmp);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
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) {
|
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);
|
_alpm_grp_free(lg->data);
|
||||||
lg->data = NULL;
|
lg->data = NULL;
|
||||||
}
|
}
|
||||||
|
@ -31,13 +31,14 @@
|
|||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "alpm.h"
|
#include "alpm.h"
|
||||||
|
|
||||||
pmgrp_t *_alpm_grp_new()
|
pmgrp_t *_alpm_grp_new(const char *name)
|
||||||
{
|
{
|
||||||
pmgrp_t* grp;
|
pmgrp_t* grp;
|
||||||
|
|
||||||
ALPM_LOG_FUNC;
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
CALLOC(grp, 1, sizeof(pmgrp_t), RET_ERR(PM_ERR_MEMORY, NULL));
|
CALLOC(grp, 1, sizeof(pmgrp_t), RET_ERR(PM_ERR_MEMORY, NULL));
|
||||||
|
STRDUP(grp->name, name, RET_ERR(PM_ERR_MEMORY, NULL));
|
||||||
|
|
||||||
return(grp);
|
return(grp);
|
||||||
}
|
}
|
||||||
@ -50,7 +51,9 @@ void _alpm_grp_free(pmgrp_t *grp)
|
|||||||
return;
|
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);
|
FREE(grp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +77,7 @@ const char SYMEXPORT *alpm_grp_get_name(const pmgrp_t *grp)
|
|||||||
return grp->name;
|
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;
|
ALPM_LOG_FUNC;
|
||||||
|
|
||||||
|
@ -19,17 +19,16 @@
|
|||||||
#ifndef _ALPM_GROUP_H
|
#ifndef _ALPM_GROUP_H
|
||||||
#define _ALPM_GROUP_H
|
#define _ALPM_GROUP_H
|
||||||
|
|
||||||
/* Groups */
|
|
||||||
#define GRP_NAME_LEN 256
|
|
||||||
|
|
||||||
#include "alpm.h"
|
#include "alpm.h"
|
||||||
|
|
||||||
struct __pmgrp_t {
|
struct __pmgrp_t {
|
||||||
char name[GRP_NAME_LEN];
|
/** group name */
|
||||||
alpm_list_t *packages; /* List of strings */
|
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);
|
void _alpm_grp_free(pmgrp_t *grp);
|
||||||
int _alpm_grp_cmp(const void *g1, const void *g2);
|
int _alpm_grp_cmp(const void *g1, const void *g2);
|
||||||
|
|
||||||
|
@ -155,7 +155,6 @@ static int query_search(alpm_list_t *targets)
|
|||||||
}
|
}
|
||||||
|
|
||||||
for(i = searchlist; i; i = alpm_list_next(i)) {
|
for(i = searchlist; i; i = alpm_list_next(i)) {
|
||||||
char *group = NULL;
|
|
||||||
alpm_list_t *grp;
|
alpm_list_t *grp;
|
||||||
pmpkg_t *pkg = alpm_list_getdata(i);
|
pmpkg_t *pkg = alpm_list_getdata(i);
|
||||||
|
|
||||||
@ -176,8 +175,9 @@ static int query_search(alpm_list_t *targets)
|
|||||||
|
|
||||||
if (!config->quiet) {
|
if (!config->quiet) {
|
||||||
if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
|
if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
|
||||||
group = alpm_list_getdata(grp);
|
pmgrp_t *group = alpm_list_getdata(grp);
|
||||||
printf(" (%s)", (char *)alpm_list_getdata(grp));
|
/* TODO handle multiple groups */
|
||||||
|
printf(" (%s)", alpm_grp_get_name(group));
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we need a newline and initial indent first */
|
/* we need a newline and initial indent first */
|
||||||
@ -197,33 +197,33 @@ static int query_search(alpm_list_t *targets)
|
|||||||
static int query_group(alpm_list_t *targets)
|
static int query_group(alpm_list_t *targets)
|
||||||
{
|
{
|
||||||
alpm_list_t *i, *j;
|
alpm_list_t *i, *j;
|
||||||
char *package = NULL;
|
char *grpname = NULL;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
if(targets == NULL) {
|
if(targets == NULL) {
|
||||||
for(j = alpm_db_getgrpcache(db_local); j; j = alpm_list_next(j)) {
|
for(j = alpm_db_getgrpcache(db_local); j; j = alpm_list_next(j)) {
|
||||||
pmgrp_t *grp = alpm_list_getdata(j);
|
pmgrp_t *grp = alpm_list_getdata(j);
|
||||||
const alpm_list_t *p, *pkgnames;
|
const alpm_list_t *p, *packages;
|
||||||
const char *grpname;
|
const char *grpname;
|
||||||
|
|
||||||
grpname = alpm_grp_get_name(grp);
|
grpname = alpm_grp_get_name(grp);
|
||||||
pkgnames = alpm_grp_get_pkgs(grp);
|
packages = alpm_grp_get_pkgs(grp);
|
||||||
|
|
||||||
for(p = pkgnames; p; p = alpm_list_next(p)) {
|
for(p = packages; p; p = alpm_list_next(p)) {
|
||||||
printf("%s %s\n", grpname, (char *)alpm_list_getdata(p));
|
printf("%s %s\n", grpname, alpm_pkg_get_name(alpm_list_getdata(p)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(i = targets; i; i = alpm_list_next(i)) {
|
for(i = targets; i; i = alpm_list_next(i)) {
|
||||||
pmgrp_t *grp;
|
pmgrp_t *grp;
|
||||||
package = alpm_list_getdata(i);
|
grpname = alpm_list_getdata(i);
|
||||||
grp = alpm_db_readgrp(db_local, package);
|
grp = alpm_db_readgrp(db_local, grpname);
|
||||||
if(grp) {
|
if(grp) {
|
||||||
const alpm_list_t *p, *pkgnames = alpm_grp_get_pkgs(grp);
|
const alpm_list_t *p, *packages = alpm_grp_get_pkgs(grp);
|
||||||
for(p = pkgnames; p; p = alpm_list_next(p)) {
|
for(p = packages; p; p = alpm_list_next(p)) {
|
||||||
printf("%s %s\n", package, (char *)alpm_list_getdata(p));
|
printf("%s %s\n", grpname, alpm_pkg_get_name(alpm_list_getdata(p)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fprintf(stderr, _("error: group \"%s\" was not found\n"), package);
|
fprintf(stderr, _("error: group \"%s\" was not found\n"), grpname);
|
||||||
ret++;
|
ret++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -353,9 +353,10 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!config->quiet) {
|
if (!config->quiet) {
|
||||||
|
/* TODO package in multiple groups needs to be handled, do a loop */
|
||||||
if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
|
if((grp = alpm_pkg_get_groups(pkg)) != NULL) {
|
||||||
group = alpm_list_getdata(grp);
|
group = alpm_list_getdata(grp);
|
||||||
printf(" (%s)", (char *)alpm_list_getdata(grp));
|
printf(" (%s)", group);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* we need a newline and initial indent first */
|
/* we need a newline and initial indent first */
|
||||||
@ -375,7 +376,8 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
|
|||||||
|
|
||||||
static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
|
static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
|
||||||
{
|
{
|
||||||
alpm_list_t *i, *j;
|
alpm_list_t *i, *j, *k;
|
||||||
|
alpm_list_t *pkgnames = NULL;
|
||||||
|
|
||||||
if(targets) {
|
if(targets) {
|
||||||
for(i = targets; i; i = alpm_list_next(i)) {
|
for(i = targets; i; i = alpm_list_next(i)) {
|
||||||
@ -385,9 +387,14 @@ static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
|
|||||||
pmgrp_t *grp = alpm_db_readgrp(db, grpname);
|
pmgrp_t *grp = alpm_db_readgrp(db, grpname);
|
||||||
|
|
||||||
if(grp) {
|
if(grp) {
|
||||||
/* TODO this should be a lot cleaner, why two outputs? */
|
|
||||||
printf("%s\n", (char *)alpm_grp_get_name(grp));
|
printf("%s\n", (char *)alpm_grp_get_name(grp));
|
||||||
list_display(" ", alpm_grp_get_pkgs(grp));
|
/* get names of packages in group */
|
||||||
|
for(k = alpm_grp_get_pkgs(grp); k; k = alpm_list_next(k)) {
|
||||||
|
pkgnames = alpm_list_add(pkgnames,
|
||||||
|
(char*)alpm_pkg_get_name(k->data));
|
||||||
|
}
|
||||||
|
list_display(" ", pkgnames);
|
||||||
|
alpm_list_free(pkgnames);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -400,7 +407,12 @@ static int sync_group(int level, alpm_list_t *syncs, alpm_list_t *targets)
|
|||||||
|
|
||||||
printf("%s\n", (char *)alpm_grp_get_name(grp));
|
printf("%s\n", (char *)alpm_grp_get_name(grp));
|
||||||
if(grp && level > 1) {
|
if(grp && level > 1) {
|
||||||
list_display(" ", alpm_grp_get_pkgs(grp));
|
for(k = alpm_grp_get_pkgs(grp); k; k = alpm_list_next(k)) {
|
||||||
|
pkgnames = alpm_list_add(pkgnames,
|
||||||
|
(char*)alpm_pkg_get_name(k->data));
|
||||||
|
}
|
||||||
|
list_display(" ", pkgnames);
|
||||||
|
alpm_list_free(pkgnames);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -622,26 +634,31 @@ static int sync_trans(alpm_list_t *targets)
|
|||||||
pmdb_t *db = alpm_list_getdata(j);
|
pmdb_t *db = alpm_list_getdata(j);
|
||||||
grp = alpm_db_readgrp(db, targ);
|
grp = alpm_db_readgrp(db, targ);
|
||||||
if(grp) {
|
if(grp) {
|
||||||
alpm_list_t *k;
|
alpm_list_t *k, *pkgnames = NULL;
|
||||||
|
|
||||||
found++;
|
found++;
|
||||||
printf(_(":: group %s (including ignored packages):\n"), targ);
|
printf(_(":: group %s (including ignored packages):\n"), targ);
|
||||||
/* remove dupe entries in case a package exists in multiple repos */
|
/* remove dupe entries in case a package exists in multiple repos */
|
||||||
const alpm_list_t *grppkgs = alpm_grp_get_pkgs(grp);
|
alpm_list_t *grppkgs = alpm_grp_get_pkgs(grp);
|
||||||
alpm_list_t *pkgs = alpm_list_remove_dupes(grppkgs);
|
alpm_list_t *pkgs = alpm_list_remove_dupes(grppkgs);
|
||||||
list_display(" ", pkgs);
|
for(k = pkgs; k; k = alpm_list_next(k)) {
|
||||||
|
pkgnames = alpm_list_add(pkgnames,
|
||||||
|
(char*)alpm_pkg_get_name(k->data));
|
||||||
|
}
|
||||||
|
list_display(" ", pkgnames);
|
||||||
if(yesno(1, _(":: Install whole content?"))) {
|
if(yesno(1, _(":: Install whole content?"))) {
|
||||||
for(k = pkgs; k; k = alpm_list_next(k)) {
|
for(k = pkgnames; k; k = alpm_list_next(k)) {
|
||||||
targets = alpm_list_add(targets, strdup(alpm_list_getdata(k)));
|
targets = alpm_list_add(targets, strdup(alpm_list_getdata(k)));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for(k = pkgs; k; k = alpm_list_next(k)) {
|
for(k = pkgnames; k; k = alpm_list_next(k)) {
|
||||||
char *pkgname = alpm_list_getdata(k);
|
char *pkgname = alpm_list_getdata(k);
|
||||||
if(yesno(1, _(":: Install %s from group %s?"), pkgname, targ)) {
|
if(yesno(1, _(":: Install %s from group %s?"), pkgname, targ)) {
|
||||||
targets = alpm_list_add(targets, strdup(pkgname));
|
targets = alpm_list_add(targets, strdup(pkgname));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
alpm_list_free(pkgnames);
|
||||||
alpm_list_free(pkgs);
|
alpm_list_free(pkgs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user