summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorespie <espie@openbsd.org>1999-02-27 13:40:24 +0000
committerespie <espie@openbsd.org>1999-02-27 13:40:24 +0000
commit0c4fe01baf8e7496d56d401bc9e3f2588e0dd717 (patch)
treeef1df9f53bb9c89acb4a60d57ecd25d8abd4c2ed
parentipsec.c: Merge with EOM 1.83 (diff)
downloadwireguard-openbsd-0c4fe01baf8e7496d56d401bc9e3f2588e0dd717.tar.xz
wireguard-openbsd-0c4fe01baf8e7496d56d401bc9e3f2588e0dd717.zip
Small new feature: pkg_info pkg
now tries to complete the package name with a version number while scanning the installed list of packages. Not foolproof. The pkg_* tools are atrocious anyway.
-rw-r--r--usr.sbin/pkg_install/info/perform.c48
1 files changed, 43 insertions, 5 deletions
diff --git a/usr.sbin/pkg_install/info/perform.c b/usr.sbin/pkg_install/info/perform.c
index b1cb852a98a..282d569d377 100644
--- a/usr.sbin/pkg_install/info/perform.c
+++ b/usr.sbin/pkg_install/info/perform.c
@@ -1,10 +1,11 @@
-/* $OpenBSD: perform.c,v 1.6 1998/11/19 04:12:55 espie Exp $ */
+/* $OpenBSD: perform.c,v 1.7 1999/02/27 13:40:24 espie Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: perform.c,v 1.6 1998/11/19 04:12:55 espie Exp $";
+static const char *rcsid = "$OpenBSD: perform.c,v 1.7 1999/02/27 13:40:24 espie Exp $";
#endif
-/*
+/* This is OpenBSD pkg_install, based on:
+ *
* FreeBSD install - a package for the installation and maintainance
* of non-core utilities.
*
@@ -37,6 +38,34 @@ static const char *rcsid = "$OpenBSD: perform.c,v 1.6 1998/11/19 04:12:55 espie
static char *Home;
+/* retrieve info on installed packages from the base name:
+ * find a full name of the form pkg-xxx.
+ */
+static char *
+find_prefix(char *buffer, int bufsize, char *base, char *pkg)
+{
+ DIR *dirp;
+ struct dirent *dp;
+ char *res;
+ int pkg_length = strlen(pkg);
+
+
+ if (! (dirp = opendir(base)) )
+ return 0;
+ while ( (dp = readdir(dirp)) ) {
+ if (strncmp(dp->d_name, pkg, pkg_length) == 0
+ && dp->d_name[pkg_length] == '-') {
+ snprintf(buffer, bufsize, "%s/%s", base, dp->d_name);
+ /* pedantic: need to dup res before closedir() */
+ res = strdup(dp->d_name);
+ (void)closedir(dirp);
+ return res;
+ }
+ }
+ (void)closedir(dirp);
+ return 0;
+}
+
static int
pkg_do(char *pkg)
{
@@ -48,6 +77,7 @@ pkg_do(char *pkg)
struct stat sb;
char *cp = NULL;
int code = 0;
+ char *pkg2 = 0; /* hold full name of package, storage to free */
if (isURL(pkg)) {
if ((cp = fileGetURL(NULL, pkg)) != NULL) {
@@ -102,14 +132,21 @@ pkg_do(char *pkg)
else {
char *tmp;
- (void) snprintf(log_dir, sizeof(log_dir), "%s/%s", (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR,
+ if (!(tmp = getenv(PKG_DBDIR)))
+ tmp = DEF_LOG_DIR;
+
+ (void) snprintf(log_dir, sizeof(log_dir), "%s/%s", tmp,
pkg);
- if (!fexists(log_dir)) {
+ if (!fexists(log_dir) &&
+ ! (pkg2 = find_prefix(log_dir, sizeof(log_dir), tmp, pkg))) {
warnx("can't find package `%s' installed or in a file!", pkg);
return 1;
}
+ if (pkg2)
+ pkg = pkg2;
if (chdir(log_dir) == FAIL) {
warnx("can't change directory to '%s'!", log_dir);
+ free(pkg2);
return 1;
}
installed = TRUE;
@@ -162,6 +199,7 @@ pkg_do(char *pkg)
}
free_plist(&plist);
bail:
+ free(pkg2);
leave_playpen(Home);
if (isTMP)
unlink(fname);