FAQ Search Today's Posts Mark Forums Read
» Video Reviews

» Linux Archive

Linux-archive is a website aiming to archive linux email lists and to make them easily accessible for linux users/developers.


» Sponsor

» Partners

» Sponsor

Go Back   Linux Archive > ArchLinux > ArchLinux Pacman Development

 
 
LinkBack Thread Tools
 
Old 07-05-2011, 07:20 PM
Dan McGee
 
Default Remwork -Si display logic

We did some funny stuff here before to allow specifying fully-qualified
package names, such as 'testing/gcc' or 'core/gcc'. However, it was done
by duplicating code, not to mention an early escape if a repository
could not be found for an early target. Something like `pacman -Si
foo/bar core/gcc' would not give expected results, although `pacman -Si
bar gcc' would.

Clean up the code, remove strncpy() usage, and clarify the error
messages a bit.

Signed-off-by: Dan McGee <dan@archlinux.org>
---
src/pacman/sync.c | 78 +++++++++++++++++++---------------------------------
1 files changed, 29 insertions(+), 49 deletions(-)

diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index ad6d5e5..dab4f2b 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -443,32 +443,27 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)

if(targets) {
for(i = targets; i; i = alpm_list_next(i)) {
- int foundpkg = 0;
+ const char *target = alpm_list_getdata(i);
+ char *name = strdup(target);
+ char *repo, *pkgstr;
+ int foundpkg = 0, founddb = 0;

- char target[512]; /* TODO is this enough space? */
- char *repo = NULL, *pkgstr = NULL;
-
- strncpy(target, i->data, 512);
- pkgstr = strchr(target, '/');
+ pkgstr = strchr(name, '/');
if(pkgstr) {
- alpm_db_t *db = NULL;
- repo = target;
+ repo = name;
*pkgstr = '';
++pkgstr;
+ } else {
+ repo = NULL;
+ pkgstr = name;
+ }

- for(j = syncs; j; j = alpm_list_next(j)) {
- db = alpm_list_getdata(j);
- if(strcmp(repo, alpm_db_get_name(db)) == 0) {
- break;
- }
- db = NULL;
- }
-
- if(!db) {
- pm_fprintf(stderr, ALPM_LOG_ERROR,
- _("repository '%s' does not exist
"), repo);
- return 1;
+ for(j = syncs; j; j = alpm_list_next(j)) {
+ alpm_db_t *db = alpm_list_getdata(j);
+ if(repo && strcmp(repo, alpm_db_get_name(db)) != 0) {
+ continue;
}
+ founddb = 1;

for(k = alpm_db_get_pkgcache(db); k; k = alpm_list_next(k)) {
alpm_pkg_t *pkg = alpm_list_getdata(k);
@@ -479,34 +474,19 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
break;
}
}
+ }

- if(!foundpkg) {
- pm_fprintf(stderr, ALPM_LOG_ERROR,
- _("package '%s' was not found in repository '%s'
"), pkgstr, repo);
- ret++;
- }
- } else {
- pkgstr = target;
-
- for(j = syncs; j; j = alpm_list_next(j)) {
- alpm_db_t *db = alpm_list_getdata(j);
-
- for(k = alpm_db_get_pkgcache(db); k; k = alpm_list_next(k)) {
- alpm_pkg_t *pkg = alpm_list_getdata(k);
-
- if(strcmp(alpm_pkg_get_name(pkg), pkgstr) == 0) {
- dump_pkg_full(pkg, PKG_FROM_SYNCDB, config->op_s_info > 1);
- foundpkg = 1;
- break;
- }
- }
- }
- if(!foundpkg) {
- pm_fprintf(stderr, ALPM_LOG_ERROR,
- _("package '%s' was not found
"), pkgstr);
- ret++;
- }
+ if(!founddb) {
+ pm_fprintf(stderr, ALPM_LOG_ERROR,
+ _("repository '%s' does not exist
"), repo);
+ ret++;
+ }
+ if(!foundpkg) {
+ pm_fprintf(stderr, ALPM_LOG_ERROR,
+ _("package '%s' was not found
"), target);
+ ret++;
}
+ free(name);
}
} else {
for(i = syncs; i; i = alpm_list_next(i)) {
@@ -630,7 +610,7 @@ static int process_pkg(alpm_pkg_t *pkg)
return 0;
}

-static int process_group(alpm_list_t *dbs, char *group)
+static int process_group(alpm_list_t *dbs, const char *group)
{
int ret = 0;
alpm_list_t *i;
@@ -676,7 +656,7 @@ cleanup:
return ret;
}

-static int process_targname(alpm_list_t *dblist, char *targname)
+static int process_targname(alpm_list_t *dblist, const char *targname)
{
alpm_pkg_t *pkg = alpm_find_dbs_satisfier(config->handle, dblist, targname);

@@ -695,7 +675,7 @@ static int process_targname(alpm_list_t *dblist, char *targname)
return process_group(dblist, targname);
}

-static int process_target(char *target)
+static int process_target(const char *target)
{
/* process targets */
char *targstring = strdup(target);
--
1.7.6
 

Thread Tools




All times are GMT. The time now is 11:07 AM.

VBulletin, Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2007, Crawlability, Inc.
Copyright 2007 - 2008, www.linux-archive.org