diff options
author | joerg <joerg@pkgsrc.org> | 2009-08-16 21:10:14 +0000 |
---|---|---|
committer | joerg <joerg@pkgsrc.org> | 2009-08-16 21:10:14 +0000 |
commit | 2841c9455cc762bf9446b066836e68ee4495e3b9 (patch) | |
tree | 6683f8221ee3928f5af465ed17cf6884c7fd0c54 /pkgtools | |
parent | a85cb6dafcbfda2ef85580211f8cf5bccac5fd9d (diff) | |
download | pkgsrc-2841c9455cc762bf9446b066836e68ee4495e3b9.tar.gz |
pkg_install-20090817:
Add a new command for pkg_admin: findbest. It takes one or more patterns
and searches for the best match in PKG_PATH, just like pkg_add would.
It prints the URLs of the best match for each pattern to stdout.
Rewrite the config file parser to read the file only once.
Diffstat (limited to 'pkgtools')
-rw-r--r-- | pkgtools/pkg_install/files/admin/main.c | 31 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/admin/pkg_admin.1 | 10 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/admin/pkg_admin.cat1 | 10 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/delete/pkg_delete.1 | 10 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/delete/pkg_delete.cat1 | 7 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/lib.h | 3 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/parse-config.c | 62 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/pkg_io.c | 69 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/version.h | 4 |
9 files changed, 149 insertions, 57 deletions
diff --git a/pkgtools/pkg_install/files/admin/main.c b/pkgtools/pkg_install/files/admin/main.c index 60d0dafbd64..07c687576d8 100644 --- a/pkgtools/pkg_install/files/admin/main.c +++ b/pkgtools/pkg_install/files/admin/main.c @@ -1,4 +1,4 @@ -/* $NetBSD: main.c,v 1.54 2009/08/02 17:56:44 joerg Exp $ */ +/* $NetBSD: main.c,v 1.55 2009/08/16 21:10:14 joerg Exp $ */ #if HAVE_CONFIG_H #include "config.h" @@ -7,10 +7,10 @@ #if HAVE_SYS_CDEFS_H #include <sys/cdefs.h> #endif -__RCSID("$NetBSD: main.c,v 1.54 2009/08/02 17:56:44 joerg Exp $"); +__RCSID("$NetBSD: main.c,v 1.55 2009/08/16 21:10:14 joerg Exp $"); /*- - * Copyright (c) 1999-2008 The NetBSD Foundation, Inc. + * Copyright (c) 1999-2009 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation @@ -74,6 +74,7 @@ __RCSID("$NetBSD: main.c,v 1.54 2009/08/02 17:56:44 joerg Exp $"); #ifndef BOOTSTRAP #include <archive.h> +#include <fetch.h> #endif #include "admin.h" @@ -500,7 +501,6 @@ main(int argc, char *argv[]) argv++; } - } else if (strcasecmp(argv[0], "list") == 0 || strcasecmp(argv[0], "dump") == 0) { @@ -559,7 +559,28 @@ main(int argc, char *argv[]) } } #ifndef BOOTSTRAP - else if (strcasecmp(argv[0], "fetch-pkg-vulnerabilities") == 0) { + else if (strcasecmp(argv[0], "findbest") == 0) { + struct url *url; + char *output; + int rc; + + process_pkg_path(); + + rc = 0; + for (++argv; *argv != NULL; ++argv) { + url = find_best_package(NULL, *argv, 1); + if (url == NULL) { + rc = 1; + continue; + } + output = fetchStringifyURL(url); + puts(output); + fetchFreeURL(url); + free(output); + } + + return rc; + } else if (strcasecmp(argv[0], "fetch-pkg-vulnerabilities") == 0) { fetch_pkg_vulnerabilities(--argc, ++argv); } else if (strcasecmp(argv[0], "check-pkg-vulnerabilities") == 0) { check_pkg_vulnerabilities(--argc, ++argv); diff --git a/pkgtools/pkg_install/files/admin/pkg_admin.1 b/pkgtools/pkg_install/files/admin/pkg_admin.1 index 339a7d51de3..dd9f9152227 100644 --- a/pkgtools/pkg_install/files/admin/pkg_admin.1 +++ b/pkgtools/pkg_install/files/admin/pkg_admin.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_admin.1,v 1.25 2009/06/03 20:03:40 joerg Exp $ +.\" $NetBSD: pkg_admin.1,v 1.26 2009/08/16 21:10:14 joerg Exp $ .\" .\" Copyright (c) 1999-2009 The NetBSD Foundation, Inc. .\" All rights reserved. @@ -34,7 +34,7 @@ .\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE .\" POSSIBILITY OF SUCH DAMAGE. .\" -.Dd April 25, 2009 +.Dd August 16, 2009 .Dt PKG_ADMIN 1 .Os .Sh NAME @@ -205,6 +205,12 @@ If .Fl u is given, the fetch is conditional and the file transfer is only done if the remote version is newer than the one in pkgdb. +.It Cm findbest Ar pattern ... +Search the entries of PKG_PATH for packages matching +.Ar pattern . +Print the URL of the best matching package to stdout for each pattern. +If a pattern is not matched, it is skipped and the command will return +a failure. .It Cm lsall Ar /dir/pkgpattern .It Cm lsbest Ar /dir/pkgpattern List all/best package matching pattern in the given directory diff --git a/pkgtools/pkg_install/files/admin/pkg_admin.cat1 b/pkgtools/pkg_install/files/admin/pkg_admin.cat1 index e7741b8914d..0508ed986d3 100644 --- a/pkgtools/pkg_install/files/admin/pkg_admin.cat1 +++ b/pkgtools/pkg_install/files/admin/pkg_admin.cat1 @@ -101,7 +101,7 @@ OOPPTTIIOONNSS cchheecckk--ssiiggnnaattuurree _f_i_l_e _._._. Reports if _f_i_l_e is a correctly signed package. - cchheecckk--ssiinnggllee--lliicceennssee _l_i_c_c_e_n_s_e + cchheecckk--ssiinnggllee--lliicceennssee _l_i_c_e_n_s_e Check if _l_i_c_e_n_s_e is a valid license name and if it is in the set of acceptable licenses. Prints either yes or no to stdout if the condition can be parsed, otherwise it exits with error. @@ -127,6 +127,12 @@ OOPPTTIIOONNSS transfer is only done if the remote version is newer than the one in pkgdb. + ffiinnddbbeesstt _p_a_t_t_e_r_n _._._. + Search the entries of PKG_PATH for packages matching _p_a_t_t_e_r_n. + Print the URL of the best matching package to stdout for each + pattern. If a pattern is not matched, it is skipped and the com- + mand will return a failure. + llssaallll _/_d_i_r_/_p_k_g_p_a_t_t_e_r_n llssbbeesstt _/_d_i_r_/_p_k_g_p_a_t_t_e_r_n @@ -236,4 +242,4 @@ HHIISSTTOORRYY AAUUTTHHOORRSS The ppkkgg__aaddmmiinn command was written by Hubert Feyrer. -NetBSD 5.0 April 25, 2009 NetBSD 5.0 +NetBSD 5.0 August 16, 2009 NetBSD 5.0 diff --git a/pkgtools/pkg_install/files/delete/pkg_delete.1 b/pkgtools/pkg_install/files/delete/pkg_delete.1 index 4a15cc705f5..08458a9f31c 100644 --- a/pkgtools/pkg_install/files/delete/pkg_delete.1 +++ b/pkgtools/pkg_install/files/delete/pkg_delete.1 @@ -1,4 +1,4 @@ -.\" $NetBSD: pkg_delete.1,v 1.22 2009/08/06 18:15:27 wiz Exp $ +.\" $NetBSD: pkg_delete.1,v 1.23 2009/08/16 21:10:15 joerg Exp $ .\" .\" FreeBSD install - a package for the installation and maintenance .\" of non-core utilities. @@ -17,7 +17,7 @@ .\" .\" from FreeBSD: @(#)pkg_delete.1 .\" -.Dd August 6, 2009 +.Dd August 16, 2009 .Dt PKG_DELETE 1 .Os .Sh NAME @@ -127,6 +127,9 @@ Force removal of the package, even if the package is marked as a .Cm preserved package. Note that this is a dangerous operation. +See also the +.Fl k +option. .It Fl K Ar pkg_dbdir Set .Ar pkg_dbdir @@ -136,6 +139,9 @@ taken from the value of the environment variable .Ev PKG_DBDIR if it's set, otherwise it defaults to .Pa /var/db/pkg . +.It Fl k +Silently skip all packages that are marked as +.Cm preserved . .It Fl N Remove the package's registration and its entries from the package database, but leave the files installed. diff --git a/pkgtools/pkg_install/files/delete/pkg_delete.cat1 b/pkgtools/pkg_install/files/delete/pkg_delete.cat1 index 58fe31da359..f3ae4504473 100644 --- a/pkgtools/pkg_install/files/delete/pkg_delete.cat1 +++ b/pkgtools/pkg_install/files/delete/pkg_delete.cat1 @@ -58,7 +58,8 @@ OOPPTTIIOONNSS the deinstall script fails. --ffff Force removal of the package, even if the package is marked as a - pprreesseerrvveedd package. Note that this is a dangerous operation. + pprreesseerrvveedd package. Note that this is a dangerous operation. See + also the --kk option. --KK _p_k_g___d_b_d_i_r Set _p_k_g___d_b_d_i_r as the package database directory. If this option @@ -66,6 +67,8 @@ OOPPTTIIOONNSS from the value of the environment variable PKG_DBDIR if it's set, otherwise it defaults to _/_v_a_r_/_d_b_/_p_k_g. + --kk Silently skip all packages that are marked as pprreesseerrvveedd. + --NN Remove the package's registration and its entries from the pack- age database, but leave the files installed. Don't run any dein- stall scripts or @unexec lines either. @@ -169,4 +172,4 @@ AAUUTTHHOORRSS Rewrote most of the code to compute correct order of deinstalla- tion and to improve error handling. -NetBSD 5.0 August 6, 2009 NetBSD 5.0 +NetBSD 5.0 August 16, 2009 NetBSD 5.0 diff --git a/pkgtools/pkg_install/files/lib/lib.h b/pkgtools/pkg_install/files/lib/lib.h index c87d48566ea..2b97cfc346d 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.57 2009/08/06 16:53:34 joerg Exp $ */ +/* $NetBSD: lib.h,v 1.58 2009/08/16 21:10:15 joerg Exp $ */ /* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */ @@ -324,6 +324,7 @@ struct archive_entry; struct archive *open_archive(const char *); struct archive *find_archive(const char *, int); void process_pkg_path(void); +struct url *find_best_package(const char *, const char *, int); /* Packing list */ plist_t *new_plist_entry(void); diff --git a/pkgtools/pkg_install/files/lib/parse-config.c b/pkgtools/pkg_install/files/lib/parse-config.c index fe9a6ee1214..54662d9040a 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.7 2009/08/16 14:26:46 joerg Exp $ */ +/* $NetBSD: parse-config.c,v 1.8 2009/08/16 21:10:15 joerg Exp $ */ #if HAVE_CONFIG_H #include "config.h" @@ -7,10 +7,10 @@ #if HAVE_SYS_CDEFS_H #include <sys/cdefs.h> #endif -__RCSID("$NetBSD: parse-config.c,v 1.7 2009/08/16 14:26:46 joerg Exp $"); +__RCSID("$NetBSD: parse-config.c,v 1.8 2009/08/16 21:10:15 joerg Exp $"); /*- - * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>. + * Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg@NetBSD.org>. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -41,6 +41,7 @@ __RCSID("$NetBSD: parse-config.c,v 1.7 2009/08/16 14:26:46 joerg Exp $"); #if HAVE_ERR_H #include <err.h> #endif +#include <errno.h> #if HAVE_STRING_H #include <string.h> #endif @@ -99,18 +100,59 @@ static struct config_variable { { NULL, NULL } }; -void -pkg_install_config(void) +char *config_tmp_variables[sizeof config_variables/sizeof config_variables[0]]; + +static void +parse_pkg_install_conf(void) { - char *value; struct config_variable *var; + FILE *fp; + char *line, *value; + size_t len, var_len, i; + + fp = fopen(config_file, "r"); + if (!fp) { + if (errno != ENOENT) + warn("Can't open '%s' for reading", config_file); + return; + } - for (var = config_variables; var->name != NULL; ++var) { - value = var_get(config_file, var->name); - if (value != NULL) - *var->var = value; + while ((line = fgetln(fp, &len)) != (char *) NULL) { + if (line[len - 1] == '\n') + --len; + for (i = 0; (var = &config_variables[i])->name != NULL; ++i) { + var_len = strlen(var->name); + if (strncmp(var->name, line, var_len) != 0) + continue; + if (line[var_len] != '=') + continue; + line += var_len + 1; + len -= var_len + 1; + if (config_tmp_variables[i]) + value = xasprintf("%s\n%.*s", + config_tmp_variables[i], (int)len, line); + else + value = xasprintf("%.*s", (int)len, line); + free(config_tmp_variables[i]); + config_tmp_variables[i] = value; + break; + } } + for (i = 0; (var = &config_variables[i])->name != NULL; ++i) { + if (config_tmp_variables[i] == NULL) + continue; + *var->var = config_tmp_variables[i]; + config_tmp_variables[i] = NULL; + } +} + +void +pkg_install_config(void) +{ + char *value; + parse_pkg_install_conf(); + if (pkg_vulnerabilities_dir == NULL) pkg_vulnerabilities_dir = _pkgdb_getPKGDB_DIR(); pkg_vulnerabilities_file = xasprintf("%s/pkg-vulnerabilities", diff --git a/pkgtools/pkg_install/files/lib/pkg_io.c b/pkgtools/pkg_install/files/lib/pkg_io.c index fd6c1734146..cf8e1329b8d 100644 --- a/pkgtools/pkg_install/files/lib/pkg_io.c +++ b/pkgtools/pkg_install/files/lib/pkg_io.c @@ -1,6 +1,6 @@ -/* $NetBSD: pkg_io.c,v 1.8 2009/03/26 14:32:39 joerg Exp $ */ +/* $NetBSD: pkg_io.c,v 1.9 2009/08/16 21:10:15 joerg Exp $ */ /*- - * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>. + * Copyright (c) 2008, 2009 Joerg Sonnenberger <joerg@NetBSD.org>. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -36,7 +36,7 @@ #include <sys/cdefs.h> #endif -__RCSID("$NetBSD: pkg_io.c,v 1.8 2009/03/26 14:32:39 joerg Exp $"); +__RCSID("$NetBSD: pkg_io.c,v 1.9 2009/08/16 21:10:15 joerg Exp $"); #include <archive.h> #include <archive_entry.h> @@ -161,7 +161,8 @@ strip_suffix(char *filename) } static int -find_best_package(struct url *url, const char *pattern, struct url **best_url) +find_best_package_int(struct url *url, const char *pattern, + struct url **best_url) { char *cur_match, *url_pattern, *best_match = NULL; struct url_list ue; @@ -260,12 +261,40 @@ process_pkg_path(void) } } +struct url * +find_best_package(const char *toplevel, const char *pattern, int do_path) +{ + struct url *url, *best_match = NULL; + struct pkg_path *pl; + + if (toplevel) { + url = fetchParseURL(last_toplevel); + if (url != NULL) { + find_best_package_int(url, pattern, &best_match); + /* XXX Check return value and complain */ + fetchFreeURL(url); + } + } + if (!do_path) + return best_match; + + TAILQ_FOREACH(pl, &pkg_path, pl_link) { + url = fetchParseURL(pl->pl_path); + if (url != NULL) { + find_best_package_int(url, pattern, &best_match); + /* XXX Check return value and complain */ + fetchFreeURL(url); + } + } + + return best_match; +} + struct archive * find_archive(const char *fname, int top_level) { struct archive *a; - struct pkg_path *pl; - struct url *url, *best_match; + struct url *best_match; char *full_fname, *last_slash; int search_path; @@ -295,32 +324,10 @@ find_archive(const char *fname, int top_level) fname = last_slash + 1; *last_slash = '\0'; - 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); - } + best_match = find_best_package(full_fname, fname, 0); - 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); - } - } - 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); - } - } - } + if (search_path && best_match == NULL) + best_match = find_best_package(last_toplevel, fname, 1); free(full_fname); diff --git a/pkgtools/pkg_install/files/lib/version.h b/pkgtools/pkg_install/files/lib/version.h index d3cd3e88d85..3a3e712ba98 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.135 2009/08/16 14:26:46 joerg Exp $ */ +/* $NetBSD: version.h,v 1.136 2009/08/16 21:10:15 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 "20090816" +#define PKGTOOLS_VERSION "20090817" #endif /* _INST_LIB_VERSION_H_ */ |