Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-1-4]: src/usr.sbin/pkg_install/lib Pull up revisions 1.36-1.37 (r...
details: https://anonhg.NetBSD.org/src/rev/1b9a71af5a0c
branches: netbsd-1-4
changeset: 470236:1b9a71af5a0c
user: he <he%NetBSD.org@localhost>
date: Mon Jan 31 20:59:08 2000 +0000
description:
Pull up revisions 1.36-1.37 (requested by hubertf):
Implement FTP wildcard depends, to give NetBSD full wildcard support
not only in pkgsrc but also for binary packages installed from
local disk or via FTP.
diffstat:
usr.sbin/pkg_install/lib/file.c | 211 ++++++++++++++++++++++++---------------
1 files changed, 131 insertions(+), 80 deletions(-)
diffs (truncated from 313 to 300 lines):
diff -r 117af9e05139 -r 1b9a71af5a0c usr.sbin/pkg_install/lib/file.c
--- a/usr.sbin/pkg_install/lib/file.c Mon Jan 31 20:58:47 2000 +0000
+++ b/usr.sbin/pkg_install/lib/file.c Mon Jan 31 20:59:08 2000 +0000
@@ -1,11 +1,11 @@
-/* $NetBSD: file.c,v 1.25.2.7 1999/12/20 15:42:15 he Exp $ */
+/* $NetBSD: file.c,v 1.25.2.8 2000/01/31 20:59:08 he Exp $ */
#include <sys/cdefs.h>
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: file.c,v 1.29 1997/10/08 07:47:54 charnier Exp";
#else
-__RCSID("$NetBSD: file.c,v 1.25.2.7 1999/12/20 15:42:15 he Exp $");
+__RCSID("$NetBSD: file.c,v 1.25.2.8 2000/01/31 20:59:08 he Exp $");
#endif
#endif
@@ -40,50 +40,6 @@
#include <time.h>
#include <fcntl.h>
-/*
- * This is as ftpGetURL from FreeBSD's ftpio.c, except that it uses
- * NetBSD's ftp command to do all FTP, which will DTRT for proxies,
- * etc.
- */
-static FILE *
-ftpGetURL(char *url, int *retcode)
-{
- FILE *ftp;
- pid_t pid_ftp;
- int p[2];
-
- *retcode = 0;
-
- if (pipe(p) < 0) {
- *retcode = 1;
- return NULL;
- }
-
- pid_ftp = fork();
- if (pid_ftp < 0) {
- *retcode = 1;
- return NULL;
- }
- if (pid_ftp == 0) {
- /* child */
- dup2(p[1], 1);
- close(p[1]);
-
- execl("/usr/bin/ftp", "ftp", "-V", "-o", "-", url, NULL);
- exit(1);
- } else {
- /* parent */
- ftp = fdopen(p[0], "r");
-
- close(p[1]);
-
- if (ftp == (FILE *) NULL) {
- *retcode = 1;
- return NULL;
- }
- }
- return ftp;
-}
/*
* Quick check to see if a file (or dir ...) exists
@@ -208,7 +164,7 @@
}
for (up = urls; up->u_s; up++) {
if (strncmp(fname, up->u_s, up->u_len) == 0) {
- return i + up->u_len;
+ return i + up->u_len; /* ... + sizeof(up->u_s); - HF */
}
}
}
@@ -253,7 +209,7 @@
int i;
if ((i = URLlength(fname)) < 0) { /* invalid URL? */
- errx(1, "fileURLhost called with a bad URL: `%s'", fname);
+ errx(1, "fileURLFilename called with a bad URL: `%s'", fname);
}
fname += i;
/* Do we have a place to stick our work? */
@@ -284,9 +240,7 @@
char *cp, *rp;
char fname[FILENAME_MAX];
char pen[FILENAME_MAX];
- FILE *ftp;
- pid_t tpid;
- int i, status;
+ int rc;
char *hint;
rp = NULL;
@@ -321,12 +275,13 @@
}
} else
strcpy(fname, spec);
+
+ /* Some sanity checks on the URL */
cp = fileURLHost(fname, host, MAXHOSTNAMELEN);
if (!*cp) {
warnx("URL `%s' has bad host part!", fname);
return NULL;
}
-
cp = fileURLFilename(fname, file, FILENAME_MAX);
if (!*cp) {
warnx("URL `%s' has bad filename part!", fname);
@@ -335,34 +290,22 @@
if (Verbose)
printf("Trying to fetch %s.\n", fname);
- ftp = ftpGetURL(fname, &status);
- if (ftp) {
- pen[0] = '\0';
- if ((rp = make_playpen(pen, sizeof(pen), 0)) != NULL) {
- rp = strdup(pen); /* be safe for nested calls */
- if (Verbose)
- printf("Extracting from FTP connection into %s\n", pen);
- tpid = fork();
- if (!tpid) {
- dup2(fileno(ftp), 0);
- i = execl(TAR_FULLPATHNAME, TAR_CMD, Verbose ? "-xzvf" : "-xzf", "-", 0);
- err(i, TAR_FULLPATHNAME " failed");
- } else {
- int pstat;
+
+ pen[0] = '\0';
+ rp = make_playpen(pen, sizeof(pen), 0);
+ if (rp == NULL) {
+ printf("Error: Unable to construct a new playpen for FTP!\n");
+ return NULL;
+ }
- fclose(ftp);
- tpid = waitpid(tpid, &pstat, 0);
- if (Verbose)
- printf("%s command returns %d status\n", TAR_CMD, WEXITSTATUS(pstat));
- }
- } else
- printf("Error: Unable to construct a new playpen for FTP!\n");
- fclose(ftp);
- } else
- printf("Error: FTP Unable to get %s: %s\n",
- fname,
- status ? "Error while performing FTP" :
- hstrerror(h_errno));
+ rp = strdup(pen);
+ rc = unpackURL(fname, pen);
+ if (rc < 0) {
+ leave_playpen(rp); /* Don't leave dir hang around! */
+
+ printf("Error on unpackURL('%s', '%s')\n", fname, pen);
+ return NULL;
+ }
return rp;
}
@@ -378,6 +321,10 @@
static char tmp[FILENAME_MAX];
char *cp;
+/* printf("HF: fileFindByPath(\"%s\", \"%s\")\n", base, fname); *//*HF*/
+
+ /* The following code won't return a match if base is an URL
+ * Could save some cycles here - HF */
if (ispkgpattern(fname)) {
if ((cp = findbestmatchingname(".", fname)) != NULL) {
strcpy(tmp, cp);
@@ -403,7 +350,28 @@
strcat(cp, "All/");
strcat(cp, fname);
strcat(cp, ".tgz");
+
if (ispkgpattern(tmp)) {
+ if (IS_URL(tmp)) {
+ /* some package depends on a wildcard pkg */
+ int rc;
+ char url[FILENAME_MAX];
+
+ /* save url to expand, as tmp is the static var in which
+ * we return the result of the expansion.
+ */
+ strcpy(url, tmp);
+
+/* printf("HF: expandURL('%s')'ing #1\n", url);*//*HF*/
+ rc = expandURL(tmp, url);
+ if (rc < 0) {
+ warnx("fileFindByPath: expandURL('%s') failed\n", url);
+ return NULL;
+ }
+ if (Verbose)
+ printf("'%s' expanded to '%s'\n", url, tmp);
+ return tmp; /* return expanded URL w/ corrent pkg */
+ } else {
cp = findbestmatchingname(dirname_of(tmp), basename_of(tmp));
if (cp) {
char *s;
@@ -412,19 +380,80 @@
strcpy(s + 1, cp);
return tmp;
}
+ }
} else {
if (fexists(tmp)) {
return tmp;
}
}
}
+ } else {
+ if (IS_URL(fname)) {
+ /* Wildcard-URL directly specified on command line */
+ int rc;
+
+/* printf("HF: expandURL('%s')'ing #2\n", fname);*//*HF*/
+ rc = expandURL(tmp, fname);
+ if (rc < 0) {
+ warnx("fileFindByPath: expandURL('%s') failed\n", fname);
+ return NULL;
+ }
+ if (Verbose)
+ printf("'%s' expanded to '%s'\n", fname, tmp);
+ return tmp; /* return expanded URL w/ corrent pkg */
+ }
}
cp = getenv("PKG_PATH");
while (cp) {
- char *cp2 = strsep(&cp, ":");
+ char *cp2 = strsep(&cp, ";");
+
+ printf("trying PKG_PATH %s\n", cp2?cp2:cp);
+ if (strstr(fname, ".tgz")) {
+ /* There's already a ".tgz" present, probably typed on the command line */
+ (void) snprintf(tmp, sizeof(tmp), "%s/%s", cp2 ? cp2 : cp, fname);
+ } else {
+ /* Try this component, and tack on a ".tgz" */
(void) snprintf(tmp, sizeof(tmp), "%s/%s.tgz", cp2 ? cp2 : cp, fname);
+ }
+ if (IS_URL(tmp)) {
+ char url[FILENAME_MAX];
+ int rc;
+
+ /* save url to expand, as tmp is the static var in which
+ * we return the result of the expansion.
+ */
+ strcpy(url, tmp);
+
+/* printf("HF: expandURL('%s')'ing #3\n", url);*//*HF*/
+ rc = expandURL(tmp, url);
+ if (rc >= 0) {
+ printf("fileFindByPath: success, expandURL('%s') returns '%s'\n", url, tmp);
+ return tmp;
+ }
+
+ /* Second chance - maybe just a package name was given, without
+ * a version number. Remove the ".tgz" we tacked on above, and
+ * re-add it with a "-[0-9]*" before. Then see if this matches
+ * something. See also perform.c.
+ */
+ {
+ char *s;
+ s=strstr(tmp, ".tgz");
+ *s = '\0';
+ snprintf(url, FILENAME_MAX, "%s-[0-9]*.tgz", tmp);
+ rc = expandURL(tmp, url);
+ if (rc >= 0) {
+ printf("fileFindByPath: late success, expandURL('%s') returns '%s'\n",
+ url, tmp);
+ return tmp;
+ }
+ }
+
+ /* No luck with this parth of PKG_PATH - try next one */
+
+ } else {
if (ispkgpattern(tmp)) {
char *s;
s = findbestmatchingname(dirname_of(tmp), basename_of(tmp));
@@ -437,6 +466,28 @@
} else {
if (fexists(tmp) && isfile(tmp)) {
return tmp;
+ }
+
+ /* Second chance: seems just a pkg name was given,
+ * no wildcard, no .tgz. Tack something on and retry.
+ * (see above, and perform.c)
+ */
+ {
+ char *s;
+ char buf2[FILENAME_MAX];
+
+ s = strstr(tmp, ".tgz");
+ *s = '\0';
Home |
Main Index |
Thread Index |
Old Index