summaryrefslogtreecommitdiff
path: root/pkgtools
diff options
context:
space:
mode:
authorjoerg <joerg>2008-02-02 16:21:45 +0000
committerjoerg <joerg>2008-02-02 16:21:45 +0000
commit6eceeb6b57fdde63725c0c01a88bf6f0cbab8aab (patch)
treeb75c2e029ae2dd7918650ea6b31c673ab8cebfb7 /pkgtools
parent633f7dbf8b83b878accacc917082cbb8becaefc4 (diff)
downloadpkgsrc-6eceeb6b57fdde63725c0c01a88bf6f0cbab8aab.tar.gz
pkg_install-20080202:
Convert pkg_info to use libarchive instead of tar for binary package handling. As a side effect pkg_info on remote packages will use one FTP instance per argument, but will try to fetch only the meta data. This reduces time for pkg_info -X on a full binary repository from 36.9s to 18.1s for the cache hot case (PKG_TMPDIR on tmpfs for the old pkg_info). Thanks to tnn@ for testing.
Diffstat (limited to 'pkgtools')
-rw-r--r--pkgtools/pkg_install/files/info/Makefile.in11
-rw-r--r--pkgtools/pkg_install/files/info/info.h65
-rw-r--r--pkgtools/pkg_install/files/info/perform.c489
-rw-r--r--pkgtools/pkg_install/files/info/show.c111
-rw-r--r--pkgtools/pkg_install/files/lib/lib.h5
-rw-r--r--pkgtools/pkg_install/files/lib/plist.c137
-rw-r--r--pkgtools/pkg_install/files/lib/var.c81
-rw-r--r--pkgtools/pkg_install/files/lib/version.h4
8 files changed, 615 insertions, 288 deletions
diff --git a/pkgtools/pkg_install/files/info/Makefile.in b/pkgtools/pkg_install/files/info/Makefile.in
index c14dcf496ce..48359f73f05 100644
--- a/pkgtools/pkg_install/files/info/Makefile.in
+++ b/pkgtools/pkg_install/files/info/Makefile.in
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.in,v 1.11 2007/07/16 09:57:58 joerg Exp $
+# $NetBSD: Makefile.in,v 1.12 2008/02/02 16:21:45 joerg Exp $
srcdir= @srcdir@
@@ -10,10 +10,17 @@ mandir= @mandir@
man1dir= $(mandir)/man1
cat1dir= $(mandir)/cat1
+BOOTSTRAP= @bootstrap@
+
CC= @CC@
CCLD= $(CC)
-LIBS= -linstall @LIBS@
+.if empty(BOOTSTRAP)
+LIBS= -linstall -larchive -lbz2 -lz @LIBS@
CPPFLAGS= @CPPFLAGS@ -I. -I$(srcdir) -I../lib
+.else
+LIBS= -linstall @LIBS@
+CPPFLAGS= @CPPFLAGS@ -I. -I$(srcdir) -I../lib -DBOOTSTRAP
+.endif
DEFS= @DEFS@
CFLAGS= @CFLAGS@
LDFLAGS= @LDFLAGS@ -L../lib
diff --git a/pkgtools/pkg_install/files/info/info.h b/pkgtools/pkg_install/files/info/info.h
index 994f1672481..233ade1f6fe 100644
--- a/pkgtools/pkg_install/files/info/info.h
+++ b/pkgtools/pkg_install/files/info/info.h
@@ -1,7 +1,36 @@
-/* $NetBSD: info.h,v 1.16 2007/08/12 22:09:02 joerg Exp $ */
+/* $NetBSD: info.h,v 1.17 2008/02/02 16:21:45 joerg Exp $ */
/* from FreeBSD Id: info.h,v 1.10 1997/02/22 16:09:40 peter Exp */
+/*-
+ * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>.
+ * 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDERS 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.
+ */
+
/*
* FreeBSD install - a package for the installation and maintainance
* of non-core utilities.
@@ -25,6 +54,24 @@
#ifndef _INST_INFO_H_INCLUDE
#define _INST_INFO_H_INCLUDE
+struct pkg_meta {
+ char *meta_contents;
+ char *meta_comment;
+ char *meta_desc;
+ char *meta_mtree;
+ char *meta_build_version;
+ char *meta_build_info;
+ char *meta_size_pkg;
+ char *meta_size_all;
+ char *meta_required_by;
+ char *meta_display;
+ char *meta_install;
+ char *meta_deinstall;
+ char *meta_preserve;
+ char *meta_views;
+ char *meta_installed_info;
+};
+
#ifndef MAXINDEXSIZE
#define MAXINDEXSIZE 60
#endif
@@ -73,14 +120,14 @@ extern lpkg_head_t pkgs;
int CheckForPkg(const char *);
int CheckForBestPkg(const char *);
-extern void show_file(const char *, const char *, const char *, Boolean);
-extern void show_var(const char *, const char *, const char *);
-extern void show_plist(const char *, package_t *, pl_ent_t);
-extern void show_files(const char *, package_t *);
-extern void show_depends(const char *, package_t *);
-extern void show_bld_depends(const char *, package_t *);
-extern void show_index(const char *, const char *, const char *);
-extern void show_summary(package_t *, const char *);
+void show_file(const char *, const char *, Boolean);
+void show_var(const char *, const char *);
+void show_plist(const char *, package_t *, pl_ent_t);
+void show_files(const char *, package_t *);
+void show_depends(const char *, package_t *);
+void show_bld_depends(const char *, package_t *);
+void show_index(const char *, const char *);
+void show_summary(struct pkg_meta *, package_t *, const char *);
int pkg_perform(lpkg_head_t *);
diff --git a/pkgtools/pkg_install/files/info/perform.c b/pkgtools/pkg_install/files/info/perform.c
index 420cd65cfae..d99c54d124c 100644
--- a/pkgtools/pkg_install/files/info/perform.c
+++ b/pkgtools/pkg_install/files/info/perform.c
@@ -1,4 +1,4 @@
-/* $NetBSD: perform.c,v 1.40 2007/08/12 22:09:02 joerg Exp $ */
+/* $NetBSD: perform.c,v 1.41 2008/02/02 16:21:45 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -10,14 +10,46 @@
#if HAVE_SYS_QUEUE_H
#include <sys/queue.h>
#endif
+#if HAVE_SYS_WAIT_H
+#include <sys/wait.h>
+#endif
#ifndef lint
#if 0
static const char *rcsid = "from FreeBSD Id: perform.c,v 1.23 1997/10/13 15:03:53 jkh Exp";
#else
-__RCSID("$NetBSD: perform.c,v 1.40 2007/08/12 22:09:02 joerg Exp $");
+__RCSID("$NetBSD: perform.c,v 1.41 2008/02/02 16:21:45 joerg Exp $");
#endif
#endif
+/*-
+ * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>.
+ * 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDERS 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.
+ */
+
/*
* FreeBSD install - a package for the installation and maintainance
* of non-core utilities.
@@ -48,9 +80,16 @@ __RCSID("$NetBSD: perform.c,v 1.40 2007/08/12 22:09:02 joerg Exp $");
#include <sys/stat.h>
#endif
+#ifndef BOOTSTRAP
+#include <archive.h>
+#include <archive_entry.h>
+#endif
#if HAVE_ERR_H
#include <err.h>
#endif
+#if HAVE_ERRNO_H
+#include <errno.h>
+#endif
#if HAVE_SIGNAL_H
#include <signal.h>
#endif
@@ -60,117 +99,242 @@ __RCSID("$NetBSD: perform.c,v 1.40 2007/08/12 22:09:02 joerg Exp $");
#if HAVE_CTYPE_H
#include <ctype.h>
#endif
+#include <stddef.h>
+
+#define LOAD_CONTENTS (1 << 0)
+#define LOAD_COMMENT (1 << 1)
+#define LOAD_DESC (1 << 2)
+#define LOAD_INSTALL (1 << 3)
+#define LOAD_DEINSTALL (1 << 4)
+#define LOAD_DISPLAY (1 << 5)
+#define LOAD_MTREE (1 << 6)
+#define LOAD_BUILD_VERSION (1 << 7)
+#define LOAD_BUILD_INFO (1 << 8)
+#define LOAD_SIZE_PKG (1 << 9)
+#define LOAD_SIZE_ALL (1 << 10)
+#define LOAD_PRESERVE (1 << 11)
+#define LOAD_VIEWS (1 << 12)
+#define LOAD_REQUIRED_BY (1 << 13)
+#define LOAD_INSTALLED_INFO (1 << 14)
+
+static const struct pkg_meta_desc {
+ size_t entry_offset;
+ const char *entry_filename;
+ int entry_mask;
+} pkg_meta_descriptors[] = {
+ { offsetof(struct pkg_meta, meta_contents), CONTENTS_FNAME ,
+ LOAD_CONTENTS},
+ { offsetof(struct pkg_meta, meta_comment), COMMENT_FNAME,
+ LOAD_COMMENT },
+ { offsetof(struct pkg_meta, meta_desc), DESC_FNAME,
+ LOAD_DESC },
+ { offsetof(struct pkg_meta, meta_install), INSTALL_FNAME,
+ LOAD_INSTALL },
+ { offsetof(struct pkg_meta, meta_deinstall), DEINSTALL_FNAME,
+ LOAD_DEINSTALL },
+ { offsetof(struct pkg_meta, meta_display), DISPLAY_FNAME,
+ LOAD_DISPLAY },
+ { offsetof(struct pkg_meta, meta_mtree), MTREE_FNAME,
+ LOAD_MTREE },
+ { offsetof(struct pkg_meta, meta_build_version), BUILD_VERSION_FNAME,
+ LOAD_BUILD_VERSION },
+ { offsetof(struct pkg_meta, meta_build_info), BUILD_INFO_FNAME,
+ LOAD_BUILD_INFO },
+ { offsetof(struct pkg_meta, meta_size_pkg), SIZE_PKG_FNAME,
+ LOAD_SIZE_PKG },
+ { offsetof(struct pkg_meta, meta_size_all), SIZE_ALL_FNAME,
+ LOAD_SIZE_ALL },
+ { offsetof(struct pkg_meta, meta_preserve), PRESERVE_FNAME,
+ LOAD_PRESERVE },
+ { offsetof(struct pkg_meta, meta_views), VIEWS_FNAME,
+ LOAD_VIEWS },
+ { offsetof(struct pkg_meta, meta_required_by), REQUIRED_BY_FNAME,
+ LOAD_REQUIRED_BY },
+ { offsetof(struct pkg_meta, meta_installed_info), INSTALLED_INFO_FNAME,
+ LOAD_INSTALLED_INFO },
+ { 0, NULL, 0 },
+};
+
+static int desired_meta_data;
+
+static void
+free_pkg_meta(struct pkg_meta *meta)
+{
+ const struct pkg_meta_desc *descr;
+
+ for (descr = pkg_meta_descriptors; descr->entry_filename; ++descr)
+ free(*(char **)((char *)meta + descr->entry_offset));
+
+ free(meta);
+}
-static char *Home;
+static struct pkg_meta *
+read_meta_data_from_fd(int fd)
+{
+#ifdef BOOTSTRAP
+ err(2, "binary packages not supported during bootstrap");
+ return NULL;
+#else
+ struct archive *archive;
+ struct pkg_meta *meta;
+ struct archive_entry *entry;
+ const char *fname;
+ const struct pkg_meta_desc *descr, *last_descr;
+ char **target;
+ int64_t size;
+ int r;
+
+ archive = archive_read_new();
+ archive_read_support_compression_all(archive);
+ archive_read_support_format_all(archive);
+ if (archive_read_open_fd(archive, fd, 1024))
+ err(2, "cannot open archive: %s", archive_error_string(archive));
+
+ if ((meta = malloc(sizeof(*meta))) == NULL)
+ err(2, "cannot allocate meta data header");
+
+ memset(meta, 0, sizeof(*meta));
+
+ last_descr = 0;
+ while ((r = archive_read_next_header(archive, &entry)) == ARCHIVE_OK) {
+ fname = archive_entry_pathname(entry);
+
+ for (descr = pkg_meta_descriptors; descr->entry_filename;
+ ++descr) {
+ if (strcmp(descr->entry_filename, fname) == 0)
+ break;
+ }
+ if (descr->entry_filename == NULL)
+ break;
+
+ target = (char **)((char *)meta + descr->entry_offset);
+ if (*target)
+ errx(2, "duplicate entry, package corrupt");
+ if (descr < last_descr)
+ warnx("misordered package, continuing");
+ else
+ last_descr = descr;
+
+ if ((descr->entry_mask & desired_meta_data) == 0) {
+ if (archive_read_data_skip(archive))
+ errx(2, "cannot read package meta data");
+ continue;
+ }
+
+ size = archive_entry_size(entry);
+ if (size > SSIZE_MAX - 1)
+ errx(2, "package meta data too large to process");
+ if ((*target = malloc(size + 1)) == NULL)
+ err(2, "cannot allocate meta data");
+ if (archive_read_data(archive, *target, size) != size)
+ errx(2, "cannot read package meta data");
+ (*target)[size] = '\0';
+ }
+
+ return meta;
+#endif
+}
+
+static struct pkg_meta *
+read_meta_data_from_pkgdb(const char *pkg)
+{
+ struct pkg_meta *meta;
+ const struct pkg_meta_desc *descr;
+ char **target;
+ char *fname;
+ int fd;
+ struct stat st;
+
+ if ((meta = malloc(sizeof(*meta))) == NULL)
+ err(2, "cannot allocate meta data header");
+
+ memset(meta, 0, sizeof(*meta));
+
+ for (descr = pkg_meta_descriptors; descr->entry_filename; ++descr) {
+ if ((descr->entry_mask & desired_meta_data) == 0)
+ continue;
+
+ fname = pkgdb_pkg_file(pkg, descr->entry_filename);
+ fd = open(fname, O_RDONLY, 0);
+ free(fname);
+ if (fd == -1) {
+ if (errno == ENOENT)
+ continue;
+ err(2, "cannot read meta data file %s",
+ descr->entry_filename);
+ }
+ target = (char **)((char *)meta + descr->entry_offset);
+
+ if (fstat(fd, &st) == -1)
+ err(2, "cannot stat meta data");
+ if ((st.st_mode & S_IFMT) != S_IFREG)
+ errx(1, "meta data is not regular file");
+ if (st.st_size > SSIZE_MAX - 1)
+ err(2, "meta data file too large to process");
+ if ((*target = malloc(st.st_size + 1)) == NULL)
+ err(2, "cannot allocate meta data");
+ if (read(fd, *target, st.st_size) != st.st_size)
+ err(2, "cannot read meta data");
+ (*target)[st.st_size] = '\0';
+ close(fd);
+ }
+
+ return meta;
+}
static lfile_head_t files;
+static void
+fetch_child(int fd, const char *url)
+{
+ close(STDOUT_FILENO);
+ if (dup2(fd, STDOUT_FILENO) == -1) {
+ static const char err_msg[] =
+ "cannot redirect stdout of FTP process\n";
+ write(STDERR_FILENO, err_msg, sizeof(err_msg) - 1);
+ _exit(255);
+ }
+ close(fd);
+ execlp(FTP_CMD, FTP_CMD, "-V", "-o", "-", url, (char *)NULL);
+ _exit(255);
+}
+
static int
pkg_do(const char *pkg)
{
- Boolean installed = FALSE, isTMP = FALSE;
+ struct pkg_meta *meta;
char log_dir[MaxPathSize];
- char fname[MaxPathSize];
- struct stat sb;
- char *cp = NULL;
int code = 0;
- lfile_t *lfp;
- int result;
- char *binpkgfile = NULL;
+ const char *binpkgfile = NULL;
if (IS_URL(pkg)) {
- if ((cp = fileGetURL(pkg)) != NULL) {
- strlcpy(fname, cp, sizeof(fname));
- isTMP = TRUE;
+ pid_t child;
+ int fd[2], status;
+
+ if (pipe(fd) == -1)
+ err(EXIT_FAILURE, "cannot create input pipes");
+ if (Verbose)
+ fprintf(stderr, "ftp -V -o - %s\n", pkg);
+ child = vfork();
+ if (child == -1)
+ err(EXIT_FAILURE, "cannot fork FTP process");
+ if (child == 0) {
+ close(fd[0]);
+ fetch_child(fd[1], pkg);
}
+ close(fd[1]);
+ meta = read_meta_data_from_fd(fd[0]);
+ kill(child, SIGTERM);
+ close(fd[0]);
+ waitpid(child, &status, 0);
} else if (fexists(pkg) && isfile(pkg)) {
- int len;
+ int pkg_fd;
- if (*pkg != '/') {
- if (!getcwd(fname, MaxPathSize)) {
- cleanup(0);
- err(EXIT_FAILURE, "fatal error during execution: getcwd");
- }
- len = strlen(fname);
- (void) snprintf(&fname[len], sizeof(fname) - len, "/%s", pkg);
- } else {
- strlcpy(fname, pkg, sizeof(fname));
- }
- cp = fname;
- binpkgfile = fname;
- }
-
- if (cp) {
- if (IS_URL(pkg)) {
- /* file is already unpacked by fileGetURL() */
- strcpy(PlayPen, cp);
- } else {
- if (IS_URL(cp)) {
- /* only a package name was given, and it was expanded to a
- * full URL by fileFindByPath. Now extract...
- */
- char *cp2;
-
- binpkgfile = NULL;
-
- if ((cp2 = fileGetURL(cp)) != NULL) {
- strlcpy(fname, cp2, sizeof(fname));
- isTMP = TRUE;
-
- strcpy(PlayPen, cp2);
- }
- } else {
- /*
- * Apply a crude heuristic to see how much space the package will
- * take up once it's unpacked. I've noticed that most packages
- * compress an average of 75%, but we're only unpacking the + files
- * needed so be very optimistic.
- */
-
- /* Determine which +-files to unpack - not all may be present! */
- LFILE_ADD(&files, lfp, CONTENTS_FNAME);
- LFILE_ADD(&files, lfp, COMMENT_FNAME);
- LFILE_ADD(&files, lfp, DESC_FNAME);
- if (Flags & SHOW_MTREE)
- LFILE_ADD(&files, lfp, MTREE_FNAME);
- if (Flags & SHOW_BUILD_VERSION)
- LFILE_ADD(&files, lfp, BUILD_VERSION_FNAME);
- if (Flags & (SHOW_BUILD_INFO|SHOW_SUMMARY|SHOW_BI_VAR))
- LFILE_ADD(&files, lfp, BUILD_INFO_FNAME);
- if (Flags & (SHOW_PKG_SIZE|SHOW_SUMMARY))
- LFILE_ADD(&files, lfp, SIZE_PKG_FNAME);
- if (Flags & SHOW_ALL_SIZE)
- LFILE_ADD(&files, lfp, SIZE_ALL_FNAME);
-#if 0
- if (Flags & SHOW_REQBY)
- LFILE_ADD(&files, lfp, REQUIRED_BY_FNAME);
- if (Flags & SHOW_DISPLAY)
- LFILE_ADD(&files, lfp, DISPLAY_FNAME);
- if (Flags & SHOW_INSTALL)
- LFILE_ADD(&files, lfp, INSTALL_FNAME);
- if (Flags & SHOW_DEINSTALL)
- LFILE_ADD(&files, lfp, DEINSTALL_FNAME);
- /* PRESERVE_FNAME? */
-#endif
-
- if (stat(fname, &sb) == FAIL) {
- warnx("can't stat package file '%s'", fname);
- code = 1;
- goto bail;
- }
- Home = make_playpen(PlayPen, PlayPenSize, sb.st_size / 2);
- result = unpack(fname, &files);
- while ((lfp = TAILQ_FIRST(&files)) != NULL) {
- TAILQ_REMOVE(&files, lfp, lf_link);
- free(lfp);
- }
- if (result) {
- warnx("error during unpacking, no info for '%s' available", pkg);
- code = 1;
- goto bail;
- }
- }
- }
+ if ((pkg_fd = open(pkg, O_RDONLY, 0)) == -1)
+ err(EXIT_FAILURE, "cannot open package %s", pkg);
+ meta = read_meta_data_from_fd(pkg_fd);
+ close(pkg_fd);
+ binpkgfile = pkg;
} else {
/*
* It's not an uninstalled package, try and find it among the
@@ -190,11 +354,7 @@ pkg_do(const char *pkg)
errx(EXIT_FAILURE, "Error during search in pkgdb for %s", pkg);
}
}
- if (chdir(log_dir) == FAIL) {
- warnx("can't change directory to '%s'!", log_dir);
- return 1;
- }
- installed = TRUE;
+ meta = read_meta_data_from_pkgdb(pkg);
}
/*
@@ -205,41 +365,32 @@ pkg_do(const char *pkg)
char tmp[MaxPathSize];
(void) snprintf(tmp, sizeof(tmp), "%-19s ", pkg);
- show_index(pkg, tmp, COMMENT_FNAME);
+ show_index(meta->meta_comment, tmp);
} else if (Flags & SHOW_BI_VAR) {
if (strcspn(BuildInfoVariable, "ABCDEFGHIJKLMNOPQRSTUVWXYZ")
== strlen(BuildInfoVariable))
- show_var(pkg, INSTALLED_INFO_FNAME, BuildInfoVariable);
+ show_var(meta->meta_installed_info, BuildInfoVariable);
else
- show_var(pkg, BUILD_INFO_FNAME, BuildInfoVariable);
+ show_var(meta->meta_build_info, BuildInfoVariable);
} else {
- FILE *fp;
package_t plist;
/* Read the contents list */
plist.head = plist.tail = NULL;
- fp = fopen(CONTENTS_FNAME, "r");
- if (!fp) {
- warn("unable to open %s file", CONTENTS_FNAME);
- code = 1;
- goto bail;
- }
- /* If we have a prefix, add it now */
- read_plist(&plist, fp);
- fclose(fp);
+ parse_plist(&plist, meta->meta_contents);
/* Start showing the package contents */
if (!Quiet && !(Flags & SHOW_SUMMARY)) {
printf("%sInformation for %s:\n\n", InfoPrefix, pkg);
- if (fexists(PRESERVE_FNAME)) {
+ if (meta->meta_preserve) {
printf("*** PACKAGE MAY NOT BE DELETED ***\n");
}
}
if (Flags & SHOW_SUMMARY) {
- show_summary(&plist, binpkgfile);
+ show_summary(meta, &plist, binpkgfile);
}
if (Flags & SHOW_COMMENT) {
- show_file(pkg, "Comment:\n", COMMENT_FNAME, TRUE);
+ show_file(meta->meta_comment, "Comment:\n", TRUE);
}
if (Flags & SHOW_DEPENDS) {
show_depends("Requires:\n", &plist);
@@ -247,30 +398,29 @@ pkg_do(const char *pkg)
if (Flags & SHOW_BLD_DEPENDS) {
show_bld_depends("Built using:\n", &plist);
}
- if ((Flags & SHOW_REQBY) && !isemptyfile(REQUIRED_BY_FNAME)) {
- show_file(pkg, "Required by:\n",
- REQUIRED_BY_FNAME, TRUE);
+ if ((Flags & SHOW_REQBY) && meta->meta_required_by) {
+ show_file(meta->meta_required_by, "Required by:\n", TRUE);
}
if (Flags & SHOW_DESC) {
- show_file(pkg, "Description:\n", DESC_FNAME, TRUE);
+ show_file(meta->meta_desc, "Description:\n", TRUE);
}
- if ((Flags & SHOW_DISPLAY) && fexists(DISPLAY_FNAME)) {
- show_file(pkg, "Install notice:\n",
- DISPLAY_FNAME, TRUE);
+ if ((Flags & SHOW_DISPLAY) && meta->meta_display) {
+ show_file(meta->meta_display, "Install notice:\n",
+ TRUE);
}
if (Flags & SHOW_PLIST) {
show_plist("Packing list:\n", &plist, PLIST_SHOW_ALL);
}
- if ((Flags & SHOW_INSTALL) && fexists(INSTALL_FNAME)) {
- show_file(pkg, "Install script:\n",
- INSTALL_FNAME, TRUE);
+ if ((Flags & SHOW_INSTALL) && meta->meta_install) {
+ show_file(meta->meta_install, "Install script:\n",
+ TRUE);
}
- if ((Flags & SHOW_DEINSTALL) && fexists(DEINSTALL_FNAME)) {
- show_file(pkg, "De-Install script:\n",
- DEINSTALL_FNAME, TRUE);
+ if ((Flags & SHOW_DEINSTALL) && meta->meta_deinstall) {
+ show_file(meta->meta_deinstall, "De-Install script:\n",
+ TRUE);
}
- if ((Flags & SHOW_MTREE) && fexists(MTREE_FNAME)) {
- show_file(pkg, "mtree file:\n", MTREE_FNAME, TRUE);
+ if ((Flags & SHOW_MTREE) && meta->meta_mtree) {
+ show_file(meta->meta_mtree, "mtree file:\n", TRUE);
}
if (Flags & SHOW_PREFIX) {
show_plist("Prefix(s):\n", &plist, PLIST_CWD);
@@ -278,41 +428,37 @@ pkg_do(const char *pkg)
if (Flags & SHOW_FILES) {
show_files("Files:\n", &plist);
}
- if ((Flags & SHOW_BUILD_VERSION) && fexists(BUILD_VERSION_FNAME)) {
- show_file(pkg, "Build version:\n",
- BUILD_VERSION_FNAME, TRUE);
+ if ((Flags & SHOW_BUILD_VERSION) && meta->meta_build_version) {
+ show_file(meta->meta_build_version, "Build version:\n",
+ TRUE);
}
if (Flags & SHOW_BUILD_INFO) {
- if (fexists(BUILD_INFO_FNAME)) {
- show_file(pkg, "Build information:\n",
- BUILD_INFO_FNAME,
- !fexists(INSTALLED_INFO_FNAME));
+ if (meta->meta_build_info) {
+ show_file(meta->meta_build_info, "Build information:\n",
+ TRUE);
}
- if (fexists(INSTALLED_INFO_FNAME)) {
- show_file(pkg, "Installed information:\n",
- INSTALLED_INFO_FNAME, TRUE);
+ if (meta->meta_installed_info) {
+ show_file(meta->meta_installed_info, "Installed information:\n",
+ TRUE);
}
}
- if ((Flags & SHOW_PKG_SIZE) && fexists(SIZE_PKG_FNAME)) {
- show_file(pkg, "Size of this package in bytes: ",
- SIZE_PKG_FNAME, TRUE);
+ if ((Flags & SHOW_PKG_SIZE) && meta->meta_size_pkg) {
+ show_file(meta->meta_size_pkg, "Size of this package in bytes: ",
+ TRUE);
}
- if ((Flags & SHOW_ALL_SIZE) && fexists(SIZE_ALL_FNAME)) {
- show_file(pkg, "Size in bytes including required pkgs: ",
- SIZE_ALL_FNAME, TRUE);
+ if ((Flags & SHOW_ALL_SIZE) && meta->meta_size_all) {
+ show_file(meta->meta_size_all, "Size in bytes including required pkgs: ",
+ TRUE);
}
if (!Quiet && !(Flags & SHOW_SUMMARY)) {
- if (fexists(PRESERVE_FNAME)) {
+ if (meta->meta_preserve) {
printf("*** PACKAGE MAY NOT BE DELETED ***\n\n");
}
puts(InfoPrefix);
}
free_plist(&plist);
}
-bail:
- leave_playpen(Home);
- if (isTMP)
- unlink(fname);
+ free_pkg_meta(meta);
return code;
}
@@ -411,7 +557,6 @@ CheckForBestPkg(const char *pkgname)
void
cleanup(int sig)
{
- leave_playpen(Home);
exit(1);
}
@@ -435,6 +580,35 @@ pkg_perform(lpkg_head_t *pkghead)
TAILQ_INIT(&files);
+ desired_meta_data = 0;
+ if ((Flags & (SHOW_INDEX | SHOW_BI_VAR)) == 0)
+ desired_meta_data |= LOAD_PRESERVE;
+ if ((Flags & (SHOW_INDEX | SHOW_BI_VAR)) == 0)
+ desired_meta_data |= LOAD_CONTENTS;
+ if (Flags & (SHOW_COMMENT | SHOW_INDEX | SHOW_SUMMARY))
+ desired_meta_data |= LOAD_COMMENT;
+ if (Flags & (SHOW_BI_VAR | SHOW_BUILD_INFO | SHOW_SUMMARY))
+ desired_meta_data |= LOAD_BUILD_INFO | LOAD_INSTALLED_INFO;
+ if (Flags & (SHOW_SUMMARY | SHOW_PKG_SIZE))
+ desired_meta_data |= LOAD_SIZE_PKG;
+ if (Flags & SHOW_ALL_SIZE)
+ desired_meta_data |= LOAD_SIZE_ALL;
+ if (Flags & (SHOW_SUMMARY | SHOW_DESC))
+ desired_meta_data |= LOAD_DESC;
+ if (Flags & SHOW_REQBY)
+ desired_meta_data |= LOAD_REQUIRED_BY;
+ if (Flags & SHOW_DISPLAY)
+ desired_meta_data |= LOAD_DISPLAY;
+ if (Flags & SHOW_INSTALL)
+ desired_meta_data |= LOAD_INSTALL;
+ if (Flags & SHOW_DEINSTALL)
+ desired_meta_data |= LOAD_DEINSTALL;
+ if (Flags & SHOW_MTREE)
+ desired_meta_data |= LOAD_MTREE;
+ if (Flags & SHOW_BUILD_VERSION)
+ desired_meta_data |= LOAD_BUILD_VERSION;
+
+
if (Which != WHICH_LIST) {
if (File2Pkg) {
/* Show all files with the package they belong to */
@@ -454,6 +628,5 @@ pkg_perform(lpkg_head_t *pkghead)
free_lpkg(lpp);
}
}
- ftp_stop();
return err_cnt;
}
diff --git a/pkgtools/pkg_install/files/info/show.c b/pkgtools/pkg_install/files/info/show.c
index 27ea79fcd88..cd3f04d273d 100644
--- a/pkgtools/pkg_install/files/info/show.c
+++ b/pkgtools/pkg_install/files/info/show.c
@@ -1,4 +1,4 @@
-/* $NetBSD: show.c,v 1.19 2008/01/29 15:39:31 hubertf Exp $ */
+/* $NetBSD: show.c,v 1.20 2008/02/02 16:21:45 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: show.c,v 1.11 1997/10/08 07:47:38 charnier Exp";
#else
-__RCSID("$NetBSD: show.c,v 1.19 2008/01/29 15:39:31 hubertf Exp $");
+__RCSID("$NetBSD: show.c,v 1.20 2008/02/02 16:21:45 joerg Exp $");
#endif
#endif
@@ -113,74 +113,50 @@ static const show_t showv[] = {
{-1, NULL, NULL}
};
-static int print_file_as_var(const char *, const char *);
+static int print_string_as_var(const char *, const char *);
void
-show_file(const char *pkg, const char *title, const char *fname, Boolean separator)
+show_file(const char *buf, const char *title, Boolean separator)
{
- FILE *fp;
- char line[1024];
- int n;
+ size_t len;
- if (!Quiet) {
+ if (!Quiet)
printf("%s%s", InfoPrefix, title);
- }
- if ((fp = fopen(fname, "r")) == (FILE *) NULL) {
- printf("ERROR: show_file: package \"%s\": can't open '%s' for reading\n", pkg, fname);
- } else {
- int append_nl = 0;
- while ((n = fread(line, 1, sizeof(line), fp)) != 0) {
- fwrite(line, 1, n, stdout);
- append_nl = (line[n - 1] != '\n');
- }
- (void) fclose(fp);
- if (append_nl)
- printf("\n");
- }
- if (!Quiet || separator) {
- printf("\n"); /* just in case */
- }
+
+ len = strlen(buf);
+ if (len == 0 || buf[len - 1] != '\n')
+ puts(buf);
+ else
+ fputs(buf, stdout);
+
+ if (!Quiet || separator)
+ printf("\n");
}
void
-show_var(const char *pkg, const char *fname, const char *variable)
+show_var(const char *buf, const char *variable)
{
- char *filename, *value;
-
- filename = pkgdb_pkg_file(pkg, fname);
+ char *value;
- if ((value = var_get(filename, variable)) != NULL) {
+ if ((value = var_get_memory(buf, variable)) != NULL) {
(void) printf("%s\n", value);
free(value);
}
- free(filename);
}
void
-show_index(const char *pkg, const char *title, const char *fname)
+show_index(const char *buf, const char *title)
{
- FILE *fp;
- char *line;
- size_t linelen;
- size_t maxline = termwidth;
+ size_t len;
- if (!Quiet) {
+ if (!Quiet)
printf("%s%s", InfoPrefix, title);
- maxline -= MAX(MAXNAMESIZE, strlen(title));
- }
- if ((fp = fopen(fname, "r")) == (FILE *) NULL) {
- warnx("show_index: package \"%s\": can't open '%s' for reading", pkg, fname);
- return;
- }
- if ((line = fgetln(fp, &linelen))) {
- line[linelen - 1] = '\0'; /* tromp newline & terminate string */
- if (termwidth && (linelen > maxline)) {
- /* XXX -1 if term does NOT have xn (or xenl) quirk */
- line[maxline] = '\0';
- }
- (void) printf("%s\n", line);
- }
- (void) fclose(fp);
+
+ len = strlen(buf);
+ if (len == 0 || buf[len - 1] != '\n')
+ puts(buf);
+ else
+ fputs(buf, stdout);
}
/*
@@ -359,7 +335,7 @@ show_bld_depends(const char *title, package_t *plist)
* Show entry for pkg_summary.txt file.
*/
void
-show_summary(package_t *plist, const char *binpkgfile)
+show_summary(struct pkg_meta *meta, package_t *plist, const char *binpkgfile)
{
static const char *bi_vars[] = {
"PKGPATH",
@@ -397,10 +373,10 @@ show_summary(package_t *plist, const char *binpkgfile)
}
}
- print_file_as_var("COMMENT", COMMENT_FNAME);
- print_file_as_var("SIZE_PKG", SIZE_PKG_FNAME);
+ print_string_as_var("COMMENT", meta->meta_comment);
+ print_string_as_var("SIZE_PKG", meta->meta_size_pkg);
- var_copy_list(BUILD_INFO_FNAME, bi_vars);
+ var_copy_list(meta->meta_build_info, bi_vars);
if (binpkgfile != NULL && stat(binpkgfile, &st) == 0) {
const char *base;
@@ -415,7 +391,7 @@ show_summary(package_t *plist, const char *binpkgfile)
/* XXX: DIGETS */
}
- print_file_as_var("DESCRIPTION", DESC_FNAME);
+ print_string_as_var("DESCRIPTION", meta->meta_desc);
putc('\n', stdout);
}
@@ -423,25 +399,16 @@ show_summary(package_t *plist, const char *binpkgfile)
* Print the contents of file fname as value of variable var to stdout.
*/
static int
-print_file_as_var(const char *var, const char *fname)
+print_string_as_var(const char *var, const char *str)
{
- FILE *fp;
- char *line;
- size_t len;
+ const char *eol;
- fp = fopen(fname, "r");
- if (!fp) {
- warn("unable to open %s file", fname);
- return -1;
+ while ((eol = strchr(str, '\n')) != NULL) {
+ printf("%s=%.*s\n", var, (int)(eol - str), str);
+ str = eol + 1;
}
-
- while ((line = fgetln(fp, &len)) != (char *) NULL) {
- if (line[len - 1] == '\n')
- --len;
- printf("%s=%.*s\n", var, (int)len, line);
- }
-
- fclose(fp);
+ if (*str)
+ printf("%s=%s\n", var, str);
return 0;
}
diff --git a/pkgtools/pkg_install/files/lib/lib.h b/pkgtools/pkg_install/files/lib/lib.h
index 693db9f5391..1fa13155c13 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.38 2007/11/30 00:30:40 rillig Exp $ */
+/* $NetBSD: lib.h,v 1.39 2008/02/02 16:21:45 joerg Exp $ */
/* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */
@@ -312,6 +312,7 @@ int pipe_to_system_end(pipe_to_system_t *);
/* variables file handling */
char *var_get(const char *, const char *);
+char *var_get_memory(const char *, const char *);
int var_set(const char *, const char *, const char *);
int var_copy_list(const char *, const char **);
@@ -391,8 +392,8 @@ void add_plist_top(package_t *, pl_ent_t, const char *);
void delete_plist(package_t *, Boolean, pl_ent_t, char *);
void write_plist(package_t *, FILE *, char *);
void stringify_plist(package_t *, char **, size_t *, char *);
+void parse_plist(package_t *, const char *);
void read_plist(package_t *, FILE *);
-int plist_cmd(unsigned char *, char **);
int delete_package(Boolean, Boolean, package_t *, Boolean);
/* Package Database */
diff --git a/pkgtools/pkg_install/files/lib/plist.c b/pkgtools/pkg_install/files/lib/plist.c
index 234e350ef36..0c0f0064fd1 100644
--- a/pkgtools/pkg_install/files/lib/plist.c
+++ b/pkgtools/pkg_install/files/lib/plist.c
@@ -1,4 +1,4 @@
-/* $NetBSD: plist.c,v 1.16 2007/08/03 13:16:00 joerg Exp $ */
+/* $NetBSD: plist.c,v 1.17 2008/02/02 16:21:45 joerg Exp $ */
#if HAVE_CONFIG_H
#include "config.h"
@@ -11,7 +11,7 @@
#if 0
static const char *rcsid = "from FreeBSD Id: plist.c,v 1.24 1997/10/08 07:48:15 charnier Exp";
#else
-__RCSID("$NetBSD: plist.c,v 1.16 2007/08/03 13:16:00 joerg Exp $");
+__RCSID("$NetBSD: plist.c,v 1.17 2008/02/02 16:21:45 joerg Exp $");
#endif
#endif
@@ -35,6 +35,35 @@ __RCSID("$NetBSD: plist.c,v 1.16 2007/08/03 13:16:00 joerg Exp $");
*
*/
+/*-
+ * Copyright (c) 2008 Joerg Sonnenberger <joerg@NetBSD.org>.
+ * 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 COPYRIGHT HOLDERS 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
+ * COPYRIGHT HOLDERS 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.
+ */
+
#include "lib.h"
#if HAVE_ERRNO_H
#include <errno.h>
@@ -48,7 +77,7 @@ __RCSID("$NetBSD: plist.c,v 1.16 2007/08/03 13:16:00 joerg Exp $");
/* This struct defines a plist command type */
typedef struct cmd_t {
- char *c_s; /* string to recognise */
+ const char *c_s; /* string to recognise */
pl_ent_t c_type; /* type of command */
int c_argc; /* # of arguments */
int c_subst; /* can substitute real prefix */
@@ -239,33 +268,93 @@ free_plist(package_t *pkg)
* For an ASCII string denoting a plist command, return its code and
* optionally its argument(s)
*/
-int
-plist_cmd(unsigned char *s, char **arg)
+static int
+plist_cmd(const char *s, char **arg)
{
const cmd_t *cmdp;
- /* 20 == fudge for max cmd len */
- unsigned char cmd[MaxPathSize + 20];
- unsigned char *cp;
- unsigned char *sp;
-
- (void) strlcpy(cmd, s, sizeof(cmd));
- str_lowercase(cmd);
- for (cp = cmd, sp = s; *cp; cp++, sp++) {
- if (isspace(*cp)) {
- for (*cp = '\0'; isspace(*sp); sp++) {
- }
+ const char *cp, *sp;
+ char *sp2;
+
+ for (cmdp = cmdv; cmdp->c_s; ++cmdp) {
+ for (sp = s, cp = cmdp->c_s; *sp && *cp; ++cp, ++sp)
+ if (tolower((unsigned char)*sp) != *cp)
+ break;
+ if (*cp == '\0')
break;
- }
- }
- if (arg) {
- *arg = sp;
}
- for (cmdp = cmdv; cmdp->c_s && strcmp(cmdp->c_s, cmd) != 0; cmdp++) {
+
+ if (cmdp->c_s == NULL || arg == NULL)
+ return cmdp->c_type;
+
+ while (isspace((unsigned char)*sp))
+ ++sp;
+ *arg = strdup(sp);
+ if (*arg == NULL)
+ err(2, "strdup failed");
+ if (*sp) {
+ sp2 = *arg + strlen(*arg) - 1;
+ /*
+ * The earlier loop ensured that at least one non-whitespace
+ * is in the string.
+ */
+ while (isspace((unsigned char)*sp2))
+ --sp2;
+ sp2[1] = '\0';
}
return cmdp->c_type;
}
/*
+ * Parse a packaging list from a memory buffer.
+ */
+void
+parse_plist(package_t *pkg, const char *buf)
+{
+ int cmd;
+ char *line, *cp;
+ const char *eol, *next;
+ size_t len;
+
+ for (; *buf; buf = next) {
+ /* Until add_plist can deal with trailing whitespace. */
+ if ((eol = strchr(buf, '\n')) != NULL) {
+ next = eol + 1;
+ len = eol - buf;
+ } else {
+ len = strlen(buf);
+ next = buf + len;
+ }
+
+ while (len && isspace((unsigned char)buf[len - 1]))
+ --len;
+
+ if (len == 0)
+ continue;
+
+ line = malloc(len + 1);
+ if (line == NULL)
+ err(2, "malloc failed");
+ memcpy(line, buf, len);
+ line[len] = '\0';
+
+ if (*(cp = line) == CMD_CHAR) {
+ if ((cmd = plist_cmd(line + 1, &cp)) == FAIL) {
+ warnx("Unrecognised PLIST command `%s'", line);
+ continue;
+ }
+ if (*cp == '\0') {
+ free(cp);
+ cp = NULL;
+ }
+ } else {
+ cmd = PLIST_FILE;
+ }
+ add_plist(pkg, cmd, cp);
+ free(cp);
+ }
+}
+
+/*
* Read a packing list from a file
*/
void
@@ -275,6 +364,7 @@ read_plist(package_t *pkg, FILE * fp)
char *cp;
int cmd;
int len;
+ int free_cp;
while (fgets(pline, MaxPathSize, fp) != (char *) NULL) {
for (len = strlen(pline); len &&
@@ -284,18 +374,23 @@ read_plist(package_t *pkg, FILE * fp)
if (len == 0) {
continue;
}
+ free_cp = 0;
if (*(cp = pline) == CMD_CHAR) {
if ((cmd = plist_cmd(pline + 1, &cp)) == FAIL) {
warnx("Unrecognised PLIST command `%s'", pline);
continue;
}
if (*cp == '\0') {
+ free(cp);
cp = NULL;
}
+ free_cp = 1;
} else {
cmd = PLIST_FILE;
}
add_plist(pkg, cmd, cp);
+ if (free_cp)
+ free(cp);
}
}
diff --git a/pkgtools/pkg_install/files/lib/var.c b/pkgtools/pkg_install/files/lib/var.c
index 4dc2cc6476b..bc902bd6702 100644
--- a/pkgtools/pkg_install/files/lib/var.c
+++ b/pkgtools/pkg_install/files/lib/var.c
@@ -1,11 +1,11 @@
-/* $NetBSD: var.c,v 1.5 2007/08/09 18:03:38 joerg Exp $ */
+/* $NetBSD: var.c,v 1.6 2008/02/02 16:21:46 joerg Exp $ */
/*-
- * Copyright (c) 2005 The NetBSD Foundation, Inc.
+ * Copyright (c) 2005, 2008 The NetBSD Foundation, Inc.
* All rights reserved.
*
* This code is derived from software contributed to The NetBSD Foundation
- * by Dieter Baron, Thomas Klausner, and Johnny Lam.
+ * by Dieter Baron, Thomas Klausner, Johnny Lam, and Joerg Sonnenberger.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -40,7 +40,7 @@
#include <sys/cdefs.h>
#endif
#ifndef lint
-__RCSID("$NetBSD: var.c,v 1.5 2007/08/09 18:03:38 joerg Exp $");
+__RCSID("$NetBSD: var.c,v 1.6 2008/02/02 16:21:46 joerg Exp $");
#endif
#if HAVE_SYS_STAT_H
@@ -65,34 +65,29 @@ static void var_print(FILE *, const char *, const char *);
* Copy the specified varibales from the file fname to stdout.
*/
int
-var_copy_list(const char *fname, const char **variables)
+var_copy_list(const char *buf, const char **variables)
{
- FILE *fp;
- char *line;
- size_t len;
- const char *p;
+ const char *eol, *next, *p;
+ size_t len;
int i;
- fp = fopen(fname, "r");
- if (!fp) {
- if (errno != ENOENT)
- warn("var_copy_list: can't open '%s' for reading",
- fname);
- return -1;
- }
+ for (; *buf; buf = next) {
+ if ((eol = strchr(buf, '\n')) != NULL) {
+ next = eol + 1;
+ len = eol - buf;
+ } else {
+ next = eol;
+ len = strlen(buf);
+ }
- while ((line = fgetln(fp, &len)) != (char *) NULL) {
- if (line[len - 1] == '\n')
- --len;
for (i=0; variables[i]; i++) {
- if ((p=var_cmp(line, len, variables[i],
+ if ((p=var_cmp(buf, len, variables[i],
strlen(variables[i]))) != NULL) {
- printf("%.*s\n", (int)len, line);
+ printf("%.*s\n", (int)len, buf);
break;
}
}
}
- (void) fclose(fp);
return 0;
}
@@ -147,6 +142,48 @@ var_get(const char *fname, const char *variable)
}
/*
+ * Print the value of variable from the memory buffer to stdout.
+ */
+char *
+var_get_memory(const char *buf, const char *variable)
+{
+ const char *eol, *next, *data;
+ size_t len, varlen, thislen, valuelen;
+ char *value;
+
+ varlen = strlen(variable);
+ if (varlen == 0)
+ return NULL;
+
+ value = NULL;
+ valuelen = 0;
+
+ for (; *buf; buf = next) {
+ if ((eol = strchr(buf, '\n')) != NULL) {
+ next = eol + 1;
+ len = eol - buf;
+ } else {
+ next = eol;
+ len = strlen(buf);
+ }
+ if ((data = var_cmp(buf, len, variable, varlen)) == NULL)
+ continue;
+
+ thislen = buf + len - data;
+ if (value) {
+ value = realloc(value, valuelen+thislen+2);
+ value[valuelen++] = '\n';
+ }
+ else {
+ value = malloc(thislen+1);
+ }
+ sprintf(value + valuelen, "%.*s", (int)thislen, data);
+ valuelen += thislen;
+ }
+ return value;
+}
+
+/*
* Add given variable with given value to file, overwriting any
* previous occurrence.
*/
diff --git a/pkgtools/pkg_install/files/lib/version.h b/pkgtools/pkg_install/files/lib/version.h
index 9a19fb5a274..68ecc41d3b7 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.88 2008/01/26 23:30:24 joerg Exp $ */
+/* $NetBSD: version.h,v 1.89 2008/02/02 16:21:46 joerg Exp $ */
/*
* Copyright (c) 2001 Thomas Klausner. All rights reserved.
@@ -33,6 +33,6 @@
#ifndef _INST_LIB_VERSION_H_
#define _INST_LIB_VERSION_H_
-#define PKGTOOLS_VERSION "20080126"
+#define PKGTOOLS_VERSION "20080202"
#endif /* _INST_LIB_VERSION_H_ */