diff options
Diffstat (limited to 'usr.sbin/pkg_install/delete')
-rw-r--r-- | usr.sbin/pkg_install/delete/delete.h | 4 | ||||
-rw-r--r-- | usr.sbin/pkg_install/delete/main.c | 53 | ||||
-rw-r--r-- | usr.sbin/pkg_install/delete/perform.c | 38 | ||||
-rw-r--r-- | usr.sbin/pkg_install/delete/pkg_delete.1 | 27 |
4 files changed, 104 insertions, 18 deletions
diff --git a/usr.sbin/pkg_install/delete/delete.h b/usr.sbin/pkg_install/delete/delete.h index cc7a70e..faa2e06 100644 --- a/usr.sbin/pkg_install/delete/delete.h +++ b/usr.sbin/pkg_install/delete/delete.h @@ -24,10 +24,12 @@ #define _INST_DELETE_H_INCLUDE extern char *Prefix; -extern Boolean NoDeInstall; extern Boolean CleanDirs; +extern Boolean Interactive; +extern Boolean NoDeInstall; extern Boolean Force; extern char *Directory; extern char *PkgName; +extern match_t MatchType; #endif /* _INST_DELETE_H_INCLUDE */ diff --git a/usr.sbin/pkg_install/delete/main.c b/usr.sbin/pkg_install/delete/main.c index fc35c4e..f87af3d 100644 --- a/usr.sbin/pkg_install/delete/main.c +++ b/usr.sbin/pkg_install/delete/main.c @@ -30,11 +30,13 @@ static const char rcsid[] = #include "lib.h" #include "delete.h" -static char Options[] = "hvDdnfp:"; +static char Options[] = "adDfGhinp:vx"; char *Prefix = NULL; -Boolean NoDeInstall = FALSE; Boolean CleanDirs = FALSE; +Boolean Interactive = FALSE; +Boolean NoDeInstall = FALSE; +match_t MatchType = MATCH_GLOB; static void usage __P((void)); @@ -75,6 +77,22 @@ main(int argc, char **argv) Verbose = TRUE; break; + case 'a': + MatchType = MATCH_ALL; + break; + + case 'G': + MatchType = MATCH_EXACT; + break; + + case 'x': + MatchType = MATCH_REGEX; + break; + + case 'i': + Interactive = TRUE; + break; + case 'h': case '?': default: @@ -87,23 +105,26 @@ main(int argc, char **argv) /* Get all the remaining package names, if any */ while (*argv) { - while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) { - *pkgs_split++ = '\0'; - /* - * If character after the '/' is alphanumeric, then we've found the - * package name. Otherwise we've come across a trailing '/' and - * need to continue our quest. - */ - if (isalpha(*pkgs_split)) { - *argv = pkgs_split; - break; + /* Don't try to apply heuristics if arguments are regexs */ + if (MatchType != MATCH_REGEX) + while ((pkgs_split = strrchr(*argv, (int)'/')) != NULL) { + *pkgs_split++ = '\0'; + /* + * If character after the '/' is alphanumeric, then we've found the + * package name. Otherwise we've come across a trailing '/' and + * need to continue our quest. + */ + if (isalpha(*pkgs_split) || ((MatchType == MATCH_GLOB) && \ + strpbrk(pkgs_split, "*?[]") != NULL)) { + *argv = pkgs_split; + break; + } } - } *pkgs++ = *argv++; } /* If no packages, yelp */ - if (pkgs == start) + if (pkgs == start && MatchType != MATCH_ALL) warnx("missing package name(s)"), usage(); *pkgs = NULL; tmp = getenv(PKG_DBDIR) ? getenv(PKG_DBDIR) : DEF_LOG_DIR; @@ -126,6 +147,8 @@ main(int argc, char **argv) static void usage() { - fprintf(stderr, "usage: pkg_delete [-vDdnf] [-p prefix] pkg-name ...\n"); + fprintf(stderr, "%s\n%s\n", + "usage: pkg_delete [-dDfGinvx] [-p prefix] pkg-name ...", + " pkg_delete -a [flags]"); exit(1); } diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c index 072b6d5..3453cf8 100644 --- a/usr.sbin/pkg_install/delete/perform.c +++ b/usr.sbin/pkg_install/delete/perform.c @@ -37,10 +37,33 @@ static char LogDir[FILENAME_MAX]; int pkg_perform(char **pkgs) { + char **matched; char *tmp; int i, j; int err_cnt = 0; - int loop_cnt; + int loop_cnt, errcode; + + if (MatchType != MATCH_EXACT) { + matched = matchinstalled(MatchType, pkgs, &errcode); + if (errcode != 0) + return 1; + /* Not reached */ + + if (matched != NULL) + pkgs = matched; + else switch (MatchType) { + case MATCH_GLOB: + break; + case MATCH_ALL: + warnx("no packages installed"); + return 0; + case MATCH_REGEX: + warnx("no packages match pattern(s)"); + return 1; + default: + break; + } + } for (i = 0; pkgs[i]; i++) { /* @@ -122,6 +145,19 @@ pkg_do(char *pkg) return 1; } + if (Interactive == TRUE) { + int first, ch; + + (void)fprintf(stderr, "delete %s? ", pkg); + (void)fflush(stderr); + first = ch = getchar(); + while (ch != '\n' && ch != EOF) + ch = getchar(); + if (first != 'y' && first != 'Y') + return 0; + /* Not reached */ + } + if (!isemptyfile(REQUIRED_BY_FNAME)) { char buf[512]; warnx("package `%s' is required by these other packages\n" diff --git a/usr.sbin/pkg_install/delete/pkg_delete.1 b/usr.sbin/pkg_install/delete/pkg_delete.1 index 7ec63a6..55350bf 100644 --- a/usr.sbin/pkg_install/delete/pkg_delete.1 +++ b/usr.sbin/pkg_install/delete/pkg_delete.1 @@ -25,9 +25,12 @@ .Nd a utility for deleting previously installed software package distributions .Sh SYNOPSIS .Nm -.Op Fl vDdnf +.Op Fl dDfGinvx .Op Fl p Ar prefix .Ar pkg-name ... +.Nm +.Fl a +.Op Ar flags .Sh DESCRIPTION The .Nm @@ -68,6 +71,12 @@ The following command line options are supported: .Bl -tag -width indent .It Ar pkg-name ... The named packages are deinstalled. +.It Fl a +Unconditionally delete all currently installed packages. +.It Fl i +Request confirmation before attempting to delete each package, +regardless whether or not the standard input device is a +terminal. .It Fl v Turn on verbose output. .It Fl D @@ -94,6 +103,22 @@ the package. .It Fl f Force removal of the package, even if a dependency is recorded or the deinstall or require script fails. +.It Fl G +Do not try to expand shell glob patterns in the +.Ar pkg-name +when selecting packages to be deleted (by default +.Nm +automatically expands shell glob patterns in the +.Ar pkg-name ) . +.It Fl x +Treat the +.Ar pkg-name +as a regular expression and delete all packages whose names match +that regular expression. Multiple regular expressions could be +provided, in that case +.Nm +deletes all packages that match at least one +regular expression from the list. .El .Sh TECHNICAL DETAILS .Nm |