Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.sbin/pkg_install FTP wildcard depends code, initial commit.



details:   https://anonhg.NetBSD.org/src/rev/b0475317f892
branches:  trunk
changeset: 480783:b0475317f892
user:      hubertf <hubertf%NetBSD.org@localhost>
date:      Wed Jan 19 23:28:28 2000 +0000

description:
FTP wildcard depends code, initial commit.

Modulo some code cleanup, this gives NetBSD full wildcard support not
only in pkgsrc, but esp. for binary packages installed from local disk
and via FTP. For more information, see:

        http://www.feyrer.de/NetBSD/wildcards.html

diffstat:

 usr.sbin/pkg_install/add/main.c          |   44 +-
 usr.sbin/pkg_install/add/perform.c       |  131 ++++-
 usr.sbin/pkg_install/add/pkg_add.1       |    8 +-
 usr.sbin/pkg_install/create/pkg_create.1 |    8 +-
 usr.sbin/pkg_install/delete/perform.c    |    6 +-
 usr.sbin/pkg_install/info/perform.c      |    5 +-
 usr.sbin/pkg_install/info/pkg_info.1     |    7 +-
 usr.sbin/pkg_install/lib/Makefile        |    5 +-
 usr.sbin/pkg_install/lib/exec.c          |    8 +-
 usr.sbin/pkg_install/lib/file.c          |  149 +++++-
 usr.sbin/pkg_install/lib/ftpio.c         |  748 +++++++++++++++++++++++++++++++
 usr.sbin/pkg_install/lib/lib.h           |   10 +-
 usr.sbin/pkg_install/lib/str.c           |    7 +-
 13 files changed, 1070 insertions(+), 66 deletions(-)

diffs (truncated from 1532 to 300 lines):

diff -r 82cb7fcf90ed -r b0475317f892 usr.sbin/pkg_install/add/main.c
--- a/usr.sbin/pkg_install/add/main.c   Wed Jan 19 23:06:06 2000 +0000
+++ b/usr.sbin/pkg_install/add/main.c   Wed Jan 19 23:28:28 2000 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: main.c,v 1.13 1999/11/10 18:51:47 abs Exp $    */
+/*     $NetBSD: main.c,v 1.14 2000/01/19 23:28:28 hubertf Exp $        */
 
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static char *rcsid = "from FreeBSD Id: main.c,v 1.16 1997/10/08 07:45:43 charnier Exp";
 #else
-__RCSID("$NetBSD: main.c,v 1.13 1999/11/10 18:51:47 abs Exp $");
+__RCSID("$NetBSD: main.c,v 1.14 2000/01/19 23:28:28 hubertf Exp $");
 #endif
 #endif
 
@@ -134,24 +134,54 @@
                                                warn("realpath failed for '%s'", *argv);
                                        } else
                                                lpp = alloc_lpkg(cp);
-                               } else if (ispkgpattern(*argv)
-                                           && (s = findbestmatchingname(dirname_of(*argv),
+                               } else if (ispkgpattern(*argv)) {
+                                           if ((s = findbestmatchingname(dirname_of(*argv),
                                            basename_of(*argv))) != NULL) {
+                                                   char tmp[FILENAME_MAX];
+                                                   
+                                                   snprintf(tmp, sizeof(tmp), "%s/%s", dirname_of(*argv), s);
+                                                   
+                                                   if (Verbose)
+                                                           printf("Using %s for %s\n", tmp, *argv);
+                                                   
+                                                   if (!(cp = realpath(tmp, pkgname))) {
+                                                           lpp = NULL;
+                                                           warn("realpath failed for '%s'", tmp);
+                                                   } else
+                                                           lpp = alloc_lpkg(cp);
+                                           } else {
+                                                   lpp = NULL;
+                                                   warnx("can't find package pattern '%s'", *argv);
+                                           }
+                               } else {
+                                       /* Maybe just a pkg name w/o pattern was given */
+                                       char tmp[FILENAME_MAX];
+                                               
+                                       snprintf(tmp, sizeof(tmp), "%s-[0-9]*.tgz", *argv);
+                                       s=findbestmatchingname(dirname_of(tmp),
+                                                              basename_of(tmp));
+                                       if (s) {
+                                               char tmp2[FILENAME_MAX];
+                                               
+                                               snprintf(tmp2, sizeof(tmp2), "%s/%s", dirname_of(tmp), s);
+                                               
                                        if (Verbose)
-                                               printf("Using %s for %s\n", s, *argv);
+                                                       printf("Using %s for %s\n", tmp2, *argv);
 
-                                       if (!(cp = realpath(s, pkgname))) {
+                                               if (!(cp = realpath(tmp2, pkgname))) {
                                                lpp = NULL;
-                                               warn("realpath failed for '%s'", s);
+                                                       warn("realpath failed for '%s'", tmp2);
                                        } else
                                                lpp = alloc_lpkg(cp);
                                } else {
+                                               /* No go there... */
                                        /* look for the file(pattern) in the expected places */
                                        if (!(cp = fileFindByPath(NULL, *argv))) {
                                                lpp = NULL;
                                                warnx("can't find package '%s'", *argv);
                                        } else
                                                lpp = alloc_lpkg(cp);
+                                       }
                                }
                        }
                        if (lpp)
diff -r 82cb7fcf90ed -r b0475317f892 usr.sbin/pkg_install/add/perform.c
--- a/usr.sbin/pkg_install/add/perform.c        Wed Jan 19 23:06:06 2000 +0000
+++ b/usr.sbin/pkg_install/add/perform.c        Wed Jan 19 23:28:28 2000 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: perform.c,v 1.43 2000/01/09 17:21:53 hubertf Exp $     */
+/*     $NetBSD: perform.c,v 1.44 2000/01/19 23:28:28 hubertf Exp $     */
 
 #include <sys/cdefs.h>
 #ifndef lint
 #if 0
 static const char *rcsid = "from FreeBSD Id: perform.c,v 1.44 1997/10/13 15:03:46 jkh Exp";
 #else
-__RCSID("$NetBSD: perform.c,v 1.43 2000/01/09 17:21:53 hubertf Exp $");
+__RCSID("$NetBSD: perform.c,v 1.44 2000/01/19 23:28:28 hubertf Exp $");
 #endif
 #endif
 
@@ -34,6 +34,7 @@
 #include "add.h"
 
 #include <signal.h>
+#include <string.h>
 #include <sys/wait.h>
 
 static char LogDir[FILENAME_MAX];
@@ -124,19 +125,72 @@
                 * specification?
                 */
                if (IS_URL(pkg)) {
+                       char buf[FILENAME_MAX];
+                       char *tmppkg = pkg;
+
                        if (ispkgpattern(pkg)) {
+#if 0
                                warnx("patterns not supported in URLs, "
-                                   "please install manually!");
+                                   "please install %s manually!", pkg);
                                /* ... until we come up with a better solution :-/  - HF */
+                               
                                goto bomb;
+#else
+                               {
+                                       /* Handle wildcard wildcard depends */
+ 
+                                       char *s;
+                                       s=fileFindByPath(NULL, pkg);
+                                       if (s == NULL) {
+                                               warnx("no pkg found for '%s', sorry.", pkg);
+                                               return 1;
+                                       }
+                                       strcpy(buf, s);
+                                       tmppkg = buf;
+                               } 
+#endif
                        }
                        
-                       if (!(Home = fileGetURL(NULL, pkg))) {
-                               warnx("unable to fetch `%s' by URL", pkg);
+                       if (!(Home = fileGetURL(NULL, tmppkg))) {
+                               warnx("unable to fetch `%s' by URL", tmppkg);
+                               if (ispkgpattern(pkg))
+                                       return 1;
+
+                               if (strstr(pkg, ".tgz") != NULL) {
+                                       /* There already is a ".tgz" - give up 
+                                        * (We don't want to pretend to be exceedingly
+                                        *  clever - the user should give something sane!)
+                                        */
+                                       return 1;
+                       }
+                       
+                               
+                               /* Second chance - maybe just a package name was given,
+                                * without even a wildcard as a version. Tack on
+                                * the same pattern as we do for local packages: "-[0-9]*",
+                                * plus a ".tgz" as we're talking binary pkgs here.
+                                * Then retry.
+                                */
+                               {
+                                       char *s;
+                                       char buf2[FILENAME_MAX];
+                                       
+                                       snprintf(buf2, sizeof(buf2), "%s-[0-9]*.tgz", tmppkg);
+                                       s=fileFindByPath(NULL, buf2);
+                                       if (s == NULL) {
+                                               warnx("no pkg found for '%s' on 2nd try, sorry.", buf2);
+                                               return 1;
+                                       }
+                                       strcpy(buf, s);
+                                       tmppkg = buf;
+                                       if (!(Home = fileGetURL(NULL, tmppkg))) {
+                                               warnx("unable to fetch `%s' by URL", tmppkg);
                                return 1;
                        }
+                               }
+                       }
                        where_to = Home;
-                       strcpy(pkg_fullname, pkg);
+                       strcpy(pkg_fullname, tmppkg);
                        cfile = fopen(CONTENTS_FNAME, "r");
                        if (!cfile) {
                                warnx("unable to open table of contents file `%s' - not a package?",
@@ -341,52 +395,82 @@
                                                                ++code;
                                                }
                                        } else {
-                                               warnx("add of dependency `%s' failed%s",
-                                                   p->name, Force ? " (proceeding anyway)" : "!");
+                                               warnx("<%s> (1) add of dependency `%s' failed%s",
+                                                   pkg, p->name, Force ? " (proceeding anyway)" : "!");
                                                if (!Force)
                                                        ++code;
                                        } /* cp */
                                } else {
-                                       /* install depending pkg via FTP */
+                                       /* pkg is url -> install depending pkg via FTP */
+
+                                       char   *saved_Current;  /* allocated/set by save_dirs(), */
+                                       char   *saved_Previous; /* freed by restore_dirs() */
+                                       char   *cp, *new_pkg, *new_name;
+
+                                       new_pkg = pkg;
+                                       new_name = p->name;
 
                                        if (ispkgpattern(p->name)) {
+#if 0
                                                warnx("can't install dependent pkg '%s' via FTP, "
                                                    "please install manually!", p->name);
                                                /* ... until we come up with a better solution - HF */
+ 
                                                goto bomb;
-                                       } else {
-                                               char   *saved_Current;  /* allocated/set by save_dirs(), */
-                                               char   *saved_Previous; /* freed by restore_dirs() */
-                                               char   *cp;
+#else
+                                               {
+                                                       /* Might hack stuff for wildcard depends in here - HF */
+                                                       
+                                                       char *s;
+                                                       s=fileFindByPath(pkg, p->name);
+                                                       printf("HF: pkg='%s'\n", pkg);
+                                                       printf("HF: s='%s'\n", s);
 
+                                                       /* adjust new_pkg and new_name */
+                                                       new_pkg = NULL;
+                                                       new_name = s;
+                                               }                                               
+#endif
+                                       }
+
+                                       /* makeplaypen() and leave_playpen() clobber Current and
+                                        * Previous, save them! */
                                                save_dirs(&saved_Current, &saved_Previous);
 
-                                               if ((cp = fileGetURL(pkg, p->name)) != NULL) {
+                                       if ((cp = fileGetURL(new_pkg, new_name)) != NULL) {
                                                        if (Verbose)
-                                                               printf("Finished loading %s over FTP.\n", p->name);
+                                                       printf("Finished loading %s over FTP.\n", new_name);
                                                        if (!fexists(CONTENTS_FNAME)) {
                                                                warnx("autoloaded package %s has no %s file?",
                                                                    p->name, CONTENTS_FNAME);
                                                                if (!Force)
                                                                        ++code;
-                                                       } else if (vsystem("(pwd; cat %s) | pkg_add %s%s%s %s-S",
+                                               } else {
+                                                       if (vsystem("(pwd; cat %s) | pkg_add %s%s%s %s-S",
                                                                        CONTENTS_FNAME,
                                                                        Force ? "-f " : "",
                                                                        Prefix ? "-p " : "",
                                                                        Prefix ? Prefix : "",
                                                                Verbose ? "-v " : "")) {
-                                                               warnx("add of dependency `%s' failed%s",
-                                                                   p->name, Force ? " (proceeding anyway)" : "!");
+                                                               warnx("<%s> (2) add of dependency `%s' failed%s",
+                                                                     pkg, p->name, Force ? " (proceeding anyway)" : "!");
                                                                if (!Force)
                                                                        ++code;
-                                                       } else if (Verbose)
-                                                               printf("\t`%s' loaded successfully.\n", p->name);
+                                                       } else if (Verbose) {
+                                                               printf("\t`%s' loaded successfully as `%s'.\n", p->name, new_name);
+                                                       }
+                                               }
                                                        /* Nuke the temporary playpen */
                                                        leave_playpen(cp);
 
-                                                       restore_dirs(saved_Current, saved_Previous);
-                                               }
+                                       } else {
+                                               if (Verbose)
+                                                       warnx("HF: fileGetURL('%s', '%s') failed", new_pkg, new_name);
+                                               if (!Force)
+                                                       code++;
                                        }
+                                       
+                                       restore_dirs(saved_Current, saved_Previous);
                                }
                        } else {
                                /* fake install (???) */
@@ -628,5 +712,8 @@
                        free_lpkg(lpp);
                }
        }
+       
+       ftp_stop();
+       
        return err_cnt;
 }
diff -r 82cb7fcf90ed -r b0475317f892 usr.sbin/pkg_install/add/pkg_add.1
--- a/usr.sbin/pkg_install/add/pkg_add.1        Wed Jan 19 23:06:06 2000 +0000
+++ b/usr.sbin/pkg_install/add/pkg_add.1        Wed Jan 19 23:28:28 2000 +0000
@@ -1,4 +1,4 @@
-.\" $NetBSD: pkg_add.1,v 1.18 2000/01/04 22:39:28 hubertf Exp $
+.\" $NetBSD: pkg_add.1,v 1.19 2000/01/19 23:28:28 hubertf Exp $
 .\"
 .\" FreeBSD install - a package for the installation and maintainance
 .\" of non-core utilities.
@@ -363,10 +363,10 @@
 is used if a given package can't be found, it's usually set to
 .Pa /usr/pkgsrc/packages/All .
 The environment variable



Home | Main Index | Thread Index | Old Index