summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBob Beck <beck@cvs.openbsd.org>1999-10-09 20:35:47 +0000
committerBob Beck <beck@cvs.openbsd.org>1999-10-09 20:35:47 +0000
commit9949e589fd670b632382d4258ad41acdee66d0fa (patch)
tree1315e3f875c786e1a68a57ac5fafa3a7d0b15856
parent04f83a5e0a410eb656e7cd02db3bae87ac03cd14 (diff)
Band Aid fixes, polyglot of espies and mine:
- ensure package files end in .tgz if not suffixed, but allow for .tar.gz and uncompressed .tar as well. - make pkg_add take as many args as you can feed it. - "pkg_add *.tgz" works now. - fix bug where realpath could fail and leave NULL in arg list. - fix bug where nonexistent package could fail and leave NULL in arg list.
-rw-r--r--usr.sbin/pkg_install/add/main.c86
-rw-r--r--usr.sbin/pkg_install/add/perform.c64
-rw-r--r--usr.sbin/pkg_install/add/pkg_add.16
-rw-r--r--usr.sbin/pkg_install/delete/perform.c42
-rw-r--r--usr.sbin/pkg_install/delete/pkg_delete.110
-rw-r--r--usr.sbin/pkg_install/lib/file.c52
-rw-r--r--usr.sbin/pkg_install/lib/lib.h3
7 files changed, 184 insertions, 79 deletions
diff --git a/usr.sbin/pkg_install/add/main.c b/usr.sbin/pkg_install/add/main.c
index e7359a3cc44..19d08c5f620 100644
--- a/usr.sbin/pkg_install/add/main.c
+++ b/usr.sbin/pkg_install/add/main.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: main.c,v 1.10 1999/02/28 18:55:24 deraadt Exp $ */
+/* $OpenBSD: main.c,v 1.11 1999/10/09 20:35:44 beck Exp $ */
#ifndef lint
-static char *rcsid = "$OpenBSD: main.c,v 1.10 1999/02/28 18:55:24 deraadt Exp $";
+static char *rcsid = "$OpenBSD: main.c,v 1.11 1999/10/09 20:35:44 beck Exp $";
#endif
/*
@@ -44,9 +44,8 @@ char *Directory = NULL;
char FirstPen[FILENAME_MAX];
add_mode_t AddMode = NORMAL;
-#define MAX_PKGS 20
-char pkgnames[MAX_PKGS][MAXPATHLEN];
-char *pkgs[MAX_PKGS];
+char **pkgs;
+int pkg_count = 0;
static void usage __P((void));
@@ -107,38 +106,77 @@ main(int argc, char **argv)
argc -= optind;
argv += optind;
- if (argc > MAX_PKGS) {
- warnx("too many packages (max %d)", MAX_PKGS);
- return(1);
- }
-
+ pkg_count = argc + 1;
+ pkgs = (char **)calloc(pkg_count, sizeof(char **));
+ if (pkgs == NULL) {
+ fprintf(stderr, "malloc failed - abandoning package add.\n");
+ exit(1);
+ }
+
if (AddMode != SLAVE) {
- for (ch = 0; ch < MAX_PKGS; pkgs[ch++] = NULL) ;
/* Get all the remaining package names, if any */
for (ch = 0; *argv; ch++, argv++) {
- if (!strcmp(*argv, "-")) /* stdin? */
- pkgs[ch] = "-";
- else if (isURL(*argv)) /* preserve URLs */
- pkgs[ch] = strcpy(pkgnames[ch], *argv);
+ /* Don't mangle stdin ("-") or URL arguments */
+ if ( (strcmp(*argv, "-") == 0)
+ || (isURL(*argv))) {
+ pkgs[ch] = strdup(*argv);
+ if (pkgs[ch] == NULL) {
+ fprintf(stderr,
+ "malloc failed - abandoning package add.\n");
+ exit(1);
+ }
+ }
else { /* expand all pathnames to fullnames */
- char *s;
+ char *s, *tmp;
+
+ s=ensure_tgz(*argv);
- if (fexists(*argv)) /* refers to a file directly */
- pkgs[ch] = realpath(*argv, pkgnames[ch]);
+ if (fexists(s)) { /* refers to a file directly */
+ pkgs[ch] = (char *) malloc(MAXPATHLEN * sizeof(char));
+ if (pkgs[ch] == NULL) {
+ fprintf(stderr,
+ "malloc failed - abandoning package add.\n");
+ exit(1);
+ }
+ tmp = realpath(s, pkgs[ch]);
+ if (tmp == NULL) {
+ perror("realpath failed");
+ fprintf(stderr, "failing path was %s", pkgs[ch]);
+ exit(1);
+ }
+ }
else if (ispkgpattern(*argv)
&& (s=findbestmatchingname(dirname_of(*argv),
basename_of(*argv))) > 0) {
if (Verbose)
printf("Using %s for %s\n",s, *argv);
-
- pkgs[ch] = realpath(s, pkgnames[ch]);
+ pkgs[ch] = (char *) malloc(MAXPATHLEN * sizeof(char));
+ if (pkgs[ch] == NULL) {
+ fprintf(stderr,
+ "malloc failed - abandoning package add.\n");
+ exit(1);
+ }
+ tmp = realpath(s, pkgs[ch]);
+ if (tmp == NULL) {
+ perror("realpath failed");
+ fprintf(stderr, "failing path was %s", pkgs[ch]);
+ exit(1);
+ }
} else {
/* look for the file(pattern) in the expected places */
- if (!(cp = fileFindByPath(NULL, *argv)))
- warnx("can't find package '%s'", *argv);
- else
- pkgs[ch] = strcpy(pkgnames[ch], cp);
+ if (!(cp = fileFindByPath(NULL, *argv))) {
+ fprintf(stderr, "can't find package '%s'", *argv);
+ exit(1);
+ }
+ else {
+ pkgs[ch] = strdup(cp);
+ if (pkgs[ch] == NULL) {
+ fprintf(stderr,
+ "malloc failed - abandoning package add.\n");
+ exit(1);
+ }
+ }
}
}
}
diff --git a/usr.sbin/pkg_install/add/perform.c b/usr.sbin/pkg_install/add/perform.c
index 840a7bb093c..d6b9e80ec41 100644
--- a/usr.sbin/pkg_install/add/perform.c
+++ b/usr.sbin/pkg_install/add/perform.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: perform.c,v 1.9 1999/07/07 06:00:24 espie Exp $ */
+/* $OpenBSD: perform.c,v 1.10 1999/10/09 20:35:45 beck Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: perform.c,v 1.9 1999/07/07 06:00:24 espie Exp $";
+static const char *rcsid = "$OpenBSD: perform.c,v 1.10 1999/10/09 20:35:45 beck Exp $";
#endif
/*
@@ -97,7 +97,7 @@ pkg_do(char *pkg)
fgets(playpen, FILENAME_MAX, stdin);
playpen[strlen(playpen) - 1] = '\0'; /* pesky newline! */
if (chdir(playpen) == FAIL) {
- warnx("add in SLAVE mode can't chdir to %s", playpen);
+ warnx("add in SLAVE mode can't chdir to `%s'", playpen);
return 1;
}
read_plist(&Plist, stdin);
@@ -130,7 +130,7 @@ pkg_do(char *pkg)
read_plist(&Plist, cfile);
fclose(cfile);
} else {
- strcpy(pkg_fullname, pkg); /* copy for sanity's sake, could remove pkg_fullname */
+ strlcpy(pkg_fullname, ensure_tgz(pkg), sizeof pkg_fullname);
if (strcmp(pkg, "-")) {
if (!ispkgpattern(pkg_fullname)
&& stat(pkg_fullname, &sb) == FAIL) {
@@ -138,7 +138,7 @@ pkg_do(char *pkg)
goto bomb;
}
snprintf(extract_contents, sizeof( extract_contents ),
- "-q %s", CONTENTS_FNAME);
+ "%s", CONTENTS_FNAME);
extract = extract_contents;
}
else {
@@ -169,12 +169,12 @@ pkg_do(char *pkg)
/* Extract directly rather than moving? Oh goodie! */
if (find_plist_option(&Plist, "extract-in-place")) {
if (Verbose)
- printf("Doing in-place extraction for %s\n", pkg_fullname);
+ printf("Doing in-place extraction for `%s'\n", pkg_fullname);
p = find_plist(&Plist, PLIST_CWD);
if (p) {
if (!(isdir(p->name) || islinktodir(p->name)) && !Fake) {
if (Verbose)
- printf("Desired prefix of %s does not exist, creating.\n", p->name);
+ printf("Desired prefix of `%s' does not exist, creating\n", p->name);
vsystem("mkdir -p %s", p->name);
}
if (chdir(p->name) == -1) {
@@ -201,11 +201,11 @@ pkg_do(char *pkg)
*/
if (!extract && !inPlace && min_free(playpen) < sb.st_size * 4) {
- warnx("projected size of %ld exceeds available free space.\n"
+ warnx("projected size of %ld exceeds available free space\n"
"Please set your PKG_TMPDIR variable to point to a"
"location with more\n"
"free space and try again", (long)(sb.st_size * 4));
- warnx("not extracting %s\ninto %s, sorry!", pkg_fullname,
+ warnx("not extracting `%s'\ninto `%s', sorry!", pkg_fullname,
where_to);
goto bomb;
}
@@ -281,7 +281,7 @@ pkg_do(char *pkg)
if (p->type != PLIST_PKGCFL)
continue;
if (Verbose)
- printf("Package `%s' conflicts with `%s'.\n", PkgName, p->name);
+ printf("Package `%s' conflicts with `%s'\n", PkgName, p->name);
/* was: */
/* if (!vsystem("/usr/sbin/pkg_info -qe '%s'", p->name)) {*/
@@ -298,7 +298,7 @@ pkg_do(char *pkg)
if (p->type != PLIST_PKGDEP)
continue;
if (Verbose)
- printf("Package `%s' depends on `%s'.\n", PkgName, p->name);
+ printf("Package `%s' depends on `%s'\n", PkgName, p->name);
/* if (vsystem("/usr/sbin/pkg_info -qe '%s'", p->name)) { */
if (!findmatchingname(dbdir, p->name, check_if_installed, installed)) {
char path[FILENAME_MAX], *cp = NULL;
@@ -307,14 +307,14 @@ pkg_do(char *pkg)
if (!isURL(pkg) && !getenv("PKG_ADD_BASE")) {
/* install depending pkg from local disk */
- snprintf(path, FILENAME_MAX, "%s/%s.tgz", Home, p->name);
+ snprintf(path, FILENAME_MAX, "%s/%s", Home, ensure_tgz(p->name));
if (fexists(path))
cp = path;
else
cp = fileFindByPath(pkg, p->name);
if (cp) {
if (Verbose)
- printf("Loading it from %s.\n", cp);
+ printf("Loading it from `%s'\n", cp);
if (vsystem("/usr/sbin/pkg_add %s%s %s%s",
Prefix ? "-p " : "",
Prefix ? Prefix : "",
@@ -347,9 +347,9 @@ pkg_do(char *pkg)
if ((cp = fileGetURL(pkg, p->name)) != NULL) {
if (Verbose)
- printf("Finished loading %s over FTP.\n", p->name);
+ printf("Finished loading `%s' over FTP\n", p->name);
if (!fexists(CONTENTS_FNAME)) {
- warnx("autoloaded package %s has no %s file?",
+ warnx("autoloaded package `%s' has no %s file?",
p->name, CONTENTS_FNAME);
if (!Force)
++code;
@@ -365,7 +365,7 @@ pkg_do(char *pkg)
++code;
}
else if (Verbose)
- printf("\t`%s' loaded successfully.\n", p->name);
+ printf("\t`%s' loaded successfully\n", p->name);
/* Nuke the temporary playpen */
leave_playpen(cp);
@@ -375,16 +375,16 @@ pkg_do(char *pkg)
}
} else {
if (Verbose)
- printf("and was not found%s.\n", Force ? " (proceeding anyway)" : "");
+ printf("and was not found%s\n", Force ? " (proceeding anyway)" : "");
else
- printf("Package dependency %s for %s not found%s\n", p->name, pkg,
+ printf("Package dependency `%s' for `%s' not found%s\n", p->name, pkg,
Force ? " (proceeding anyway)" : "!");
if (!Force)
++code;
}
}
else if (Verbose)
- printf(" - %s already installed.\n", installed);
+ printf(" - `%s' already installed\n", installed);
}
if (code != 0)
@@ -394,9 +394,9 @@ pkg_do(char *pkg)
if (fexists(REQUIRE_FNAME)) {
vsystem("chmod +x %s", REQUIRE_FNAME); /* be sure */
if (Verbose)
- printf("Running requirements file first for %s.\n", PkgName);
+ printf("Running requirements file first for `%s'\n", PkgName);
if (!Fake && vsystem("./%s %s INSTALL", REQUIRE_FNAME, PkgName)) {
- warnx("package %s fails requirements %s", pkg_fullname,
+ warnx("package `%s' fails requirements %s", pkg_fullname,
Force ? "installing anyway" : "- not installed");
if (!Force) {
code = 1;
@@ -409,7 +409,7 @@ pkg_do(char *pkg)
if (!NoInstall && fexists(INSTALL_FNAME)) {
vsystem("chmod +x %s", INSTALL_FNAME); /* make sure */
if (Verbose)
- printf("Running install with PRE-INSTALL for %s.\n", PkgName);
+ printf("Running install with PRE-INSTALL for `%s'\n", PkgName);
if (!Fake && vsystem("./%s %s PRE-INSTALL", INSTALL_FNAME, PkgName)) {
warnx("install script returned error status");
unlink(INSTALL_FNAME);
@@ -424,7 +424,7 @@ pkg_do(char *pkg)
if (!Fake && fexists(MTREE_FNAME)) {
if (Verbose)
- printf("Running mtree for %s.\n", PkgName);
+ printf("Running mtree for `%s'\n", PkgName);
p = find_plist(&Plist, PLIST_CWD);
if (Verbose)
printf("mtree -q -U -f %s -d -e -p %s\n", MTREE_FNAME,
@@ -441,7 +441,7 @@ pkg_do(char *pkg)
/* Run the installation script one last time? */
if (!NoInstall && fexists(INSTALL_FNAME)) {
if (Verbose)
- printf("Running install with POST-INSTALL for %s.\n", PkgName);
+ printf("Running install with POST-INSTALL for `%s'\n", PkgName);
if (!Fake && vsystem("./%s %s POST-INSTALL", INSTALL_FNAME, PkgName)) {
warnx("install script returned error status");
unlink(INSTALL_FNAME);
@@ -467,7 +467,7 @@ pkg_do(char *pkg)
(void) snprintf(LogDir, sizeof(LogDir), "%s/%s", dbdir, PkgName);
zapLogDir = 1;
if (Verbose)
- printf("Attempting to record package into %s.\n", LogDir);
+ printf("Attempting to record package into `%s'\n", LogDir);
if (make_hierarchy(LogDir)) {
warnx("can't record package into '%s', you're on your own!",
LogDir);
@@ -529,11 +529,11 @@ pkg_do(char *pkg)
else {
fprintf(cfile, "%s\n", PkgName);
if (fclose(cfile) == EOF)
- warnx("cannot properly close file %s", contents);
+ warnx("cannot properly close file `%s'", contents);
}
}
if (Verbose)
- printf("Package %s registered in %s\n", PkgName, LogDir);
+ printf("Package `%s' registered in `%s'\n", PkgName, LogDir);
}
if ((p = find_plist(&Plist, PLIST_DISPLAY)) != NULL) {
@@ -547,7 +547,7 @@ pkg_do(char *pkg)
snprintf(buf, sizeof buf, "%s/%s", LogDir, p->name);
if (!stat(buf,&sbuf) || vsystem("%s %s", Pager, buf))
- warnx("cannot open %s as display file", buf);
+ warnx("cannot open `%s' as display file", buf);
}
goto success;
@@ -574,15 +574,15 @@ sanity_check(char *pkg)
int code = 0;
if (!fexists(CONTENTS_FNAME)) {
- warnx("package %s has no CONTENTS file!", pkg);
+ warnx("package `%s' has no CONTENTS file!", pkg);
code = 1;
}
else if (!fexists(COMMENT_FNAME)) {
- warnx("package %s has no COMMENT file!", pkg);
+ warnx("package `%s' has no COMMENT file!", pkg);
code = 1;
}
else if (!fexists(DESC_FNAME)) {
- warnx("package %s has no DESC file!", pkg);
+ warnx("package `%s' has no DESC file!", pkg);
code = 1;
}
return code;
@@ -600,7 +600,7 @@ cleanup(int signo)
if (!alreadyCleaning) {
alreadyCleaning = 1;
if (signo)
- printf("Signal %d received, cleaning up.\n", signo);
+ printf("Signal %d received, cleaning up\n", signo);
if (!Fake && zapLogDir && LogDir[0])
vsystem("%s -rf %s", REMOVE_CMD, LogDir);
leave_playpen(Home);
diff --git a/usr.sbin/pkg_install/add/pkg_add.1 b/usr.sbin/pkg_install/add/pkg_add.1
index 547e7847e21..361f1aec250 100644
--- a/usr.sbin/pkg_install/add/pkg_add.1
+++ b/usr.sbin/pkg_install/add/pkg_add.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: pkg_add.1,v 1.11 1999/10/07 22:22:58 aaron Exp $
+.\" $OpenBSD: pkg_add.1,v 1.12 1999/10/09 20:35:45 beck Exp $
.\"
.\" FreeBSD install - a package for the installation and maintainance
.\" of non-core utilities.
@@ -49,6 +49,10 @@ that would otherwise need to be built manually.
Package names may be specified as filenames (which normally consist of the
package name itself plus the
.Dq .tgz
+,
+.Dq .tar.gz
+, or
+.Dq .tar
suffix) or an FTP location in the form of an URL. For example, the following
is valid:
.Pp
diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c
index a0003701bb3..0893a6e7e6b 100644
--- a/usr.sbin/pkg_install/delete/perform.c
+++ b/usr.sbin/pkg_install/delete/perform.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: perform.c,v 1.5 1998/10/13 23:09:50 marc Exp $ */
+/* $OpenBSD: perform.c,v 1.6 1999/10/09 20:35:45 beck Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: perform.c,v 1.5 1998/10/13 23:09:50 marc Exp $";
+static const char *rcsid = "$OpenBSD: perform.c,v 1.6 1999/10/09 20:35:45 beck Exp $";
#endif
/*
@@ -46,6 +46,29 @@ pkg_perform(char **pkgs)
static package_t Plist;
+static int
+trim_end(char *name)
+{
+ size_t n, m;
+ n = strlen(name);
+ m = strlen(".tgz");
+ if (n > m && strcmp(name+n-m, ".tgz") == 0) {
+ name[n-m] = 0;
+ return 1;
+ }
+ m = strlen(".tar.gz");
+ if (n > m && strcmp(name+n-m, ".tar.gz") == 0) {
+ name[n-m] = 0;
+ return 1;
+ }
+ m = strlen(".tar");
+ if (n > m && strcmp(name+n-m, ".tar") == 0) {
+ name[n-m] = 0;
+ return 1;
+ }
+ return 0;
+}
+
/* This is seriously ugly code following. Written very fast! */
static int
pkg_do(char *pkg)
@@ -59,11 +82,18 @@ pkg_do(char *pkg)
if (Plist.head)
free_plist(&Plist);
- (void) snprintf(LogDir, sizeof(LogDir), "%s/%s", (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR,
- pkg);
+ tmp = getenv(PKG_DBDIR);
+ if (!tmp)
+ tmp = DEF_LOG_DIR;
+try_again:
+ (void) snprintf(LogDir, sizeof(LogDir), "%s/%s", tmp, pkg);
if (!fexists(LogDir)) {
- warnx("no such package '%s' installed", pkg);
- return 1;
+ if (trim_end(pkg))
+ goto try_again;
+ else {
+ warnx("no such package '%s' installed", pkg);
+ return 1;
+ }
}
if (!getcwd(home, FILENAME_MAX)) {
cleanup(0);
diff --git a/usr.sbin/pkg_install/delete/pkg_delete.1 b/usr.sbin/pkg_install/delete/pkg_delete.1
index 0739a28d593..882a1d6cc75 100644
--- a/usr.sbin/pkg_install/delete/pkg_delete.1
+++ b/usr.sbin/pkg_install/delete/pkg_delete.1
@@ -1,4 +1,4 @@
-.\" $OpenBSD: pkg_delete.1,v 1.6 1999/07/03 02:11:10 aaron Exp $
+.\" $OpenBSD: pkg_delete.1,v 1.7 1999/10/09 20:35:45 beck Exp $
.\"
.\" FreeBSD install - a package for the installation and maintainance
.\" of non-core utilities.
@@ -35,6 +35,14 @@ command is used to delete packages that have been previously installed
with the
.Xr pkg_add 1
command.
+.Pp
+Package names may be specified either as the package name itself, or as filenames which consist of the package name plus the
+.Dq .tgz
+,
+.Dq .tar.gz
+, or the
+.Dq .tar
+suffix.
.Sh WARNING
.Bf -emphasis
Since the
diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c
index 0119f42ff5a..a3b050b1c5c 100644
--- a/usr.sbin/pkg_install/lib/file.c
+++ b/usr.sbin/pkg_install/lib/file.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: file.c,v 1.8 1999/09/20 16:54:44 espie Exp $ */
+/* $OpenBSD: file.c,v 1.9 1999/10/09 20:35:46 beck Exp $ */
#ifndef lint
-static const char *rcsid = "$OpenBSD: file.c,v 1.8 1999/09/20 16:54:44 espie Exp $";
+static const char *rcsid = "$OpenBSD: file.c,v 1.9 1999/10/09 20:35:46 beck Exp $";
#endif
/*
@@ -34,6 +34,31 @@ static const char *rcsid = "$OpenBSD: file.c,v 1.8 1999/09/20 16:54:44 espie Exp
#include <pwd.h>
#include <time.h>
+/* This fixes errant package names so they end up in .tgz.
+ XXX returns static storage, so beware ! Consume the result
+ before reusing the function.
+ */
+#define TGZ ".tgz"
+char *
+ensure_tgz(char *name)
+{
+ static char buffer[FILENAME_MAX];
+ size_t len;
+
+ len = strlen(name);
+ if ( (strcmp (name, "-") == 0 )
+ || (len >= strlen(TGZ) && strcmp(name+len-strlen(TGZ), TGZ) == 0)
+ || (len >= strlen(".tar.gz") &&
+ strcmp(name+len-strlen(".tar.gz"), ".tar.gz") == 0)
+ || (len >= strlen(".tar") &&
+ strcmp(name+len-strlen(".tar"), ".tar") == 0))
+ return name;
+ else {
+ snprintf(buffer, sizeof buffer, "%s%s", name, TGZ);
+ return buffer;
+ }
+}
+
/* This is as ftpGetURL from FreeBSD's ftpio.c, except that it uses
* OpenBSD's ftp command to do all FTP.
*/
@@ -264,7 +289,7 @@ fileGetURL(char *base, char *spec)
to construct a composite one out of that and the basename we were
handed as a dependency. */
if (base) {
- strcpy(fname, base);
+ strlcpy(fname, base, sizeof fname);
/* OpenBSD packages are currently stored in a flat space, so
we don't yet need to backup the category and switch to all.
*/
@@ -280,20 +305,19 @@ fileGetURL(char *base, char *spec)
#if 0
strcat(cp, "All/");
#endif
- strcat(cp, spec);
- strcat(cp, ".tgz");
+ strlcat(cp, ensure_tgz(spec), sizeof fname);
}
else
return NULL;
}
else {
/* Otherwise, we've been given an environment variable hinting at the right location from sysinstall */
- strcpy(fname, hint);
- strcat(fname, spec);
+ strlcpy(fname, hint, sizeof fname);
+ strlcat(fname, spec, sizeof fname);
}
}
else
- strcpy(fname, spec);
+ strlcpy(fname, spec, sizeof fname);
cp = fileURLHost(fname, host, MAXHOSTNAMELEN);
if (!*cp) {
warnx("URL `%s' has bad host part!", fname);
@@ -354,8 +378,8 @@ fileFindByPath(char *base, char *fname)
return tmp;
}
} else {
- if (fexists(fname) && isfile(fname)) {
- strcpy(tmp, fname);
+ strlcpy(tmp, ensure_tgz(fname), sizeof tmp);
+ if (fexists(tmp) && isfile(tmp)) {
return tmp;
}
}
@@ -370,9 +394,8 @@ fileFindByPath(char *base, char *fname)
}
if (cp) {
*(cp + 1) = '\0';
- strcat(cp, "All/");
- strcat(cp, fname);
- strcat(cp, ".tgz");
+ strlcat(tmp, "All/", sizeof tmp);
+ strlcat(tmp, ensure_tgz(fname), sizeof tmp);
if (ispkgpattern(tmp)) {
cp=findbestmatchingname(dirname_of(tmp),
basename_of(tmp));
@@ -395,7 +418,8 @@ fileFindByPath(char *base, char *fname)
while (cp) {
char *cp2 = strsep(&cp, ":");
- snprintf(tmp, FILENAME_MAX, "%s/%s.tgz", cp2 ? cp2 : cp, fname);
+ snprintf(tmp, FILENAME_MAX, "%s/%s", cp2 ? cp2 : cp,
+ ensure_tgz(fname));
if (ispkgpattern(tmp)) {
char *s;
s = findbestmatchingname(dirname_of(tmp),
diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h
index c2368fa78d4..a92e5100bc4 100644
--- a/usr.sbin/pkg_install/lib/lib.h
+++ b/usr.sbin/pkg_install/lib/lib.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: lib.h,v 1.4 1998/11/19 04:12:55 espie Exp $ */
+/* $OpenBSD: lib.h,v 1.5 1999/10/09 20:35:46 beck Exp $ */
/*
* FreeBSD install - a package for the installation and maintainance
@@ -168,6 +168,7 @@ Boolean isemptyfile(char *fname);
Boolean isfile(char *);
Boolean isempty(char *);
Boolean isURL(char *);
+char *ensure_tgz(char *);
char *fileGetURL(char *, char *);
char *fileURLFilename(char *, char *, int);
char *fileURLHost(char *, char *, int);