From c94d3e89cbbe8f1330ddfafc99d81c4c54053282 Mon Sep 17 00:00:00 2001 From: hubertf Date: Thu, 19 Aug 1999 19:37:20 +0000 Subject: [PATCH] Allow specifying a package name without a version. If no (installed) package is found with the given name, "-[0-9]*" is appended, and the search retried. Withs with any options to pkg_delete and (esp.) pkg_info: pkg_info kde pkg_info -e emacs pkg_info -qL xlock pkg_delete -v emacs --- usr.sbin/pkg_install/delete/delete.h | 4 ++- usr.sbin/pkg_install/delete/main.c | 6 ++-- usr.sbin/pkg_install/delete/perform.c | 19 ++++++++-- usr.sbin/pkg_install/delete/pkg_delete.1 | 5 +-- usr.sbin/pkg_install/info/info.h | 4 ++- usr.sbin/pkg_install/info/main.c | 6 ++-- usr.sbin/pkg_install/info/perform.c | 46 +++++++++++++++++++----- usr.sbin/pkg_install/info/pkg_info.1 | 9 ++--- 8 files changed, 74 insertions(+), 25 deletions(-) diff --git a/usr.sbin/pkg_install/delete/delete.h b/usr.sbin/pkg_install/delete/delete.h index bbe51193d337..ec5046e3cda2 100644 --- a/usr.sbin/pkg_install/delete/delete.h +++ b/usr.sbin/pkg_install/delete/delete.h @@ -1,4 +1,4 @@ -/* $NetBSD: delete.h,v 1.4 1999/03/08 00:20:21 hubertf Exp $ */ +/* $NetBSD: delete.h,v 1.5 1999/08/19 19:37:20 hubertf Exp $ */ /* from FreeBSD Id: delete.h,v 1.4 1997/02/22 16:09:35 peter Exp */ @@ -33,4 +33,6 @@ extern Boolean Force; extern Boolean Recurse_up; extern Boolean Recurse_down; +extern int find_fn(const char *pkg, char *data); + #endif /* _INST_DELETE_H_INCLUDE */ diff --git a/usr.sbin/pkg_install/delete/main.c b/usr.sbin/pkg_install/delete/main.c index cc1308bb51f8..30f4edce34a9 100644 --- a/usr.sbin/pkg_install/delete/main.c +++ b/usr.sbin/pkg_install/delete/main.c @@ -1,11 +1,11 @@ -/* $NetBSD: main.c,v 1.11 1999/03/22 05:02:40 hubertf Exp $ */ +/* $NetBSD: main.c,v 1.12 1999/08/19 19:37:21 hubertf Exp $ */ #include #ifndef lint #if 0 static char *rcsid = "from FreeBSD Id: main.c,v 1.11 1997/10/08 07:46:48 charnier Exp"; #else -__RCSID("$NetBSD: main.c,v 1.11 1999/03/22 05:02:40 hubertf Exp $"); +__RCSID("$NetBSD: main.c,v 1.12 1999/08/19 19:37:21 hubertf Exp $"); #endif #endif @@ -54,7 +54,7 @@ usage(void) exit(1); } -static int +int find_fn(const char *pkg, char *data) { lpkg_t *lpp; diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c index fe0a4bd21a41..c4620ff405e5 100644 --- a/usr.sbin/pkg_install/delete/perform.c +++ b/usr.sbin/pkg_install/delete/perform.c @@ -1,11 +1,11 @@ -/* $NetBSD: perform.c,v 1.23 1999/03/22 06:04:16 abs Exp $ */ +/* $NetBSD: perform.c,v 1.24 1999/08/19 19:37:21 hubertf Exp $ */ #include #ifndef lint #if 0 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.15 1997/10/13 15:03:52 jkh Exp"; #else -__RCSID("$NetBSD: perform.c,v 1.23 1999/03/22 06:04:16 abs Exp $"); +__RCSID("$NetBSD: perform.c,v 1.24 1999/08/19 19:37:21 hubertf Exp $"); #endif #endif @@ -475,6 +475,21 @@ pkg_do(char *pkg) (void) snprintf(LogDir, sizeof(LogDir), "%s/%s", (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR, pkg); if (!fexists(LogDir) || !isdir(LogDir)) { + { + /* Check if the given package name matches something + * with 'pkg-[0-9]*' + */ + char try[FILENAME_MAX]; + snprintf(try, FILENAME_MAX, "%s-[0-9]*", pkg); + if (findmatchingname(_pkgdb_getPKGDB_DIR(), try, + find_fn, NULL) != 0) { + return 0; /* we've just appended some names to the pkgs list, + * they will be processed after this package. + */ + } + } + + /* No match */ warnx("no such package '%s' installed", pkg); return 1; } diff --git a/usr.sbin/pkg_install/delete/pkg_delete.1 b/usr.sbin/pkg_install/delete/pkg_delete.1 index 6683369c6f05..04d660393c74 100644 --- a/usr.sbin/pkg_install/delete/pkg_delete.1 +++ b/usr.sbin/pkg_install/delete/pkg_delete.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_delete.1,v 1.12 1999/03/22 18:44:03 garbled Exp $ +.\" $NetBSD: pkg_delete.1,v 1.13 1999/08/19 19:37:21 hubertf Exp $ .\" .\" FreeBSD install - a package for the installation and maintainance .\" of non-core utilities. @@ -70,7 +70,8 @@ The following command line options are supported: .Bl -tag -width indent .It Ar pkg-name ... The named packages are deinstalled, wildcards can be used, see -.Xr pkg_info 1 . +.Xr pkg_info 1 . If no version is given, the one currently installed +will be removed. If the .Fl F flag is given, one or more (absolute) filenames may be specified and diff --git a/usr.sbin/pkg_install/info/info.h b/usr.sbin/pkg_install/info/info.h index b0eaffebbcfe..be4be7e0bb39 100644 --- a/usr.sbin/pkg_install/info/info.h +++ b/usr.sbin/pkg_install/info/info.h @@ -1,4 +1,4 @@ -/* $NetBSD: info.h,v 1.9 1999/03/04 00:35:05 hubertf Exp $ */ +/* $NetBSD: info.h,v 1.10 1999/08/19 19:37:22 hubertf Exp $ */ /* from FreeBSD Id: info.h,v 1.10 1997/02/22 16:09:40 peter Exp */ @@ -58,11 +58,13 @@ extern char PlayPen[]; extern size_t PlayPenSize; extern char *CheckPkg; extern size_t termwidth; +extern lpkg_head_t pkgs; extern void show_file(char *, char *); extern void show_plist(char *, package_t *, pl_ent_t); extern void show_files(char *, package_t *); extern void show_depends(char *, package_t *); extern void show_index(char *, char *); +extern int find_fn(const char *pkg, char *data); #endif /* _INST_INFO_H_INCLUDE */ diff --git a/usr.sbin/pkg_install/info/main.c b/usr.sbin/pkg_install/info/main.c index 702604451adf..8447779c2506 100644 --- a/usr.sbin/pkg_install/info/main.c +++ b/usr.sbin/pkg_install/info/main.c @@ -1,11 +1,11 @@ -/* $NetBSD: main.c,v 1.16 1999/03/22 05:02:41 hubertf Exp $ */ +/* $NetBSD: main.c,v 1.17 1999/08/19 19:37:22 hubertf Exp $ */ #include #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.16 1999/03/22 05:02:41 hubertf Exp $"); +__RCSID("$NetBSD: main.c,v 1.17 1999/08/19 19:37:22 hubertf Exp $"); #endif #endif @@ -61,7 +61,7 @@ usage(void) exit(1); } -static int +int find_fn(const char *pkg, char *data) { lpkg_t *lpp; diff --git a/usr.sbin/pkg_install/info/perform.c b/usr.sbin/pkg_install/info/perform.c index c66a2c4250dc..40b4a2d5c1aa 100644 --- a/usr.sbin/pkg_install/info/perform.c +++ b/usr.sbin/pkg_install/info/perform.c @@ -1,11 +1,11 @@ -/* $NetBSD: perform.c,v 1.25 1999/08/19 14:12:34 agc Exp $ */ +/* $NetBSD: perform.c,v 1.26 1999/08/19 19:37:22 hubertf Exp $ */ #include #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.25 1999/08/19 14:12:34 agc Exp $"); +__RCSID("$NetBSD: perform.c,v 1.26 1999/08/19 19:37:22 hubertf Exp $"); #endif #endif @@ -76,6 +76,7 @@ pkg_do(char *pkg) if ((cp = fileFindByPath(NULL, pkg)) != NULL) strncpy(fname, cp, FILENAME_MAX); } + if (cp) { if (URLlength(pkg) > 0) { /* file is already unpacked by fileGetURL() */ @@ -99,17 +100,32 @@ pkg_do(char *pkg) goto bail; } } - } - /* - * It's not an uninstalled package, try and find it among the - * installed - */ - else { + } else { + /* + * It's not an uninstalled package, try and find it among the + * installed + */ char *tmp; - (void) snprintf(log_dir, sizeof(log_dir), "%s/%s", (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR, + (void) snprintf(log_dir, sizeof(log_dir), "%s/%s", + (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR, pkg); if (!fexists(log_dir) || !isdir(log_dir)) { + { + /* Check if the given package name matches something + * with 'pkg-[0-9]*' + */ + char try[FILENAME_MAX]; + snprintf(try, FILENAME_MAX, "%s-[0-9]*", pkg); + if (findmatchingname(_pkgdb_getPKGDB_DIR(), try, + find_fn, NULL) != 0) { + return 0; /* we've just appended some names to the pkgs list, + * they will be processed after this package. + */ + } + } + + /* No match */ warnx("can't find package `%s' installed or in a file!", pkg); return 1; } @@ -226,6 +242,17 @@ CheckForPkg(char *pkgspec, char *dbdir) if (!error && !Quiet) { printf("%s\n", pkgspec); } + if (error) { + /* found nothing - try 'pkg-[0-9]*' + */ + char try[FILENAME_MAX]; + snprintf(try, FILENAME_MAX, "%s-[0-9]*", pkgspec); + if (findmatchingname(_pkgdb_getPKGDB_DIR(), try, + foundpkg, NULL) != 0) { + error = 0; + } + + } return error; } @@ -290,6 +317,7 @@ pkg_perform(lpkg_head_t *pkgs) } } } else { + /* Show info on individual pkg(s) */ lpkg_t *lpp; while ((lpp = TAILQ_FIRST(pkgs))) { diff --git a/usr.sbin/pkg_install/info/pkg_info.1 b/usr.sbin/pkg_install/info/pkg_info.1 index dadc1728e051..ab10d0783e07 100644 --- a/usr.sbin/pkg_install/info/pkg_info.1 +++ b/usr.sbin/pkg_install/info/pkg_info.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_info.1,v 1.17 1999/03/22 18:44:04 garbled Exp $ +.\" $NetBSD: pkg_info.1,v 1.18 1999/08/19 19:37:22 hubertf Exp $ .\" .\" FreeBSD install - a package for the installation and maintainance .\" of non-core utilities. @@ -47,10 +47,11 @@ command. .Pp The .Ar pkg-name -may be the name of an installed package, a pattern matching several -installed packages (see the +may be the name of an installed package (with our without version), a +pattern matching several installed packages (see the .Fl e -switch for a description of possible patterns), the pathname to a +switch for a description of possible patterns), +the pathname to a package distribution file, a filename belonging to an installed package (if .Fl F