Skip to content

Commit

Permalink
PR47192 + 47196 from stacktic
Browse files Browse the repository at this point in the history
  • Loading branch information
imilh committed Nov 24, 2012
1 parent 700d301 commit e56060e
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
20121124
PR47196 fixed by stacktic

20121117
PR47060 fixed by stacktic

Expand Down
25 changes: 16 additions & 9 deletions pkg_str.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Id: pkg_str.c,v 1.11 2011/10/06 16:11:52 imilh Exp $ */
/* $Id: pkg_str.c,v 1.12 2012/11/24 18:37:42 imilh Exp $ */

/*
* Copyright (c) 2009, 2010 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -42,21 +42,28 @@
char *
unique_pkg(const char *pkgname, const char *dest)
{
char *u_pkg = NULL, query[BUFSIZ];
char *u_pkg;
Plistnumbered *plist;
Pkglist *best_match, *current;

XMALLOC(u_pkg, sizeof(char) * BUFSIZ);
best_match = NULL;

/* record if it's a versionned pkgname */
if (exact_pkgfmt(pkgname))
snprintf(query, BUFSIZ, UNIQUE_EXACT_PKG, dest, pkgname);
plist = rec_pkglist(UNIQUE_EXACT_PKG, dest, pkgname);
else
snprintf(query, BUFSIZ, UNIQUE_PKG, dest, pkgname);
plist = rec_pkglist(UNIQUE_PKG, dest, pkgname);

if (pkgindb_doquery(query, pdb_get_value, u_pkg) != PDB_OK) {
XFREE(u_pkg);
if (plist == NULL)
return NULL;
}

best_match = SLIST_FIRST(plist->P_Plisthead);
SLIST_FOREACH(current, plist->P_Plisthead, next)
if (dewey_cmp(current->version, DEWEY_GT, best_match->version))
best_match = current;

XSTRDUP(u_pkg, best_match->full);
free_pkglist(&plist->P_Plisthead, LIST);
free(plist);
return u_pkg;
}

Expand Down
8 changes: 3 additions & 5 deletions pkgindb_queries.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Id: pkgindb_queries.c,v 1.26 2012/05/28 10:56:27 imilh Exp $ */
/* $Id: pkgindb_queries.c,v 1.27 2012/11/24 18:37:42 imilh Exp $ */

/*
* Copyright (c) 2009, 2010, 2011, 2012 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -177,12 +177,10 @@ const char INSERT_DEPENDS_VALUES[] =
"INSERT INTO %s (PKG_ID, %s_PKGNAME, %s_DEWEY) VALUES (%d,\"%s\",\"%s\");";

const char UNIQUE_PKG[] =
"SELECT FULLPKGNAME FROM %s WHERE PKGNAME = '%s' "
"ORDER BY PKGVERS DESC LIMIT 1;";
"SELECT FULLPKGNAME, PKGVERS FROM %s WHERE PKGNAME = '%s';";

const char UNIQUE_EXACT_PKG[] =
"SELECT FULLPKGNAME FROM %s WHERE FULLPKGNAME GLOB '%s*' "
"ORDER BY PKGVERS DESC LIMIT 1;";
"SELECT FULLPKGNAME, PKGVERS FROM %s WHERE FULLPKGNAME GLOB '%s*';";

const char EXPORT_KEEP_LIST[] =
"SELECT PKGPATH FROM LOCAL_PKG WHERE PKG_KEEP IS NOT NULL "
Expand Down
30 changes: 15 additions & 15 deletions selection.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* $Id: selection.c,v 1.5 2012/11/14 19:48:53 imilh Exp $ */
/* $Id: selection.c,v 1.6 2012/11/24 18:37:42 imilh Exp $ */

/*
* Copyright (c) 2009, 2010, 2011 The NetBSD Foundation, Inc.
Expand Down Expand Up @@ -54,7 +54,7 @@ void
import_keep(uint8_t do_inst, const char *import_file)
{
int list_size = 0;
char **pkglist = NULL;
char **pkglist = NULL, *match = NULL;
char input[BUFSIZ], fullpkgname[BUFSIZ], query[BUFSIZ];
FILE *fp;

Expand All @@ -65,24 +65,24 @@ import_keep(uint8_t do_inst, const char *import_file)
if (!isalnum((int)input[0]))
continue;

/* 1st element + NULL */
XREALLOC(pkglist, (list_size + 2) * sizeof(char *));

trimcr(&input[0]);
trimcr(input);
if (strchr(input, '/') != NULL) {
snprintf(query, BUFSIZ, GET_PKGNAME_BY_PKGPATH, input);

snprintf(query, BUFSIZ, GET_PKGNAME_BY_PKGPATH, input);
if ((pkgindb_doquery(query,
pdb_get_value, fullpkgname)) == PDB_OK)
XSTRDUP(match, fullpkgname);
} else
match = unique_pkg(input, REMOTE_PKG);

if ((pkgindb_doquery(query,
pdb_get_value, &fullpkgname[0])) == PDB_ERR) {
if (match == NULL) {
fprintf(stderr, MSG_PKG_NOT_AVAIL, input);
continue;
}

XSTRDUP(pkglist[list_size], fullpkgname);

list_size++;

pkglist[list_size] = NULL;
/* 1st element + NULL */
XREALLOC(pkglist, (list_size + 2) * sizeof(char *));
pkglist[list_size] = match;
pkglist[++list_size] = NULL;
}
fclose(fp);

Expand Down

0 comments on commit e56060e

Please sign in to comment.