Consistently check findmatchingname() return value for error condition.

Among other this fixes 'pkg_info -e whateverpkg' exit status when
/var/db/pkg is missing: it is now 1 and not 0.
This commit is contained in:
seb 2003-03-24 21:44:45 +00:00
parent 0e5392f73f
commit 3273d1bc8b
3 changed files with 15 additions and 11 deletions

View File

@ -1,8 +1,8 @@
/* $NetBSD: main.c,v 1.33 2003/03/15 20:49:25 agc Exp $ */
/* $NetBSD: main.c,v 1.34 2003/03/24 21:44:45 seb Exp $ */
#include <sys/cdefs.h>
#ifndef lint
__RCSID("$NetBSD: main.c,v 1.33 2003/03/15 20:49:25 agc Exp $");
__RCSID("$NetBSD: main.c,v 1.34 2003/03/24 21:44:45 seb Exp $");
#endif
/*
@ -390,7 +390,7 @@ main(int argc, char *argv[])
while (*argv != NULL) {
if (ispkgpattern(*argv)) {
if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, checkpattern_fn, NULL) == 0)
if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, checkpattern_fn, NULL) <= 0)
errx(EXIT_FAILURE, "No matching pkg for %s.", *argv);
} else {
rc = chdir(*argv);

View File

@ -1,11 +1,11 @@
/* $NetBSD: main.c,v 1.33 2003/01/05 21:49:56 agc Exp $ */
/* $NetBSD: main.c,v 1.34 2003/03/24 21:44:45 seb Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static char *rcsid = "from FreeBSD Id: main.c,v 1.14 1997/10/08 07:47:26 charnier Exp";
#else
__RCSID("$NetBSD: main.c,v 1.33 2003/01/05 21:49:56 agc Exp $");
__RCSID("$NetBSD: main.c,v 1.34 2003/03/24 21:44:45 seb Exp $");
#endif
#endif
@ -238,7 +238,7 @@ main(int argc, char **argv)
errx(EXIT_FAILURE, "No matching pkg for %s.", *argv);
} else {
if (ispkgpattern(*argv)) {
if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, add_to_list_fn, &pkgs) == 0)
if (findmatchingname(_pkgdb_getPKGDB_DIR(), *argv, add_to_list_fn, &pkgs) <= 0)
errx(EXIT_FAILURE, "No matching pkg for %s.", *argv);
} else {
lpp = alloc_lpkg(*argv);

View File

@ -1,11 +1,11 @@
/* $NetBSD: perform.c,v 1.44 2003/03/15 20:49:26 agc Exp $ */
/* $NetBSD: perform.c,v 1.45 2003/03/24 21:44:46 seb Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.23 1997/10/13 15:03:53 jkh Exp";
#else
__RCSID("$NetBSD: perform.c,v 1.44 2003/03/15 20:49:26 agc Exp $");
__RCSID("$NetBSD: perform.c,v 1.45 2003/03/24 21:44:46 seb Exp $");
#endif
#endif
@ -130,7 +130,7 @@ pkg_do(char *pkg)
char try[FILENAME_MAX];
snprintf(try, FILENAME_MAX, "%s-[0-9]*", pkg);
if (findmatchingname(_pkgdb_getPKGDB_DIR(), try,
add_to_list_fn, &pkgs) != 0) {
add_to_list_fn, &pkgs) > 0) {
return 0; /* we've just appended some names to the pkgs list,
* they will be processed after this package. */
}
@ -278,7 +278,11 @@ CheckForPkg(char *pkgspec, char *dbdir)
if (strpbrk(pkgspec, "<>[]?*{")) {
/* expensive (pattern) match */
return !findmatchingname(dbdir, pkgspec, foundpkg, dbdir);
error = findmatchingname(dbdir, pkgspec, foundpkg, dbdir);
if (error == -1)
return 1;
else
return !error;
}
/* simple match */
(void) snprintf(buf, sizeof(buf), "%s/%s", dbdir, pkgspec);
@ -291,7 +295,7 @@ CheckForPkg(char *pkgspec, char *dbdir)
char try[FILENAME_MAX];
snprintf(try, FILENAME_MAX, "%s-[0-9]*", pkgspec);
if (findmatchingname(dbdir, try, foundpkg, dbdir) != 0) {
if (findmatchingname(dbdir, try, foundpkg, dbdir) > 0) {
error = 0;
}
}