summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorjoerg <joerg>2007-08-12 22:09:02 +0000
committerjoerg <joerg>2007-08-12 22:09:02 +0000
commit137a265f7811c9a9efe77a7102a7490b01c909a1 (patch)
tree001f7de164666ac001930305faf6ce75195e2a34 /pkgtools
parentaed03e49e42d43dabeda1c6a07fe771dd45879a6 (diff)
downloadpkgsrc-137a265f7811c9a9efe77a7102a7490b01c909a1.tar.gz
pkg_admin: when retrying with a wildcard pattern, use the computed
pattern and not the base name. pkg_info: add -E option to return the best matching installed package. Bump to 20070813.
Diffstat (limited to 'pkgtools')
-rw-r--r--pkgtools/pkg_install/files/admin/main.c8
-rw-r--r--pkgtools/pkg_install/files/info/info.h6
-rw-r--r--pkgtools/pkg_install/files/info/main.c56
-rw-r--r--pkgtools/pkg_install/files/info/perform.c42
-rw-r--r--pkgtools/pkg_install/files/info/pkg_info.119
-rw-r--r--pkgtools/pkg_install/files/info/pkg_info.cat120
-rw-r--r--pkgtools/pkg_install/files/lib/version.h4
7 files changed, 117 insertions, 38 deletions
diff --git a/pkgtools/pkg_install/files/admin/main.c b/pkgtools/pkg_install/files/admin/main.c
index dae985dee42..5c4468246a6 100644
--- a/pkgtools/pkg_install/files/admin/main.c
+++ b/pkgtools/pkg_install/files/admin/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.28 2007/08/12 18:54:08 joerg Exp $ */
+/* $NetBSD: main.c,v 1.29 2007/08/12 22:09:02 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -8,7 +8,7 @@
#include <sys/cdefs.h>
#endif
#ifndef lint
-__RCSID("$NetBSD: main.c,v 1.28 2007/08/12 18:54:08 joerg Exp $");
+__RCSID("$NetBSD: main.c,v 1.29 2007/08/12 22:09:02 joerg Exp $");
#endif
/*
@@ -658,7 +658,7 @@ main(int argc, char *argv[])
if (asprintf(&pattern, "%s-[0-9]*", *argv) == -1)
errx(EXIT_FAILURE, "asprintf failed");
- if (match_installed_pkgs(*argv, checkpattern_fn, &got_match) == -1)
+ if (match_installed_pkgs(pattern, checkpattern_fn, &got_match) == -1)
errx(EXIT_FAILURE, "Cannot process pkdbdb");
if (got_match == 0)
@@ -915,7 +915,7 @@ set_unset_variable(char **argv, Boolean unset)
if (asprintf(&pattern, "%s-[0-9]*", *argv) == -1)
errx(EXIT_FAILURE, "asprintf failed");
- if (match_installed_pkgs(*argv, set_installed_info_var, &arg) == -1)
+ if (match_installed_pkgs(pattern, set_installed_info_var, &arg) == -1)
errx(EXIT_FAILURE, "Cannot process pkdbdb");
if (arg.got_match == 0) {
diff --git a/pkgtools/pkg_install/files/info/info.h b/pkgtools/pkg_install/files/info/info.h
index f09890726de..994f1672481 100644
--- a/pkgtools/pkg_install/files/info/info.h
+++ b/pkgtools/pkg_install/files/info/info.h
@@ -1,4 +1,4 @@
-/* $NetBSD: info.h,v 1.15 2007/08/09 23:54:17 joerg Exp $ */
+/* $NetBSD: info.h,v 1.16 2007/08/12 22:09:02 joerg Exp $ */
/* from FreeBSD Id: info.h,v 1.10 1997/02/22 16:09:40 peter Exp */
@@ -67,10 +67,12 @@ extern char *InfoPrefix;
extern char *BuildInfoVariable;
extern char PlayPen[];
extern size_t PlayPenSize;
-extern char *CheckPkg;
extern size_t termwidth;
extern lpkg_head_t pkgs;
+int CheckForPkg(const char *);
+int CheckForBestPkg(const char *);
+
extern void show_file(const char *, const char *, const char *, Boolean);
extern void show_var(const char *, const char *, const char *);
extern void show_plist(const char *, package_t *, pl_ent_t);
diff --git a/pkgtools/pkg_install/files/info/main.c b/pkgtools/pkg_install/files/info/main.c
index 069e7b92236..fbf0a574732 100644
--- a/pkgtools/pkg_install/files/info/main.c
+++ b/pkgtools/pkg_install/files/info/main.c
@@ -1,4 +1,4 @@
-/* $NetBSD: main.c,v 1.18 2007/08/08 22:33:39 joerg Exp $ */
+/* $NetBSD: main.c,v 1.19 2007/08/12 22:09:02 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#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.18 2007/08/08 22:33:39 joerg Exp $");
+__RCSID("$NetBSD: main.c,v 1.19 2007/08/12 22:09:02 joerg Exp $");
#endif
#endif
@@ -50,7 +50,7 @@ __RCSID("$NetBSD: main.c,v 1.18 2007/08/08 22:33:39 joerg Exp $");
#include "lib.h"
#include "info.h"
-static const char Options[] = ".aBbcDde:fFhIiK:kLl:mNnpQ:qRsSuvVX";
+static const char Options[] = ".aBbcDde:E:fFhIiK:kLl:mNnpQ:qRsSuvVX";
int Flags = 0;
enum which Which = WHICH_LIST;
@@ -60,7 +60,6 @@ char *InfoPrefix = "";
char *BuildInfoVariable = "";
char PlayPen[MaxPathSize];
size_t PlayPenSize = sizeof(PlayPen);
-char *CheckPkg = NULL;
size_t termwidth = 0;
lpkg_head_t pkgs;
@@ -78,6 +77,8 @@ usage(void)
int
main(int argc, char **argv)
{
+ char *CheckPkg = NULL;
+ char *BestCheckPkg = NULL;
lpkg_t *lpp;
int ch;
int rc;
@@ -112,6 +113,10 @@ main(int argc, char **argv)
Flags |= SHOW_DESC;
break;
+ case 'E':
+ BestCheckPkg = optarg;
+ break;
+
case 'e':
CheckPkg = optarg;
break;
@@ -223,6 +228,21 @@ main(int argc, char **argv)
Which = WHICH_ALL;
}
+ if (CheckPkg != NULL && BestCheckPkg != NULL) {
+ warnx("-E and -e are mutally exlusive");
+ usage();
+ }
+
+ if (argc != 0 && CheckPkg != NULL) {
+ warnx("can't give any additional arguments to -e");
+ usage();
+ }
+
+ if (argc != 0 && BestCheckPkg != NULL) {
+ warnx("can't give any additional arguments to -E");
+ usage();
+ }
+
if (argc != 0 && Which != WHICH_LIST) {
warnx("can't use both -a/-u and package name");
usage();
@@ -242,23 +262,29 @@ main(int argc, char **argv)
| SHOW_DEPENDS | SHOW_DISPLAY;
/* -Fe /filename -> change CheckPkg to real packagename */
- if (CheckPkg && File2Pkg) {
- char *s;
+ if (CheckPkg) {
+ if (File2Pkg) {
+ char *s;
- if (!pkgdb_open(ReadOnly))
- err(EXIT_FAILURE, "cannot open pkgdb");
+ if (!pkgdb_open(ReadOnly))
+ err(EXIT_FAILURE, "cannot open pkgdb");
- s = pkgdb_retrieve(CheckPkg);
+ s = pkgdb_retrieve(CheckPkg);
- if (s) {
- CheckPkg = strdup(s);
- } else {
- errx(EXIT_FAILURE, "No matching pkg for %s.", CheckPkg);
- }
+ if (s) {
+ CheckPkg = strdup(s);
+ } else {
+ errx(EXIT_FAILURE, "No matching pkg for %s.", CheckPkg);
+ }
- pkgdb_close();
+ pkgdb_close();
+ }
+ return CheckForPkg(CheckPkg);
}
+ if (BestCheckPkg)
+ return CheckForBestPkg(BestCheckPkg);
+
TAILQ_INIT(&pkgs);
/* Get all the remaining package names, if any */
diff --git a/pkgtools/pkg_install/files/info/perform.c b/pkgtools/pkg_install/files/info/perform.c
index ddedd47797c..420cd65cfae 100644
--- a/pkgtools/pkg_install/files/info/perform.c
+++ b/pkgtools/pkg_install/files/info/perform.c
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.39 2007/08/10 21:43:58 joerg Exp $ */
+/* $NetBSD: perform.c,v 1.40 2007/08/12 22:09:02 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -14,7 +14,7 @@
#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.39 2007/08/10 21:43:58 joerg Exp $");
+__RCSID("$NetBSD: perform.c,v 1.40 2007/08/12 22:09:02 joerg Exp $");
#endif
#endif
@@ -341,7 +341,7 @@ print_matching_pkg(const char *pkgname, void *cookie)
*
* If -q was not specified, print all matching packages to stdout.
*/
-static int
+int
CheckForPkg(const char *pkgname)
{
struct print_matching_arg arg;
@@ -377,6 +377,37 @@ CheckForPkg(const char *pkgname)
return 1;
}
+/*
+ * Returns 0 if at least one package matching pkgname.
+ * Returns 1 otherwise.
+ *
+ * If -q was not specified, print best match to stdout.
+ */
+int
+CheckForBestPkg(const char *pkgname)
+{
+ char *pattern, *best_match;
+
+ best_match = find_best_matching_installed_pkg(pkgname);
+ if (best_match == NULL) {
+ if (ispkgpattern(pkgname))
+ return 1;
+
+ if (asprintf(&pattern, "%s-[0-9]*", pkgname) == -1)
+ errx(EXIT_FAILURE, "asprintf failed");
+
+ best_match = find_best_matching_installed_pkg(pattern);
+ free(pattern);
+ }
+
+ if (best_match == NULL)
+ return 1;
+ if (!Quiet)
+ puts(best_match);
+ free(best_match);
+ return 0;
+}
+
void
cleanup(int sig)
{
@@ -404,10 +435,7 @@ pkg_perform(lpkg_head_t *pkghead)
TAILQ_INIT(&files);
- /* Overriding action? */
- if (CheckPkg) {
- err_cnt += CheckForPkg(CheckPkg);
- } else if (Which != WHICH_LIST) {
+ if (Which != WHICH_LIST) {
if (File2Pkg) {
/* Show all files with the package they belong to */
if (pkgdb_dump() == -1)
diff --git a/pkgtools/pkg_install/files/info/pkg_info.1 b/pkgtools/pkg_install/files/info/pkg_info.1
index 27d26c9bb29..0b8a4cff087 100644
--- a/pkgtools/pkg_install/files/info/pkg_info.1
+++ b/pkgtools/pkg_install/files/info/pkg_info.1
@@ -1,4 +1,4 @@
-.\" $NetBSD: pkg_info.1,v 1.20 2007/07/26 11:30:56 joerg Exp $
+.\" $NetBSD: pkg_info.1,v 1.21 2007/08/12 22:09:02 joerg Exp $
.\"
.\" FreeBSD install - a package for the installation and maintenance
.\" of non-core utilities.
@@ -27,6 +27,7 @@
.Nm
.Op Fl BbcDdFfhIikLmNnpqRrSsVvX
.Op Fl e Ar package
+.Op Fl E Ar package
.Op Fl K Ar pkg_dbdir
.Op Fl l Ar prefix
.Ar pkg-name ...
@@ -86,10 +87,24 @@ Show the one-line comment field for each package.
Show the install-message file (if any) for each package.
.It Fl d
Show the long-description field for each package.
+.It Fl E Ar pkg-name
+This option
+allows you to test for the existence of a given package.
+If a package identified by
+.Ar pkg-name
+is currently installed, return code is 0, otherwise 1.
+The name of the best matching package found installed is printed to
+stdout unless turned off using the
+.Fl q
+option.
+.Ar pkg-name
+can contain wildcards (see the
+.Sx PACKAGE WILDCARDS
+section below).
.It Fl e Ar pkg-name
This option
allows you to test for the existence of a given package.
-If the package identified by
+If a package identified by
.Ar pkg-name
is currently installed, return code is 0, otherwise 1.
The names of any package(s) found installed are printed to
diff --git a/pkgtools/pkg_install/files/info/pkg_info.cat1 b/pkgtools/pkg_install/files/info/pkg_info.cat1
index dc510aa1a58..239cbb18413 100644
--- a/pkgtools/pkg_install/files/info/pkg_info.cat1
+++ b/pkgtools/pkg_install/files/info/pkg_info.cat1
@@ -4,8 +4,8 @@ NNAAMMEE
ppkkgg__iinnffoo -- a utility for displaying information on software packages
SSYYNNOOPPSSIISS
- ppkkgg__iinnffoo [--BBbbccDDddFFffhhIIiikkLLmmNNnnppqqRRrrSSssVVvvXX] [--ee _p_a_c_k_a_g_e] [--KK _p_k_g___d_b_d_i_r]
- [--ll _p_r_e_f_i_x] _p_k_g_-_n_a_m_e _._._.
+ ppkkgg__iinnffoo [--BBbbccDDddFFffhhIIiikkLLmmNNnnppqqRRrrSSssVVvvXX] [--ee _p_a_c_k_a_g_e] [--EE _p_a_c_k_a_g_e]
+ [--KK _p_k_g___d_b_d_i_r] [--ll _p_r_e_f_i_x] _p_k_g_-_n_a_m_e _._._.
ppkkgg__iinnffoo [--aa | --uu] [flags]
ppkkgg__iinnffoo [--QQ _v_a_r_i_a_b_l_e] _p_k_g_-_n_a_m_e _._._.
@@ -42,14 +42,22 @@ DDEESSCCRRIIPPTTIIOONN
--dd Show the long-description field for each package.
- --ee _p_k_g_-_n_a_m_e
+ --EE _p_k_g_-_n_a_m_e
This option allows you to test for the existence of a given pack-
- age. If the package identified by _p_k_g_-_n_a_m_e is currently
- installed, return code is 0, otherwise 1. The names of any pack-
- age(s) found installed are printed to stdout unless turned off
+ age. If a package identified by _p_k_g_-_n_a_m_e is currently installed,
+ return code is 0, otherwise 1. The name of the best matching
+ package found installed is printed to stdout unless turned off
using the --qq option. _p_k_g_-_n_a_m_e can contain wildcards (see the
_P_A_C_K_A_G_E _W_I_L_D_C_A_R_D_S section below).
+ --ee _p_k_g_-_n_a_m_e
+ This option allows you to test for the existence of a given pack-
+ age. If a package identified by _p_k_g_-_n_a_m_e is currently installed,
+ return code is 0, otherwise 1. The names of any package(s) found
+ installed are printed to stdout unless turned off using the --qq
+ option. _p_k_g_-_n_a_m_e can contain wildcards (see the _P_A_C_K_A_G_E
+ _W_I_L_D_C_A_R_D_S section below).
+
--FF Interpret any pkg-name given as filename, and translate it to a
package name using the Package Database. This can be used to
query information on a per-file basis, e.g. in conjunction with
diff --git a/pkgtools/pkg_install/files/lib/version.h b/pkgtools/pkg_install/files/lib/version.h
index f6bd8722927..08be3404bc4 100644
--- a/pkgtools/pkg_install/files/lib/version.h
+++ b/pkgtools/pkg_install/files/lib/version.h
@@ -1,4 +1,4 @@
-/* $NetBSD: version.h,v 1.76 2007/08/12 16:47:19 joerg Exp $ */
+/* $NetBSD: version.h,v 1.77 2007/08/12 22:09:02 joerg Exp $ */
/*
* Copyright (c) 2001 Thomas Klausner. All rights reserved.
@@ -33,6 +33,6 @@
#ifndef _INST_LIB_VERSION_H_
#define _INST_LIB_VERSION_H_
-#define PKGTOOLS_VERSION "20070812"
+#define PKGTOOLS_VERSION "20070813"
#endif /* _INST_LIB_VERSION_H_ */