Source-Changes-HG archive

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

[src/PKGSRC]: src/external/bsd/pkg_install/dist Import pkg_install from pkgsr...



details:   https://anonhg.NetBSD.org/src/rev/80f890b099ac
branches:  PKGSRC
changeset: 946581:80f890b099ac
user:      wiz <wiz%NetBSD.org@localhost>
date:      Wed Dec 02 13:49:25 2020 +0000

description:
Import pkg_install from pkgsrc as of 20201202.

This changes the default database path from /var/db/pkg to /usr/pkg/pkgdb

diffstat:

 external/bsd/pkg_install/dist/add/perform.c              |  104 ++++++---
 external/bsd/pkg_install/dist/admin/check.c              |   10 +-
 external/bsd/pkg_install/dist/admin/main.c               |  154 ++++++++++++--
 external/bsd/pkg_install/dist/admin/pkg_admin.1          |   10 +-
 external/bsd/pkg_install/dist/create/perform.c           |    6 +-
 external/bsd/pkg_install/dist/create/pl.c                |    8 +-
 external/bsd/pkg_install/dist/info/perform.c             |    8 +-
 external/bsd/pkg_install/dist/lib/iterate.c              |  141 +++++++++++++-
 external/bsd/pkg_install/dist/lib/lib.h                  |   25 ++-
 external/bsd/pkg_install/dist/lib/license.c              |    3 +-
 external/bsd/pkg_install/dist/lib/pkgdb.c                |   24 +-
 external/bsd/pkg_install/dist/lib/plist.c                |   13 +-
 external/bsd/pkg_install/dist/lib/version.h              |    4 +-
 external/bsd/pkg_install/dist/lib/vulnerabilities-file.c |    6 +-
 14 files changed, 410 insertions(+), 106 deletions(-)

diffs (truncated from 950 to 300 lines):

diff -r 5c9d460d1ebe -r 80f890b099ac external/bsd/pkg_install/dist/add/perform.c
--- a/external/bsd/pkg_install/dist/add/perform.c       Sun Oct 13 21:52:26 2019 +0000
+++ b/external/bsd/pkg_install/dist/add/perform.c       Wed Dec 02 13:49:25 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: perform.c,v 1.1.1.23 2018/03/27 23:08:43 joerg Exp $   */
+/*     $NetBSD: perform.c,v 1.1.1.24 2020/12/02 13:49:25 wiz Exp $     */
 #if HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -6,7 +6,7 @@
 #if HAVE_SYS_CDEFS_H
 #include <sys/cdefs.h>
 #endif
-__RCSID("$NetBSD: perform.c,v 1.1.1.23 2018/03/27 23:08:43 joerg Exp $");
+__RCSID("$NetBSD: perform.c,v 1.1.1.24 2020/12/02 13:49:25 wiz Exp $");
 
 /*-
  * Copyright (c) 2003 Grant Beattie <grant%NetBSD.org@localhost>
@@ -450,7 +450,7 @@
                return -1;
        }
        *iter = '\0';
-       pkg->other_version = find_best_matching_installed_pkg(pkgbase);
+       pkg->other_version = find_best_matching_installed_pkg(pkgbase, 0);
        free(pkgbase);
        if (pkg->other_version == NULL)
                return 0;
@@ -505,10 +505,12 @@
                                continue;
                        if (pkg_match(p->name, pkg->pkgname) == 1)
                                continue; /* Both match, ok. */
-                       warnx("Dependency of %s fulfilled by %s, but not by %s",
-                           iter, pkg->other_version, pkg->pkgname);
-                       if (!ForceDepending)
+                       if (!ForceDepending) {
+                               warnx("Dependency of %s fulfilled by %s, "
+                                   "but not by %s", iter, pkg->other_version,
+                                   pkg->pkgname);
                                status = -1;
+                       }
                        break;
                }
                free_plist(&plist);             
@@ -979,7 +981,8 @@
        setenv(PKG_REFCOUNT_DBDIR_VNAME, config_pkg_refcount_dbdir, 1);
 
        if (Verbose)
-               printf("Running install with PRE-INSTALL for %s.\n", pkg->pkgname);
+               printf("Running install with %s for %s.\n", argument,
+                   pkg->pkgname);
        if (Fake)
                return 0;
 
@@ -1102,6 +1105,40 @@
        return status;
 }
 
+/*
+ * Install a required dependency and verify its installation.
+ */
+static int
+install_depend_pkg(const char *dep)
+{
+       /* XXX check cyclic dependencies? */
+       if (Fake || NoRecord) {
+               if (!Force) {
+                       warnx("Missing dependency %s\n", dep);
+                       return 1;
+               }
+               warnx("Missing dependency %s, continuing", dep);
+       }
+
+       if (pkg_do(dep, 1, 0)) {
+               if (!ForceDepends) {
+                       warnx("Can't install dependency %s", dep);
+                       return 1;
+               }
+               warnx("Can't install dependency %s, continuing", dep);
+       }
+
+       if (find_best_matching_installed_pkg(dep, 0) == NULL) {
+               if (!ForceDepends) {
+                       warnx("Just installed dependency %s disappeared", dep);
+                       return 1;
+               }
+               warnx("Missing dependency %s ignored", dep);
+       }
+
+       return 0;
+}
+
 static int
 check_dependencies(struct pkg_task *pkg)
 {
@@ -1112,6 +1149,9 @@
 
        status = 0;
 
+       /*
+        * Recursively handle dependencies, installing as required.
+        */
        for (p = pkg->plist.head; p != NULL; p = p->next) {
                if (p->type == PLIST_IGNORE) {
                        p = p->next;
@@ -1119,43 +1159,27 @@
                } else if (p->type != PLIST_PKGDEP)
                        continue;
 
-               best_installed = find_best_matching_installed_pkg(p->name);
-
-               if (best_installed == NULL) {
-                       /* XXX check cyclic dependencies? */
-                       if (Fake || NoRecord) {
-                               if (!Force) {
-                                       warnx("Missing dependency %s\n",
-                                            p->name);
-                                       status = -1;
-                                       break;
-                               }
-                               warnx("Missing dependency %s, continuing",
-                                   p->name);
-                               continue;
-                       }
-                       if (pkg_do(p->name, 1, 0)) {
-                               if (ForceDepends) {
-                                       warnx("Can't install dependency %s, "
-                                           "continuing", p->name);
-                                       continue;
-                               } else {
-                                       warnx("Can't install dependency %s",
-                                           p->name);
-                                       status = -1;
-                                       break;
-                               }
-                       }
-                       best_installed = find_best_matching_installed_pkg(p->name);
-                       if (best_installed == NULL && ForceDepends) {
-                               warnx("Missing dependency %s ignored", p->name);
-                               continue;
-                       } else if (best_installed == NULL) {
-                               warnx("Just installed dependency %s disappeared", p->name);
+               if (find_best_matching_installed_pkg(p->name, 0) == NULL) {
+                       if (install_depend_pkg(p->name) != 0) {
                                status = -1;
                                break;
                        }
                }
+       }
+
+       /*
+        * Now that all dependencies have been processed we can find the best
+        * matches for pkg_register_depends() to store in our +REQUIRED_BY.
+        */
+       for (p = pkg->plist.head; p != NULL; p = p->next) {
+               if (p->type == PLIST_IGNORE) {
+                       p = p->next;
+                       continue;
+               } else if (p->type != PLIST_PKGDEP)
+                       continue;
+
+               best_installed = find_best_matching_installed_pkg(p->name, 0);
+
                for (i = 0; i < pkg->dep_length; ++i) {
                        if (strcmp(best_installed, pkg->dependencies[i]) == 0)
                                break;
diff -r 5c9d460d1ebe -r 80f890b099ac external/bsd/pkg_install/dist/admin/check.c
--- a/external/bsd/pkg_install/dist/admin/check.c       Sun Oct 13 21:52:26 2019 +0000
+++ b/external/bsd/pkg_install/dist/admin/check.c       Wed Dec 02 13:49:25 2020 +0000
@@ -1,5 +1,8 @@
-/*     $NetBSD: check.c,v 1.1.1.4 2010/01/30 21:33:23 joerg Exp $      */
+/*     $NetBSD: check.c,v 1.1.1.5 2020/12/02 13:49:25 wiz Exp $        */
 
+#ifdef HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#else
 #if HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -7,7 +10,8 @@
 #if HAVE_SYS_CDEFS_H
 #include <sys/cdefs.h>
 #endif
-__RCSID("$NetBSD: check.c,v 1.1.1.4 2010/01/30 21:33:23 joerg Exp $");
+#endif
+__RCSID("$NetBSD: check.c,v 1.1.1.5 2020/12/02 13:49:25 wiz Exp $");
 
 /*-
  * Copyright (c) 1999-2008 The NetBSD Foundation, Inc.
@@ -77,7 +81,7 @@
 static int checkpattern_fn(const char *, void *);
 
 /*
- * Assumes CWD is in /var/db/pkg/<pkg>!
+ * Assumes CWD is in the database directory ($PREFIX/pkgdb/<pkg>)!
  */
 static void 
 check1pkg(const char *pkgdir, int *filecnt, int *pkgcnt)
diff -r 5c9d460d1ebe -r 80f890b099ac external/bsd/pkg_install/dist/admin/main.c
--- a/external/bsd/pkg_install/dist/admin/main.c        Sun Oct 13 21:52:26 2019 +0000
+++ b/external/bsd/pkg_install/dist/admin/main.c        Wed Dec 02 13:49:25 2020 +0000
@@ -1,5 +1,8 @@
-/*     $NetBSD: main.c,v 1.1.1.18 2019/10/13 21:52:26 joerg Exp $      */
+/*     $NetBSD: main.c,v 1.1.1.19 2020/12/02 13:49:25 wiz Exp $        */
 
+#ifdef HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#else
 #if HAVE_CONFIG_H
 #include "config.h"
 #endif
@@ -7,7 +10,8 @@
 #if HAVE_SYS_CDEFS_H
 #include <sys/cdefs.h>
 #endif
-__RCSID("$NetBSD: main.c,v 1.1.1.18 2019/10/13 21:52:26 joerg Exp $");
+#endif
+__RCSID("$NetBSD: main.c,v 1.1.1.19 2020/12/02 13:49:25 wiz Exp $");
 
 /*-
  * Copyright (c) 1999-2019 The NetBSD Foundation, Inc.
@@ -90,6 +94,25 @@
        size_t packages;
 };
 
+/*
+ * A hashed list of +REQUIRED_BY entries.
+ */
+struct reqd_by_entry {
+       char *pkgname;
+       SLIST_ENTRY(reqd_by_entry) entries;
+};
+SLIST_HEAD(reqd_by_entry_head, reqd_by_entry);
+
+/*
+ * A hashed list of packages that contain +REQUIRED_BY entries.
+ */
+struct pkg_reqd_by {
+       char *pkgname;
+       struct reqd_by_entry_head required_by[PKG_HASH_SIZE];
+       SLIST_ENTRY(pkg_reqd_by) entries;
+};
+SLIST_HEAD(pkg_reqd_by_head, pkg_reqd_by);
+
 static const char Options[] = "C:K:SVbd:qs:v";
 
 int    quiet, verbose;
@@ -280,37 +303,79 @@
 }
 
 static void
-add_required_by(const char *pattern, const char *required_by)
+add_required_by(const char *pattern, const char *pkgname, struct pkg_reqd_by_head *hash)
 {
-       char *best_installed, *path;
-       int fd;
-       size_t len;
+       struct pkg_reqd_by_head *phead;
+       struct pkg_reqd_by *pkg;
+       struct reqd_by_entry_head *ehead;
+       struct reqd_by_entry *entry;
+       char *best_installed;
+       int i;
 
-       best_installed = find_best_matching_installed_pkg(pattern);
+       best_installed = find_best_matching_installed_pkg(pattern, 1);
        if (best_installed == NULL) {
-               warnx("Dependency %s of %s unresolved", pattern, required_by);
+               warnx("Dependency %s of %s unresolved", pattern, pkgname);
                return;
        }
 
-       path = pkgdb_pkg_file(best_installed, REQUIRED_BY_FNAME);
-       free(best_installed);
+       /*
+        * Find correct reqd_by head based on hash of best_installed, which is
+        * the package in question that we are adding +REQUIRED_BY entries for.
+        */
+       phead = &hash[PKG_HASH_ENTRY(best_installed)];
+
+       /*
+        * Look for an existing entry in this hash list.
+        */
+       SLIST_FOREACH(pkg, phead, entries) {
+               if (strcmp(pkg->pkgname, best_installed) == 0) {
+
+                       /*
+                        * Found an entry, now see if it already has a
+                        * +REQUIRED_BY entry recorded for this pkgname,
+                        * and if not then add it.
+                        */
+                       ehead = &pkg->required_by[PKG_HASH_ENTRY(pkgname)];
+                       SLIST_FOREACH(entry, ehead, entries) {
+                               if (strcmp(entry->pkgname, pkgname) == 0)
+                                       break;
+                       }
 
-       if ((fd = open(path, O_WRONLY | O_APPEND | O_CREAT, 0644)) == -1)
-               errx(EXIT_FAILURE, "Cannot write to %s", path);
-       free(path);
-       



Home | Main Index | Thread Index | Old Index