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 * in pkg_add, before the "install depen...



details:   https://anonhg.NetBSD.org/src/rev/b584d2091aab
branches:  trunk
changeset: 483848:b584d2091aab
user:      hubertf <hubertf%NetBSD.org@localhost>
date:      Sun Mar 19 17:24:27 2000 +0000

description:
* in pkg_add, before the "install dependencies" loop, check ALL
   dependencies if they _can_ be installed. I.e. if a package wants
   version X installed, but version Y is already installed, pkg_adding
   that required pkg will blow up later (probably some pkg_add recursions
   down, given what we keep in the depends list). Now, it stopps right
   away:

        noon# pkg_add /usr/pkgsrc/packages/i386ELF/All/xdaemon-1.0.tgz
        pkg_add: pkg `xteddy-1.*' required, but `xteddy-2.0.1' found installed.
        Please resolve this conflict!

   The idea of this is from Thomas Klausner, further inputs from Alistair
   Crooks.

 * allow pkg names without versions given to "pkg_admin check"
 * Use sizeof() instead of hardcoding the buffers' size in some places

diffstat:

 usr.sbin/pkg_install/add/perform.c |  56 ++++++++++++++++++++++++++++++-------
 usr.sbin/pkg_install/admin/main.c  |  35 ++++++++++++++++-------
 2 files changed, 69 insertions(+), 22 deletions(-)

diffs (191 lines):

diff -r 2cd4867428ac -r b584d2091aab usr.sbin/pkg_install/add/perform.c
--- a/usr.sbin/pkg_install/add/perform.c        Sun Mar 19 17:11:50 2000 +0000
+++ b/usr.sbin/pkg_install/add/perform.c        Sun Mar 19 17:24:27 2000 +0000
@@ -1,11 +1,11 @@
-/*     $NetBSD: perform.c,v 1.45 2000/01/25 12:09:19 hubertf Exp $     */
+/*     $NetBSD: perform.c,v 1.46 2000/03/19 17:24:27 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.45 2000/01/25 12:09:19 hubertf Exp $");
+__RCSID("$NetBSD: perform.c,v 1.46 2000/03/19 17:24:27 hubertf Exp $");
 #endif
 #endif
 
@@ -310,17 +310,14 @@
 
        /* See if some other version of us is already installed */
        {
-               char    buf[FILENAME_MAX];
-               char    installed[FILENAME_MAX];
                char   *s;
 
                if ((s = strrchr(PkgName, '-')) != NULL) {
-                       int     l;
+                       char    buf[FILENAME_MAX];
+                       char    installed[FILENAME_MAX];
 
-                       l = s - PkgName + 1;
-                       (void) memcpy(buf, PkgName, l);
-                       (void) strcpy(&buf[l], "[0-9]*");
-
+                       (void) snprintf(buf, sizeof(buf), "%.*s[0-9]*",
+                               (int)(s - PkgName) + 1, PkgName);
                        if (findmatchingname(dbdir, buf, note_whats_installed, installed) > 0) {
                                warnx("other version '%s' already installed", installed);
                                code = 1;
@@ -341,11 +338,48 @@
                /* was: */
                /* if (!vsystem("/usr/sbin/pkg_info -qe '%s'", p->name)) { */
                if (findmatchingname(dbdir, p->name, note_whats_installed, installed) > 0) {
-                       warnx("Conflicting package installed, please use\n\t\"pkg_delete %s\" first to remove it!\n", installed);
+                       warnx("Conflicting package `%s'installed, please use\n"
+                             "\t\"pkg_delete %s\" first to remove it!\n", installed, installed);
                        ++code;
                }
        }
 
+       /* Quick pre-check if any conflicting dependencies are installed
+        * (e.g. version X is installed, but version Y is required)
+        */
+       for (p = Plist.head; p; p = p->next) {
+               char installed[FILENAME_MAX];
+               
+               if (p->type != PLIST_PKGDEP)
+                       continue;
+               if (Verbose)
+                       printf("Depends pre-scan: `%s' required.\n", p->name);
+               /* if (vsystem("/usr/sbin/pkg_info -qe '%s'", p->name)) { */
+               if (findmatchingname(dbdir, p->name, note_whats_installed, installed) <= 0) {
+                       /* 
+                        * required pkg not found. look if it's available with a more liberal
+                        * pattern. If so, this will lead to problems later (check on "some
+                        * other version of us is already installed" will fail, see above),
+                        * and we better stop right now.
+                        */
+                       char *s;
+                       
+                       if ((s = strrchr(p->name, '-')) != NULL) {
+                               char    buf[FILENAME_MAX];
+               
+                               (void) snprintf(buf, sizeof(buf), "%.*s[0-9]*",
+                                       (int)(s - p->name) + 1, p->name);
+                               if (findmatchingname(dbdir, buf, note_whats_installed, installed) > 0) {
+                                       warnx("pkg `%s' required, but `%s' found installed.\n"
+                                             "Please resolve this conflict!", p->name, installed);
+                                       code = 1;
+                                       goto success; /* close enough */
+                               }
+                       }
+               }
+       }
+       
+
        /* Now check the packing list for dependencies */
        for (p = Plist.head; p; p = p->next) {
                char    installed[FILENAME_MAX];
@@ -546,7 +580,7 @@
                if (make_hierarchy(LogDir)) {
                        warnx("can't record package into '%s', you're on your own!",
                            LogDir);
-                       memset(LogDir, 0, FILENAME_MAX);
+                       memset(LogDir, 0, sizeof(LogDir));
                        code = 1;
                        goto success;   /* close enough for government work */
                }
diff -r 2cd4867428ac -r b584d2091aab usr.sbin/pkg_install/admin/main.c
--- a/usr.sbin/pkg_install/admin/main.c Sun Mar 19 17:11:50 2000 +0000
+++ b/usr.sbin/pkg_install/admin/main.c Sun Mar 19 17:24:27 2000 +0000
@@ -1,8 +1,8 @@
-/*     $NetBSD: main.c,v 1.11 2000/02/22 01:24:26 hubertf Exp $        */
+/*     $NetBSD: main.c,v 1.12 2000/03/19 17:24:28 hubertf Exp $        */
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: main.c,v 1.11 2000/02/22 01:24:26 hubertf Exp $");
+__RCSID("$NetBSD: main.c,v 1.12 2000/03/19 17:24:28 hubertf Exp $");
 #endif
 
 /*
@@ -53,6 +53,7 @@
 extern const char *__progname; /* from crt0.o */
 
 int     filecnt;
+int     pkgcnt;
 
 /*
  * Assumes CWD is in /var/db/pkg/<pkg>!
@@ -144,6 +145,8 @@
        }
        free_plist(&Plist);
        fclose(f);
+
+       pkgcnt++;
 }
 
 static void 
@@ -155,8 +158,8 @@
        plist_t *p;
        char   *PkgName, dir[FILENAME_MAX], *dirp = NULL;
        char   *PkgDBDir = NULL, file[FILENAME_MAX];
-       int     pkgcnt = 0;
 
+       pkgcnt = 0;
        filecnt = 0;
 
        if (unlink(_pkgdb_getPKGDB_FILE()) != 0 && errno != ENOENT)
@@ -275,8 +278,8 @@
 {
        DIR    *dp;
        struct dirent *de;
-       int     pkgcnt = 0;
 
+       pkgcnt = 0;
        filecnt = 0;
 
        setbuf(stdout, NULL);
@@ -346,7 +349,6 @@
 
                if (*argv != NULL) {
                        /* args specified */
-                       int     pkgcnt = 0;
                        int     rc;
 
                        filecnt = 0;
@@ -363,16 +365,27 @@
                                                errx(1, "No matching pkg for %s.", *argv);
                                } else {
                                        rc = chdir(*argv);
-                                       if (rc == -1)
-                                               err(1, "Cannot chdir to %s/%s", _pkgdb_getPKGDB_DIR(), *argv);
+                                       if (rc == -1) {
+                                               /* found nothing - try 'pkg-[0-9]*' */
+                                               char try[FILENAME_MAX];
+                                       
+                                               snprintf(try, sizeof(try), "%s-[0-9]*", *argv);
+                                               if (findmatchingname(_pkgdb_getPKGDB_DIR(), try,
+                                                                    checkpattern_fn, NULL) <= 0) {
 
-                                       check1pkg(*argv);
-                                       printf(".");
+                                                       errx(1, "cannot find package %s", *argv);
+                                               } else {
+                                                       /* nothing to do - all the work is/was
+                                                        * done in checkpattern_fn() */
+                                               }
+                                       } else {
+                                               check1pkg(*argv);
+                                               printf(".");
 
-                                       chdir("..");
+                                               chdir("..");
+                                       }
                                }
 
-                               pkgcnt++;
                                argv++;
                        }
 



Home | Main Index | Thread Index | Old Index