Source-Changes-HG archive

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

[src/netbsd-1-6]: src/usr.sbin/pkg_install/lib Pull up revision 1.3 (requeste...



details:   https://anonhg.NetBSD.org/src/rev/1a538f0a8993
branches:  netbsd-1-6
changeset: 529504:1a538f0a8993
user:      tron <tron%NetBSD.org@localhost>
date:      Sun Nov 24 22:22:57 2002 +0000

description:
Pull up revision 1.3 (requested by jschauma in ticket #1011):
Introduce path_prepend_from_pkgname() and path_remove_first() and
use in pkg_add to ensure the location of the package being added is
checked first for any additional packages.

diffstat:

 usr.sbin/pkg_install/lib/path.c |  98 ++++++++++++++++++++++++++++------------
 1 files changed, 68 insertions(+), 30 deletions(-)

diffs (147 lines):

diff -r b789d807faa3 -r 1a538f0a8993 usr.sbin/pkg_install/lib/path.c
--- a/usr.sbin/pkg_install/lib/path.c   Sun Nov 24 22:22:49 2002 +0000
+++ b/usr.sbin/pkg_install/lib/path.c   Sun Nov 24 22:22:57 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: path.c,v 1.1.2.3 2002/11/24 22:21:32 tron Exp $        */
+/*     $NetBSD: path.c,v 1.1.2.4 2002/11/24 22:22:57 tron Exp $        */
 
 /*-
  * Copyright (c)2002 YAMAMOTO Takashi,
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: path.c,v 1.1.2.3 2002/11/24 22:21:32 tron Exp $");
+__RCSID("$NetBSD: path.c,v 1.1.2.4 2002/11/24 22:22:57 tron Exp $");
 #endif
 
 #include <err.h>
@@ -37,6 +37,8 @@
 
 struct pathhead PkgPath = TAILQ_HEAD_INITIALIZER(PkgPath);
 
+static struct path *path_new_entry(const char *cp, size_t len);
+
 /*
  * path_create: make PkgPath from a given string.
  *
@@ -48,8 +50,6 @@
 {
        const char *cp;
        size_t len;
-       char cwd[MAXPATHLEN];
-       size_t cwdlen;
 
        path_free();
 
@@ -60,10 +60,6 @@
        if (Verbose)
                printf("parsing: %s\n", path);
 
-       if (getcwd(cwd, sizeof(cwd)) == NULL)
-               err(1, "getcwd");
-       cwdlen = strlen(cwd);
-
        cp = path;
        while (*cp) {
                len = strcspn(cp, ";");
@@ -71,28 +67,7 @@
                        /* add a new path */
                        struct path *new;
 
-                       new = malloc(sizeof(*new));
-                       if (new == NULL)
-                               err(1, "path_create");
-
-                       if (!IS_FULLPATH(cp) && !IS_URL(cp)) {
-                               /* this is a relative path */
-                               size_t total;
-
-                               total = cwdlen + 1 + len + 1;
-                               new->pl_path = malloc(total);
-                               if (new->pl_path == NULL)
-                                       err(1, "path_create");
-                               snprintf(new->pl_path, total, "%s/%*.*s", cwd, (int)len, (int)len, cp);
-                       }
-                       else {
-                               new->pl_path = malloc(len + 1);
-                               if (new->pl_path == NULL)
-                                       err(1, "path_create");
-                               memcpy(new->pl_path, cp, len);
-                               new->pl_path[len] = '\0';
-                       }
-
+                       new = path_new_entry(cp, len);
                        if (Verbose)
                                printf("path: %s\n", new->pl_path);
                        TAILQ_INSERT_TAIL(&PkgPath, new, pl_entry);
@@ -121,6 +96,69 @@
 }
 
 /*
+ * path_new_entry: Generate a new 'struct path' entry to be included in
+ * 'PkgPath' using the first 'len' characters of 'cp'.
+ */
+static struct path *
+path_new_entry(const char *cp, size_t len)
+{
+       struct path *new;
+
+       new = malloc(sizeof(*new));
+       if (new == NULL)
+               err(1, "path_create");
+
+       if (!IS_FULLPATH(cp) && !IS_URL(cp)) {
+               /* this is a relative path */
+               size_t total;
+               char cwd[MAXPATHLEN];
+               size_t cwdlen;
+
+               if (getcwd(cwd, sizeof(cwd)) == NULL)
+                       err(1, "getcwd");
+               cwdlen = strlen(cwd);
+               total = cwdlen + 1 + len + 1;
+               new->pl_path = malloc(total);
+               if (new->pl_path == NULL)
+                       err(1, "path_create");
+               snprintf(new->pl_path, total, "%s/%*.*s", cwd, (int)len, (int)len, cp);
+       }
+       else {
+               new->pl_path = malloc(len + 1);
+               if (new->pl_path == NULL)
+                       err(1, "path_create");
+               memcpy(new->pl_path, cp, len);
+               new->pl_path[len] = '\0';
+       }
+       return new;
+}
+
+/*
+ * Given a package name, push its path onto the start of 'PkgPath'
+ */
+void
+path_prepend_from_pkgname(const char *pkgname)
+{
+       struct path *new;
+       char *ptr;
+       if ((ptr = strrchr(pkgname , '/')))
+               new = path_new_entry(pkgname, ptr - pkgname);
+       else
+               new = path_new_entry(".", 1);
+
+       TAILQ_INSERT_HEAD(&PkgPath, new, pl_entry);
+}
+
+/*
+ * Remove the first entry of 'PkgPath' - used after path_prepend_from_pkgname()
+ */
+void
+path_remove_first()
+{
+       TAILQ_REMOVE(&PkgPath, TAILQ_FIRST(&PkgPath), pl_entry);
+}
+
+/*
  * path_setenv: construct string from PkgPath and set it to a environment.
  *
  * => the environment name is given by envname.



Home | Main Index | Thread Index | Old Index