pkgsrc-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[pkgsrc/trunk]: pkgsrc/pkgtools/pkg_install/files pkg_admin: when retrying wi...



details:   https://anonhg.NetBSD.org/pkgsrc/rev/c493c9202982
branches:  trunk
changeset: 532150:c493c9202982
user:      joerg <joerg%pkgsrc.org@localhost>
date:      Sun Aug 12 22:09:02 2007 +0000

description:
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:

 pkgtools/pkg_install/files/admin/main.c       |   8 +-
 pkgtools/pkg_install/files/info/info.h        |   6 +-
 pkgtools/pkg_install/files/info/main.c        |  56 +++++++++++++++++++-------
 pkgtools/pkg_install/files/info/perform.c     |  42 ++++++++++++++++---
 pkgtools/pkg_install/files/info/pkg_info.1    |  19 ++++++++-
 pkgtools/pkg_install/files/info/pkg_info.cat1 |  22 +++++++---
 pkgtools/pkg_install/files/lib/version.h      |   4 +-
 7 files changed, 118 insertions(+), 39 deletions(-)

diffs (truncated from 354 to 300 lines):

diff -r 9a0a44f48685 -r c493c9202982 pkgtools/pkg_install/files/admin/main.c
--- a/pkgtools/pkg_install/files/admin/main.c   Sun Aug 12 21:53:42 2007 +0000
+++ b/pkgtools/pkg_install/files/admin/main.c   Sun Aug 12 22:09:02 2007 +0000
@@ -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 @@
                                        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 @@
                                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 -r 9a0a44f48685 -r c493c9202982 pkgtools/pkg_install/files/info/info.h
--- a/pkgtools/pkg_install/files/info/info.h    Sun Aug 12 21:53:42 2007 +0000
+++ b/pkgtools/pkg_install/files/info/info.h    Sun Aug 12 22:09:02 2007 +0000
@@ -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 *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 -r 9a0a44f48685 -r c493c9202982 pkgtools/pkg_install/files/info/main.c
--- a/pkgtools/pkg_install/files/info/main.c    Sun Aug 12 21:53:42 2007 +0000
+++ b/pkgtools/pkg_install/files/info/main.c    Sun Aug 12 22:09:02 2007 +0000
@@ -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 @@
 #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   *BuildInfoVariable = "";
 char    PlayPen[MaxPathSize];
 size_t  PlayPenSize = sizeof(PlayPen);
-char   *CheckPkg = NULL;
 size_t  termwidth = 0;
 lpkg_head_t pkgs;
 
@@ -78,6 +77,8 @@
 int
 main(int argc, char **argv)
 {
+       char *CheckPkg = NULL;
+       char *BestCheckPkg = NULL;
        lpkg_t *lpp;
        int     ch;
        int     rc;
@@ -112,6 +113,10 @@
                        Flags |= SHOW_DESC;
                        break;
 
+               case 'E':
+                       BestCheckPkg = optarg;
+                       break;
+
                case 'e':
                        CheckPkg = optarg;
                        break;
@@ -223,6 +228,21 @@
                        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,22 +262,28 @@
                        | 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();
                }
+               return CheckForPkg(CheckPkg);
+       }
 
-               pkgdb_close();
-       }
+       if (BestCheckPkg)
+               return CheckForBestPkg(BestCheckPkg);
 
        TAILQ_INIT(&pkgs);
 
diff -r 9a0a44f48685 -r c493c9202982 pkgtools/pkg_install/files/info/perform.c
--- a/pkgtools/pkg_install/files/info/perform.c Sun Aug 12 21:53:42 2007 +0000
+++ b/pkgtools/pkg_install/files/info/perform.c Sun Aug 12 22:09:02 2007 +0000
@@ -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 @@
  *
  * 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 @@
                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 @@
 
        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 -r 9a0a44f48685 -r c493c9202982 pkgtools/pkg_install/files/info/pkg_info.1
--- a/pkgtools/pkg_install/files/info/pkg_info.1        Sun Aug 12 21:53:42 2007 +0000
+++ b/pkgtools/pkg_install/files/info/pkg_info.1        Sun Aug 12 22:09:02 2007 +0000
@@ -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 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 -r 9a0a44f48685 -r c493c9202982 pkgtools/pkg_install/files/info/pkg_info.cat1
--- a/pkgtools/pkg_install/files/info/pkg_info.cat1     Sun Aug 12 21:53:42 2007 +0000
+++ b/pkgtools/pkg_install/files/info/pkg_info.cat1     Sun Aug 12 22:09:02 2007 +0000
@@ -4,8 +4,8 @@



Home | Main Index | Thread Index | Old Index