diff options
author | joerg <joerg@pkgsrc.org> | 2009-02-28 16:03:56 +0000 |
---|---|---|
committer | joerg <joerg@pkgsrc.org> | 2009-02-28 16:03:56 +0000 |
commit | 5bdcb8f5208e876af0951105fcf2aeb718c89f0d (patch) | |
tree | 3b6fb5f6a5a9ef3c27dea6518b98aa3bbaf8f17d /pkgtools | |
parent | 437a9f72f8b5188feaebd6c2363411e1d8c11d47 (diff) | |
download | pkgsrc-5bdcb8f5208e876af0951105fcf2aeb718c89f0d.tar.gz |
pkg_install-20090228:
Integrate the PKG_PATH logic for tightly with the find_archive logic:
- remember initial current working directory from the time PKG_PATH is
processed, it will be used as reference for all relative entries
- remove now redundant fchdir dance in pkg_add
- pass down to find_archive if this is a top-level package (e.g.
requested on the command line) or not; the location of top-level
packages is searched for packages first and for URLs or path names the
PKG_PATH itself is not processed (e.g. pkg_add foo/bar not look into
PKG_PATH for bar). This addresses PR 33884 in a different way.
- document the rules for finding packages more explicitly
- allow specifying PKG_PATH in pkg_install.conf as well; environment
takes precendence.
- remove PKG_PATH related logic in pkg_info(1), it doesn't deal with
PKG_PATH anyway
- remove PKG_PATH, PKG_TMPDIR and TMPDIR description in pkg_info(1),
they are no longer used
Diffstat (limited to 'pkgtools')
-rw-r--r-- | pkgtools/pkg_install/files/add/main.c | 6 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/add/perform.c | 27 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/add/pkg_add.1 | 31 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/add/pkg_add.cat1 | 30 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/info/main.c | 12 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/info/pkg_info.1 | 43 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/info/pkg_info.cat1 | 21 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/Makefile.in | 4 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/lib.h | 8 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/parse-config.c | 9 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/path.c | 193 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/path.h | 40 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/pkg_install.conf.5.in | 9 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/pkg_install.conf.cat5.in | 6 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/pkg_io.c | 123 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/version.h | 4 |
16 files changed, 166 insertions, 400 deletions
diff --git a/pkgtools/pkg_install/files/add/main.c b/pkgtools/pkg_install/files/add/main.c index 4f8280cbcca..da8d295ed3d 100644 --- a/pkgtools/pkg_install/files/add/main.c +++ b/pkgtools/pkg_install/files/add/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.17 2009/02/02 12:35:00 joerg Exp $ */ +/* $NetBSD: main.c,v 1.18 2009/02/28 16:03:56 joerg Exp $ */ #if HAVE_CONFIG_H #include "config.h" @@ -7,7 +7,7 @@ #if HAVE_SYS_CDEFS_H #include <sys/cdefs.h> #endif -__RCSID("$NetBSD: main.c,v 1.17 2009/02/02 12:35:00 joerg Exp $"); +__RCSID("$NetBSD: main.c,v 1.18 2009/02/28 16:03:56 joerg Exp $"); /* * @@ -152,7 +152,7 @@ main(int argc, char **argv) pkg_install_config(); - path_create(getenv("PKG_PATH")); + process_pkg_path(); TAILQ_INIT(&pkgs); if (argc == 0) { diff --git a/pkgtools/pkg_install/files/add/perform.c b/pkgtools/pkg_install/files/add/perform.c index 3d414ff4c7d..0111edbd9e2 100644 --- a/pkgtools/pkg_install/files/add/perform.c +++ b/pkgtools/pkg_install/files/add/perform.c @@ -1,4 +1,4 @@ -/* $NetBSD: perform.c,v 1.80 2009/02/27 19:34:12 joerg Exp $ */ +/* $NetBSD: perform.c,v 1.81 2009/02/28 16:03:56 joerg 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.80 2009/02/27 19:34:12 joerg Exp $"); +__RCSID("$NetBSD: perform.c,v 1.81 2009/02/28 16:03:56 joerg Exp $"); /*- * Copyright (c) 2003 Grant Beattie <grant@NetBSD.org> @@ -123,7 +123,7 @@ static const struct pkg_meta_desc { { 0, NULL, 0 }, }; -static int pkg_do(const char *, int); +static int pkg_do(const char *, int, int); static int mkdir_p(const char *path) @@ -1024,7 +1024,7 @@ check_dependencies(struct pkg_task *pkg) p->name); continue; } - if (pkg_do(p->name, 1)) { + if (pkg_do(p->name, 1, 0)) { warnx("Can't install dependency %s", p->name); status = -1; break; @@ -1238,7 +1238,7 @@ check_vulnerable(struct pkg_task *pkg) * Install a single package. */ static int -pkg_do(const char *pkgpath, int mark_automatic) +pkg_do(const char *pkgpath, int mark_automatic, int top_level) { int status, invalid_sig; void *archive_cookie; @@ -1249,7 +1249,8 @@ pkg_do(const char *pkgpath, int mark_automatic) status = -1; - if ((pkg->archive = find_archive(pkgpath, &archive_cookie)) == NULL) { + pkg->archive = find_archive(pkgpath, &archive_cookie, top_level); + if (pkg->archive == NULL) { warnx("no pkg found for '%s', sorry.", pkgpath); goto clean_find_archive; } @@ -1426,25 +1427,15 @@ clean_find_archive: int pkg_perform(lpkg_head_t *pkgs) { - int oldcwd, errors = 0; + int errors = 0; lpkg_t *lpp; - if ((oldcwd = open(".", O_RDONLY, 0)) == -1) - err(EXIT_FAILURE, "unable to open cwd"); - while ((lpp = TAILQ_FIRST(pkgs)) != NULL) { - path_prepend_from_pkgname(lpp->lp_name); - if (pkg_do(lpp->lp_name, Automatic)) + if (pkg_do(lpp->lp_name, Automatic, 1)) ++errors; - path_prepend_clear(); TAILQ_REMOVE(pkgs, lpp, lp_link); free_lpkg(lpp); - - if (fchdir(oldcwd) == -1) - err(EXIT_FAILURE, "unable to restore cwd"); } - close(oldcwd); - return errors; } diff --git a/pkgtools/pkg_install/files/add/pkg_add.1 b/pkgtools/pkg_install/files/add/pkg_add.1 index bb06709718b..3b6fd67b00c 100644 --- a/pkgtools/pkg_install/files/add/pkg_add.1 +++ b/pkgtools/pkg_install/files/add/pkg_add.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_add.1,v 1.32 2009/02/08 23:12:10 wiz Exp $ +.\" $NetBSD: pkg_add.1,v 1.33 2009/02/28 16:03:56 joerg Exp $ .\" .\" FreeBSD install - a package for the installation and maintenance .\" of non-core utilities. @@ -17,7 +17,7 @@ .\" .\" @(#)pkg_add.1 .\" -.Dd October 10, 2008 +.Dd February 27, 2009 .Dt PKG_ADD 1 .Os .Sh NAME @@ -87,19 +87,18 @@ The following command line arguments are supported: .Bl -tag -width indent .It Ar pkg-name [ ... ] The named packages are installed. -.Ar pkg-name -may be either a URL or a local pathname, -a package name of "-" will cause .Nm -to read from stdin. -If the packages are not found in the current -working directory, +will first try to use +.Ar pkg-name +as full URL or path name without any wildcard processing. +If that fails, .Nm -will search them in each directory named by the -.Ev PKG_PATH -environment variable. -Any dependencies required by the installed package will be searched -in the same location that the original package was installed from. +will try to match packages using wildcard processing. +If that fails as well and +.Ar pkg-name +does not contain any /, the entries of the +.Dv PKG_PATH +variable are searched using the wildcard processing rules. .It Fl A Mark package as installed automatically, as dependency of another package. @@ -414,14 +413,16 @@ The default package database directory is .It Ev PKG_PATH The value of the .Ev PKG_PATH -is used if a given package can't be found, it's usually set to +variable overrides the +.Xr pkg_install.conf 5 +variable of the same name. +It is used if a given package can't be found, it's usually set to .Pa /usr/pkgsrc/packages/All . The environment variable should be a series of entries separated by semicolons. Each entry consists of a directory name or URL. The current directory may be indicated implicitly by an empty directory name, or explicitly by a single period. -FTP URLs may not end with a slash. .It Ev PKG_REFCOUNT_DBDIR Location of the package reference counts database directory. The default location is the path to the package database directory with diff --git a/pkgtools/pkg_install/files/add/pkg_add.cat1 b/pkgtools/pkg_install/files/add/pkg_add.cat1 index 0d8b192a623..10acb4d1461 100644 --- a/pkgtools/pkg_install/files/add/pkg_add.cat1 +++ b/pkgtools/pkg_install/files/add/pkg_add.cat1 @@ -37,13 +37,12 @@ OOPPTTIIOONNSS The following command line arguments are supported: _p_k_g_-_n_a_m_e [_._._.] - The named packages are installed. _p_k_g_-_n_a_m_e may be either a URL - or a local pathname, a package name of "-" will cause ppkkgg__aadddd to - read from stdin. If the packages are not found in the current - working directory, ppkkgg__aadddd will search them in each directory - named by the PKG_PATH environment variable. Any dependencies - required by the installed package will be searched in the same - location that the original package was installed from. + The named packages are installed. ppkkgg__aadddd will first try to use + _p_k_g_-_n_a_m_e as full URL or path name without any wildcard process- + ing. If that fails, ppkkgg__aadddd will try to match packages using + wildcard processing. If that fails as well and _p_k_g_-_n_a_m_e does not + contain any /, the entries of the PKG_PATH variable are searched + using the wildcard processing rules. --AA Mark package as installed automatically, as dependency of another package. You can use @@ -237,13 +236,14 @@ EENNVVIIRROONNMMEENNTT the package database directory. The default package database directory is _/_v_a_r_/_d_b_/_p_k_g. - PKG_PATH The value of the PKG_PATH is used if a given package can't be - found, it's usually set to _/_u_s_r_/_p_k_g_s_r_c_/_p_a_c_k_a_g_e_s_/_A_l_l. The - environment variable should be a series of entries separated - by semicolons. Each entry consists of a directory name or - URL. The current directory may be indicated implicitly by an - empty directory name, or explicitly by a single period. FTP - URLs may not end with a slash. + PKG_PATH The value of the PKG_PATH variable is used if a given package + can't be found, it's usually set to _/_u_s_r_/_p_k_g_s_r_c_/_p_a_c_k_a_g_e_s_/_A_l_l. + The environment variable should be a series of entries sepa- + rated by semicolons. Each entry consists of a directory name + or URL. The current directory may be indicated implicitly by + an empty directory name, or explicitly by a single period. + It overrides the pkg_install.conf(5) variable of the same + name. PKG_REFCOUNT_DBDIR Location of the package reference counts database directory. @@ -317,4 +317,4 @@ BBUUGGSS Sure to be others. -NetBSD 5.0 October 10, 2008 NetBSD 5.0 +NetBSD 5.0 February 27, 2009 NetBSD 5.0 diff --git a/pkgtools/pkg_install/files/info/main.c b/pkgtools/pkg_install/files/info/main.c index 88376fa2b54..6736f2e8754 100644 --- a/pkgtools/pkg_install/files/info/main.c +++ b/pkgtools/pkg_install/files/info/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.23 2009/02/02 12:35:01 joerg Exp $ */ +/* $NetBSD: main.c,v 1.24 2009/02/28 16:03:56 joerg Exp $ */ #if HAVE_CONFIG_H #include "config.h" @@ -7,7 +7,7 @@ #if HAVE_SYS_CDEFS_H #include <sys/cdefs.h> #endif -__RCSID("$NetBSD: main.c,v 1.23 2009/02/02 12:35:01 joerg Exp $"); +__RCSID("$NetBSD: main.c,v 1.24 2009/02/28 16:03:56 joerg Exp $"); /* * @@ -242,14 +242,6 @@ main(int argc, char **argv) usage(); } - /* Don't do FTP stuff when operating on all pkgs */ - if (Which != WHICH_LIST && getenv("PKG_PATH") != 0) { - warnx("disabling PKG_PATH when operating on all packages."); - unsetenv("PKG_PATH"); - } - - path_create(getenv("PKG_PATH")); - /* Set some reasonable defaults */ if (!Flags) Flags = SHOW_COMMENT | SHOW_DESC | SHOW_REQBY diff --git a/pkgtools/pkg_install/files/info/pkg_info.1 b/pkgtools/pkg_install/files/info/pkg_info.1 index 78683024683..89676dc8ad2 100644 --- a/pkgtools/pkg_install/files/info/pkg_info.1 +++ b/pkgtools/pkg_install/files/info/pkg_info.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_info.1,v 1.22 2007/11/02 16:03:37 joerg Exp $ +.\" $NetBSD: pkg_info.1,v 1.23 2009/02/28 16:03:56 joerg Exp $ .\" .\" FreeBSD install - a package for the installation and maintenance .\" of non-core utilities. @@ -17,7 +17,7 @@ .\" .\" @(#)pkg_info.1 .\" -.Dd March 2, 2007 +.Dd February 27, 2009 .Dt PKG_INFO 1 .Os .Sh NAME @@ -301,45 +301,6 @@ flag isn't given, then is the location of the package database directory. The default package database directory is .Pa /var/db/pkg . -.It Ev PKG_PATH -This can be used to specify a semicolon-separated list of paths and URLs to search for -package files. -If -.Ev PKG_PATH -is used, the suffix -.Pa .tgz -is automatically appended to the -.Ar pkg-name , -whereas searching in the current directory uses -.Ar pkg-name -literally. -.It Ev PKG_TMPDIR , Ev TMPDIR -These are tried in turn (if set) as candidate directories in which -to create a -.Dq staging area -for any files extracted by -.Nm -from package files. -If neither -.Ev PKG_TMPDIR -nor -.Ev TMPDIR -yields a suitable scratch directory, -.Pa /var/tmp , -.Pa /tmp , -and -.Pa /usr/tmp -are tried in turn. -Note that -.Pa /usr/tmp -may be created, if it doesn't already exist. -.Pp -Since -.Nm -requires very little information to be extracted from any package -files examined, it is unlikely that these environment variables would -ever need to be used to work around limited available space in the -default locations. .El .Sh SEE ALSO .Xr pkg_add 1 , diff --git a/pkgtools/pkg_install/files/info/pkg_info.cat1 b/pkgtools/pkg_install/files/info/pkg_info.cat1 index 1945fffff3f..1e6a42b93d8 100644 --- a/pkgtools/pkg_install/files/info/pkg_info.cat1 +++ b/pkgtools/pkg_install/files/info/pkg_info.cat1 @@ -171,25 +171,6 @@ EENNVVIIRROONNMMEENNTT the package database directory. The default package database directory is _/_v_a_r_/_d_b_/_p_k_g. - PKG_PATH This can be used to specify a semicolon-separated list of - paths and URLs to search for package files. If PKG_PATH is - used, the suffix _._t_g_z is automatically appended to the - _p_k_g_-_n_a_m_e, whereas searching in the current directory uses - _p_k_g_-_n_a_m_e literally. - - PKG_TMPDIR, TMPDIR - These are tried in turn (if set) as candidate directories in - which to create a ``staging area'' for any files extracted by - ppkkgg__iinnffoo from package files. If neither PKG_TMPDIR nor TMPDIR - yields a suitable scratch directory, _/_v_a_r_/_t_m_p, _/_t_m_p, and - _/_u_s_r_/_t_m_p are tried in turn. Note that _/_u_s_r_/_t_m_p may be cre- - ated, if it doesn't already exist. - - Since ppkkgg__iinnffoo requires very little information to be - extracted from any package files examined, it is unlikely that - these environment variables would ever need to be used to work - around limited available space in the default locations. - SSEEEE AALLSSOO pkg_add(1), pkg_admin(1), pkg_create(1), pkg_delete(1), mktemp(3), pkgsrc(7), mtree(8) @@ -203,4 +184,4 @@ AAUUTTHHOORRSS NetBSD wildcard dependency processing, pkgdb, depends displaying, pkg size display etc. -NetBSD 4.0 March 2, 2007 NetBSD 4.0 +NetBSD 5.0 February 27, 2009 NetBSD 5.0 diff --git a/pkgtools/pkg_install/files/lib/Makefile.in b/pkgtools/pkg_install/files/lib/Makefile.in index 63e460113dd..69b8ac6abde 100644 --- a/pkgtools/pkg_install/files/lib/Makefile.in +++ b/pkgtools/pkg_install/files/lib/Makefile.in @@ -1,4 +1,4 @@ -# $NetBSD: Makefile.in,v 1.25 2009/02/09 16:54:08 joerg Exp $ +# $NetBSD: Makefile.in,v 1.26 2009/02/28 16:03:56 joerg Exp $ srcdir= @srcdir@ @@ -28,7 +28,7 @@ LIB= libinstall.a OBJS= automatic.o conflicts.o decompress.o dewey.o fexec.o file.o \ gpgsig.o global.o iterate.o lpkg.o opattern.o \ - parse-config.o path.o pkgdb.o plist.o remove.o \ + parse-config.o pkgdb.o plist.o remove.o \ str.o var.o version.o vulnerabilities-file.o xwrapper.o CPPFLAGS+= -DSYSCONFDIR=\"$(sysconfdir)\" diff --git a/pkgtools/pkg_install/files/lib/lib.h b/pkgtools/pkg_install/files/lib/lib.h index d46cc513c9b..3fb35fb5146 100644 --- a/pkgtools/pkg_install/files/lib/lib.h +++ b/pkgtools/pkg_install/files/lib/lib.h @@ -1,4 +1,4 @@ -/* $NetBSD: lib.h,v 1.48 2009/02/13 11:21:07 joerg Exp $ */ +/* $NetBSD: lib.h,v 1.49 2009/02/28 16:03:56 joerg Exp $ */ /* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */ @@ -64,8 +64,6 @@ #include <unistd.h> #endif -#include "path.h" - /* Macros */ #define SUCCESS (0) #define FAIL (-1) @@ -319,7 +317,8 @@ struct archive_entry; struct archive *open_archive(const char *, void **); void close_archive(void *); -struct archive *find_archive(const char *, void **); +struct archive *find_archive(const char *, void **, int); +void process_pkg_path(void); /* Packing list */ plist_t *new_plist_entry(void); @@ -416,6 +415,7 @@ extern const char *certs_packages; extern const char *certs_pkg_vulnerabilities; extern const char *check_vulnerabilities; extern const char *config_file; +extern const char *config_pkg_path; extern const char *verified_installation; extern const char *gpg_cmd; extern const char *gpg_keyring_pkgvuln; diff --git a/pkgtools/pkg_install/files/lib/parse-config.c b/pkgtools/pkg_install/files/lib/parse-config.c index 9ec6d783dc6..0fbe45961de 100644 --- a/pkgtools/pkg_install/files/lib/parse-config.c +++ b/pkgtools/pkg_install/files/lib/parse-config.c @@ -1,4 +1,4 @@ -/* $NetBSD: parse-config.c,v 1.3 2009/02/03 13:44:34 joerg Exp $ */ +/* $NetBSD: parse-config.c,v 1.4 2009/02/28 16:03:56 joerg Exp $ */ #if HAVE_CONFIG_H #include "config.h" @@ -7,7 +7,7 @@ #if HAVE_SYS_CDEFS_H #include <sys/cdefs.h> #endif -__RCSID("$NetBSD: parse-config.c,v 1.3 2009/02/03 13:44:34 joerg Exp $"); +__RCSID("$NetBSD: parse-config.c,v 1.4 2009/02/28 16:03:56 joerg Exp $"); /*- * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>. @@ -57,6 +57,7 @@ const char *cert_chain_file; const char *certs_packages; const char *certs_pkg_vulnerabilities; const char *check_vulnerabilities; +const char *config_pkg_path; const char *verified_installation; const char *gpg_cmd; const char *gpg_keyring_pkgvuln; @@ -86,6 +87,7 @@ static struct config_variable { { "GPG_SIGN_AS", &gpg_sign_as }, { "IGNORE_PROXY", &ignore_proxy }, { "IGNORE_URL", &ignore_advisories }, + { "PKG_PATH", &config_pkg_path }, { "PKGVULNDIR", &pkg_vulnerabilities_dir }, { "PKGVULNURL", &pkg_vulnerabilities_url }, { "VERBOSE_NETIO", &verbose_netio }, @@ -119,6 +121,9 @@ pkg_install_config(void) if (check_vulnerabilities == NULL) check_vulnerabilities = "never"; + if ((value = getenv("PKG_PATH")) != NULL) + config_pkg_path = value; + snprintf(fetch_flags, sizeof(fetch_flags), "%s%s%s", (verbose_netio && *verbose_netio) ? "v" : "", (active_ftp && *active_ftp) ? "" : "p", diff --git a/pkgtools/pkg_install/files/lib/path.c b/pkgtools/pkg_install/files/lib/path.c deleted file mode 100644 index 982510bc577..00000000000 --- a/pkgtools/pkg_install/files/lib/path.c +++ /dev/null @@ -1,193 +0,0 @@ -/* $NetBSD: path.c,v 1.7 2009/02/02 12:35:01 joerg Exp $ */ - -/*- - * Copyright (c)2002 YAMAMOTO Takashi, - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#if HAVE_CONFIG_H -#include "config.h" -#endif -#include <nbcompat.h> -#if HAVE_SYS_CDEFS_H -#include <sys/cdefs.h> -#endif -__RCSID("$NetBSD: path.c,v 1.7 2009/02/02 12:35:01 joerg Exp $"); - -#if HAVE_ERR_H -#include <err.h> -#endif - -#include "lib.h" - -struct pathhead PkgPath = TAILQ_HEAD_INITIALIZER(PkgPath); -static struct path *prepend = 0; - -static struct path *path_new_entry(const char *cp, size_t len); - -/* - * path_create: make PkgPath from a given string. - * - * => relative pathes are resolved to absolute ones. - * => if NULL is passed, use "." instead. XXX - */ -void -path_create(const char *path) -{ - const char *cp; - size_t len; - - path_free(); - - if (path == NULL) { - path = "."; /* XXX */ - } - - if (Verbose) - printf("parsing: %s\n", path); - - cp = path; - while (*cp) { - len = strcspn(cp, ";"); - if (len > 0) { - /* add a new path */ - struct path *new; - - new = path_new_entry(cp, len); - if (Verbose) - printf("path: %s\n", new->pl_path); - TAILQ_INSERT_TAIL(&PkgPath, new, pl_entry); - } - - cp += len; - if (*cp == '\0') - break; - cp++; - } -} - -/* - * path_free: free PkgPath. - */ -void -path_free() -{ - struct path *p; - - while ((p = TAILQ_FIRST(&PkgPath)) != NULL) { - TAILQ_REMOVE(&PkgPath, p, pl_entry); - free(p->pl_path); - free(p); - } -} - -/* - * 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 = xmalloc(sizeof(*new)); - - if (!IS_FULLPATH(cp) && !IS_URL(cp)) { - /* this is a relative path */ - char cwd[MaxPathSize]; - - if (getcwd(cwd, sizeof(cwd)) == NULL) - err(EXIT_FAILURE, "getcwd"); - new->pl_path = xasprintf("%s/%*.*s", cwd, (int)len, (int)len, cp); - } - else { - new->pl_path = xmalloc(len + 1); - memcpy(new->pl_path, cp, len); - new->pl_path[len] = '\0'; - } - return new; -} - -/* - * path_prepend_from_pkgname: prepend the path for a package onto 'PkgPath' - */ -void -path_prepend_from_pkgname(const char *pkgname) -{ - char *ptr; - if ((ptr = strrchr(pkgname , '/'))) { - prepend = path_new_entry(pkgname, ptr - pkgname); - TAILQ_INSERT_HEAD(&PkgPath, prepend, pl_entry); - } -} - -/* - * path_prepend_clear: Remove any prepended entry from 'PkgPath' - */ -void -path_prepend_clear() -{ - if (prepend) { - TAILQ_REMOVE(&PkgPath, prepend, pl_entry); - prepend = 0; - } -} - -/* - * path_setenv: construct string from PkgPath and set it to a environment. - * - * => the environment name is given by envname. - */ -void -path_setenv(const char *envname) -{ - struct path *p; - ssize_t len = 0; - char *env, *env0, *envend; - char *sep; - - TAILQ_FOREACH(p, &PkgPath, pl_entry) - len += strlen(p->pl_path) + 1; - - env = xmalloc(len); - - env0 = env; - envend = env + len; - sep = ""; - TAILQ_FOREACH(p, &PkgPath, pl_entry) { - int r; - - r = snprintf(env, envend - env, "%s%s", sep, p->pl_path); - if (r < 0 || r >= envend - env) - err(EXIT_FAILURE, "snprintf"); - env += r; - sep = ";"; - } - - if (Verbose) - printf("%s = %s\n", envname, env0); - if (setenv(envname, env0, 1) != 0) - err(EXIT_FAILURE, "setenv"); - free(env0); -} diff --git a/pkgtools/pkg_install/files/lib/path.h b/pkgtools/pkg_install/files/lib/path.h deleted file mode 100644 index 946eeae378b..00000000000 --- a/pkgtools/pkg_install/files/lib/path.h +++ /dev/null @@ -1,40 +0,0 @@ -/* $NetBSD: path.h,v 1.3 2003/09/23 07:13:53 grant Exp $ */ - -/*- - * Copyright (c)2002 YAMAMOTO Takashi, - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -struct path { - TAILQ_ENTRY(path) pl_entry; - char *pl_path; -}; - -TAILQ_HEAD(pathhead, path); -extern struct pathhead PkgPath; -void path_create(const char *); -void path_free(void); -void path_prepend_from_pkgname(const char *); -void path_prepend_clear(void); -void path_setenv(const char *); diff --git a/pkgtools/pkg_install/files/lib/pkg_install.conf.5.in b/pkgtools/pkg_install/files/lib/pkg_install.conf.5.in index 5e4f6f974f8..a22e941dd7d 100644 --- a/pkgtools/pkg_install/files/lib/pkg_install.conf.5.in +++ b/pkgtools/pkg_install/files/lib/pkg_install.conf.5.in @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_install.conf.5.in,v 1.2 2009/02/25 15:19:00 joerg Exp $ +.\" $NetBSD: pkg_install.conf.5.in,v 1.3 2009/02/28 16:03:56 joerg Exp $ .\" .\" Copyright (c) 2008, 2009 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -27,7 +27,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd January 8, 2009 +.Dd February 27, 2009 .Dt PKG_INSTALL.CONF 5 .Os .Sh NAME @@ -109,6 +109,11 @@ One line per advisory which should be ignored when running The URL from the .Pa pkg-vulnerabilities file should be used as value. +.It Dv PKG_PATH +Search path as used by +.Nm pkg_add . +Overriden by the environment variable +.Ev PKG_PATH . .It Dv PKGVULNDIR Directory name in which the .Pa pkg-vulnerabilities diff --git a/pkgtools/pkg_install/files/lib/pkg_install.conf.cat5.in b/pkgtools/pkg_install/files/lib/pkg_install.conf.cat5.in index dd6bf7de4c6..03bc79b5b75 100644 --- a/pkgtools/pkg_install/files/lib/pkg_install.conf.cat5.in +++ b/pkgtools/pkg_install/files/lib/pkg_install.conf.cat5.in @@ -76,6 +76,10 @@ DDEESSCCRRIIPPTTIIOONN The URL from the _p_k_g_-_v_u_l_n_e_r_a_b_i_l_i_t_i_e_s file should be used as value. + PKG_PATH + Search path as used by ppkkgg__aadddd. Overriden by the environment + variable PKG_PATH. + PKGVULNDIR Directory name in which the _p_k_g_-_v_u_l_n_e_r_a_b_i_l_i_t_i_e_s file resides. Default is _$_{_P_K_G___D_B_D_I_R_}. @@ -116,4 +120,4 @@ FFIILLEESS SSEEEE AALLSSOO pkg_add(1), pkg_admin(1) -NetBSD 5.0 January 8, 2009 NetBSD 5.0 +NetBSD 5.0 February 27, 2009 NetBSD 5.0 diff --git a/pkgtools/pkg_install/files/lib/pkg_io.c b/pkgtools/pkg_install/files/lib/pkg_io.c index abc973c8ed8..ff78414c984 100644 --- a/pkgtools/pkg_install/files/lib/pkg_io.c +++ b/pkgtools/pkg_install/files/lib/pkg_io.c @@ -1,4 +1,4 @@ -/* $NetBSD: pkg_io.c,v 1.4 2009/02/02 12:35:01 joerg Exp $ */ +/* $NetBSD: pkg_io.c,v 1.5 2009/02/28 16:03:56 joerg Exp $ */ /*- * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>. * All rights reserved. @@ -36,7 +36,7 @@ #include <sys/cdefs.h> #endif -__RCSID("$NetBSD: pkg_io.c,v 1.4 2009/02/02 12:35:01 joerg Exp $"); +__RCSID("$NetBSD: pkg_io.c,v 1.5 2009/02/28 16:03:56 joerg Exp $"); #include <archive.h> #include <archive_entry.h> @@ -51,6 +51,14 @@ __RCSID("$NetBSD: pkg_io.c,v 1.4 2009/02/02 12:35:01 joerg Exp $"); #include "lib.h" +struct pkg_path { + TAILQ_ENTRY(pkg_path) pl_link; + char *pl_path; +}; + +static char *orig_cwd, *last_toplevel; +static TAILQ_HEAD(, pkg_path) pkg_path = TAILQ_HEAD_INITIALIZER(pkg_path); + struct fetch_archive { struct url *url; fetchIO *fetch; @@ -229,49 +237,100 @@ find_best_package(struct url *url, const char *pattern, struct url **best_url) return 0; } +void +process_pkg_path(void) +{ + char cwd[PATH_MAX]; + int relative_path; + struct pkg_path *pl; + const char *start, *next; + size_t len; + + if (getcwd(cwd, sizeof(cwd)) == NULL) + errx(EXIT_FAILURE, "getcwd failed"); + + orig_cwd = xstrdup(cwd); + + if (config_pkg_path == NULL) + return; + + for (start = config_pkg_path; *start; start = next) { + len = strcspn(start, ";"); + if (*(next = start + len) != '\0') + ++next; + + relative_path = !IS_FULLPATH(start) && !IS_URL(start); + pl = xmalloc(sizeof(*pl)); + pl->pl_path = xasprintf("%s%s%*.*s", + relative_path ? cwd : "", len && relative_path ? "/" : "", + (int)len, (int)len, start); + TAILQ_INSERT_TAIL(&pkg_path, pl, pl_link); + } +} + struct archive * -find_archive(const char *fname, void **cookie) +find_archive(const char *fname, void **cookie, int top_level) { struct archive *a; - struct path *path; - const char *cur_path; + struct pkg_path *pl; struct url *url, *best_match; - char tmp[MaxPathSize]; + char *full_fname, *last_slash; + int search_path; - best_match = NULL; + search_path = 0; + if (IS_FULLPATH(fname) || IS_URL(fname)) { + full_fname = xstrdup(fname); + } else { + if (strchr(fname, '/') == NULL) + search_path = 1; + full_fname = xasprintf("%s/%s", orig_cwd, fname); + } + + last_slash = strrchr(full_fname, '/'); + if (top_level) { + free(last_toplevel); + *last_slash = '\0'; + last_toplevel = xstrdup(full_fname); + *last_slash = '/'; + } - a = open_archive(fname, cookie); - if (a != NULL) + a = open_archive(full_fname, cookie); + if (a != NULL) { + free(full_fname); return a; + } - if (strchr(fname, '/') != NULL) { - const char *last_slash; + fname = last_slash + 1; + *last_slash = '\0'; - last_slash = strrchr(fname, '/'); - snprintf(tmp, sizeof(tmp), "%s%.*s", - IS_URL(fname) ? "" : "file://", - (int)(last_slash - fname + 1), fname); - url = fetchParseURL(tmp); - if (url == NULL) - return NULL; - fname = last_slash + 1; /* XXX fetchUnquoteFilename */ + best_match = NULL; + url = fetchParseURL(full_fname); + if (url != NULL) { find_best_package(url, fname, &best_match); + /* XXX Check return value and complain */ fetchFreeURL(url); - } else { - TAILQ_FOREACH(path, &PkgPath, pl_entry) { - cur_path = path->pl_path; - if (!IS_URL(cur_path)) { - snprintf(tmp, sizeof(tmp), "file://%s", cur_path); - cur_path = tmp; + } + + if (search_path && best_match == NULL) { + if (last_toplevel) { + url = fetchParseURL(last_toplevel); + if (url != NULL) { + find_best_package(url, fname, &best_match); + /* XXX Check return value and complain */ + fetchFreeURL(url); } - url = fetchParseURL(cur_path); - if (url == NULL) - continue; - find_best_package(url, fname, &best_match); - /* XXX Check return value and complain */ - fetchFreeURL(url); } - } + TAILQ_FOREACH(pl, &pkg_path, pl_link) { + url = fetchParseURL(pl->pl_path); + if (url != NULL) { + find_best_package(url, fname, &best_match); + /* XXX Check return value and complain */ + fetchFreeURL(url); + } + } + } + + free(full_fname); if (best_match == NULL) return NULL; diff --git a/pkgtools/pkg_install/files/lib/version.h b/pkgtools/pkg_install/files/lib/version.h index 17b36c4589f..819d9ac24a0 100644 --- a/pkgtools/pkg_install/files/lib/version.h +++ b/pkgtools/pkg_install/files/lib/version.h @@ -1,4 +1,4 @@ -/* $NetBSD: version.h,v 1.114 2009/02/26 12:52:43 joerg Exp $ */ +/* $NetBSD: version.h,v 1.115 2009/02/28 16:03:56 joerg Exp $ */ /* * Copyright (c) 2001 Thomas Klausner. All rights reserved. @@ -27,6 +27,6 @@ #ifndef _INST_LIB_VERSION_H_ #define _INST_LIB_VERSION_H_ -#define PKGTOOLS_VERSION "20090226" +#define PKGTOOLS_VERSION "20090228" #endif /* _INST_LIB_VERSION_H_ */ |