diff options
author | joerg <joerg> | 2008-04-04 15:21:32 +0000 |
---|---|---|
committer | joerg <joerg> | 2008-04-04 15:21:32 +0000 |
commit | c12ebd2c35f4d814c139b10af71280fc2de2cfba (patch) | |
tree | 17f752445c926f2ac88209d1c9a7f73d9ea8d0e3 /pkgtools | |
parent | d888c2e1db1d5f6aad140728428dca42b1ab388b (diff) | |
download | pkgsrc-c12ebd2c35f4d814c139b10af71280fc2de2cfba.tar.gz |
pkg_install-20080404:
Switch pkg_info to use libfetch for remote access.
Diffstat (limited to 'pkgtools')
-rw-r--r-- | pkgtools/pkg_install/Makefile | 7 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/info/Makefile.in | 4 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/info/perform.c | 80 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/Makefile.in | 4 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/lib.h | 10 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/pkg_io.c | 139 | ||||
-rw-r--r-- | pkgtools/pkg_install/files/lib/version.h | 4 |
7 files changed, 186 insertions, 62 deletions
diff --git a/pkgtools/pkg_install/Makefile b/pkgtools/pkg_install/Makefile index 15f141d1cae..a0b27ca7bad 100644 --- a/pkgtools/pkg_install/Makefile +++ b/pkgtools/pkg_install/Makefile @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.149 2008/04/03 14:22:26 jlam Exp $ +# $NetBSD: Makefile,v 1.150 2008/04/04 15:21:32 joerg Exp $ # Notes to package maintainers: # @@ -105,6 +105,7 @@ USE_BUILTIN.libarchive= no FILESDIR.bzip2?= ${.CURDIR}/../../archivers/bzip2/files FILESDIR.libarchive?= ${.CURDIR}/../../archivers/libarchive/files FILESDIR.zlib?= ${.CURDIR}/../../devel/zlib/files +FILESDIR.libfetch?= ${.CURDIR}/../../net/libfetch/files .if empty(USE_BUILTIN.bzip2:M[yY][eE][sS]) CPPFLAGS+= -I${WRKDIR}/bzip2 @@ -118,6 +119,8 @@ LDFLAGS+= -L${WRKDIR}/zlib CPPFLAGS+= -I${WRKDIR}/libarchive/libarchive LDFLAGS+= -L${WRKDIR}/libarchive/.libs .endif +CPPFLAGS+= -I${WRKDIR}/libfetch +LDFLAGS+= -L${WRKDIR}/libfetch do-extract: @${CP} -R ${FILESDIR} ${WRKSRC} @@ -130,6 +133,7 @@ do-extract: .if empty(USE_BUILTIN.libarchive:M[yY][eE][sS]) @${CP} -R ${FILESDIR.libarchive} ${WRKDIR}/libarchive .endif + @${CP} -R ${FILESDIR.libfetch} ${WRKDIR}/libfetch pre-configure: .if empty(USE_BUILTIN.bzip2:M[yY][eE][sS]) @@ -146,6 +150,7 @@ pre-configure: --disable-dependency-tracking cd ${WRKDIR}/libarchive && ${BUILD_MAKE_CMD} .endif + cd ${WRKDIR}/libfetch && ${BUILD_MAKE_CMD} # XXX Reverse the order that update does things since # XXX we need pkg_delete built before we can deinstall. diff --git a/pkgtools/pkg_install/files/info/Makefile.in b/pkgtools/pkg_install/files/info/Makefile.in index 055465ad524..5e1bbc856e5 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.13 2008/03/10 12:14:32 wiz Exp $ +# $NetBSD: Makefile.in,v 1.14 2008/04/04 15:21:32 joerg Exp $ srcdir= @srcdir@ @@ -16,7 +16,7 @@ BOOTSTRAP= @bootstrap@ CC= @CC@ CCLD= $(CC) .if empty(BOOTSTRAP) -LIBS= -linstall -larchive -lbz2 -lz @LIBS@ +LIBS= -linstall -larchive -lbz2 -lfetch -lz @LIBS@ CPPFLAGS= @CPPFLAGS@ -I. -I$(srcdir) -I../lib .else LIBS= -linstall @LIBS@ diff --git a/pkgtools/pkg_install/files/info/perform.c b/pkgtools/pkg_install/files/info/perform.c index b702ea1978c..528ec13c7a9 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.45 2008/03/09 18:03:46 joerg Exp $ */ +/* $NetBSD: perform.c,v 1.46 2008/04/04 15:21:32 joerg Exp $ */ #if HAVE_CONFIG_H #include "config.h" @@ -17,7 +17,7 @@ #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.45 2008/03/09 18:03:46 joerg Exp $"); +__RCSID("$NetBSD: perform.c,v 1.46 2008/04/04 15:21:32 joerg Exp $"); #endif #endif @@ -172,14 +172,10 @@ free_pkg_meta(struct pkg_meta *meta) free(meta); } +#ifndef BOOTSTRAP static struct pkg_meta * -read_meta_data_from_fd(int fd) +read_meta_data_from_archive(struct archive *archive) { -#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; @@ -190,12 +186,6 @@ read_meta_data_from_fd(int fd) found_required = 0; - 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"); @@ -252,8 +242,8 @@ read_meta_data_from_fd(int fd) archive_read_finish(archive); return meta; -#endif } +#endif static struct pkg_meta * read_meta_data_from_pkgdb(const char *pkg) @@ -304,21 +294,6 @@ read_meta_data_from_pkgdb(const char *pkg) 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) { @@ -328,33 +303,30 @@ pkg_do(const char *pkg) const char *binpkgfile = NULL; if (IS_URL(pkg)) { - 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); +#ifdef BOOTSTRAP + errx(2, "Remote access not supported during bootstrap"); +#else + struct archive *archive; + void *remote_archive_cookie; + + archive = open_remote_archive(pkg, &remote_archive_cookie); + + meta = read_meta_data_from_archive(archive); + close_remote_archive(remote_archive_cookie); +#endif } else if (fexists(pkg) && isfile(pkg)) { - int pkg_fd; +#ifdef BOOTSTRAP + errx(2, "Binary packages not supported during bootstrap"); +#else + struct archive *archive; + void *remote_archive_cookie; - 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); + archive = open_local_archive(pkg, &remote_archive_cookie); + + meta = read_meta_data_from_archive(archive); + close_local_archive(remote_archive_cookie); binpkgfile = pkg; +#endif } else { /* * It's not an uninstalled package, try and find it among the diff --git a/pkgtools/pkg_install/files/lib/Makefile.in b/pkgtools/pkg_install/files/lib/Makefile.in index 42fd666f6e8..f542390de47 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.19 2008/03/10 12:14:32 wiz Exp $ +# $NetBSD: Makefile.in,v 1.20 2008/04/04 15:21:32 joerg Exp $ srcdir= @srcdir@ @@ -29,7 +29,7 @@ LIB= libinstall.a OBJS= automatic.o conflicts.o decompress.o dewey.o fexec.o file.o \ ftpio.o global.o iterate.o lpkg.o opattern.o \ - path.o pen.o pexec.o pkgdb.o plist.o \ + path.o pen.o pexec.o pkgdb.o pkg_io.o plist.o \ str.o var.o version.o vulnerabilities-file.o .if !empty(BOOTSTRAP) diff --git a/pkgtools/pkg_install/files/lib/lib.h b/pkgtools/pkg_install/files/lib/lib.h index 04fb9ee452b..03dfc0e68df 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.40 2008/02/19 15:16:24 joerg Exp $ */ +/* $NetBSD: lib.h,v 1.41 2008/04/04 15:21:32 joerg Exp $ */ /* from FreeBSD Id: lib.h,v 1.25 1997/10/08 07:48:03 charnier Exp */ @@ -385,6 +385,14 @@ int ftp_cmd(const char *, const char *); int ftp_start(const char *); void ftp_stop(void); +/* pkg_io.c: Local and remote archive handling */ +struct archive; + +struct archive *open_remote_archive(const char *, void **); +void close_remote_archive(void *); +struct archive *open_local_archive(const char *, void **); +void close_local_archive(void *); + /* Packing list */ plist_t *new_plist_entry(void); plist_t *last_plist(package_t *); diff --git a/pkgtools/pkg_install/files/lib/pkg_io.c b/pkgtools/pkg_install/files/lib/pkg_io.c new file mode 100644 index 00000000000..643262e0221 --- /dev/null +++ b/pkgtools/pkg_install/files/lib/pkg_io.c @@ -0,0 +1,139 @@ +/* $NetBSD: pkg_io.c,v 1.1 2008/04/04 15:21:32 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. + */ + +#if HAVE_CONFIG_H +#include "config.h" +#endif +#include <nbcompat.h> +#if HAVE_SYS_CDEFS_H +#include <sys/cdefs.h> +#endif + +__RCSID("$NetBSD: pkg_io.c,v 1.1 2008/04/04 15:21:32 joerg Exp $"); + +#include <archive.h> +#include <archive_entry.h> +#if HAVE_ERR_H +#include <err.h> +#endif +#if HAVE_ERRNO_H +#include <errno.h> +#endif +#include <fetch.h> +#include <stdlib.h> + +#include "lib.h" + +struct fetch_archive { + const char *url; + fetchIO *fetch; + char buffer[32768]; +}; + +static int +fetch_archive_open(struct archive *a, void *client_data) +{ + struct fetch_archive *f = client_data; + + f->fetch = fetchGetURL(f->url, ""); + if (f->fetch == NULL) + return ENOENT; + return 0; +} + +static ssize_t +fetch_archive_read(struct archive *a, void *client_data, + const void **buffer) +{ + struct fetch_archive *f = client_data; + + *buffer = f->buffer; + return fetchIO_read(f->fetch, f->buffer, sizeof(f->buffer)); +} + +static int +fetch_archive_close(struct archive *a, void *client_data) +{ + struct fetch_archive *f = client_data; + + if (f->fetch != NULL) + fetchIO_close(f->fetch); + return 0; +} + +struct archive * +open_remote_archive(const char *url, void **cookie) +{ + struct fetch_archive *f; + struct archive *archive; + + f = malloc(sizeof(*f)); + if (f == NULL) + err(2, "cannot allocate memory for remote archive"); + f->url = url; + + archive = archive_read_new(); + archive_read_support_compression_all(archive); + archive_read_support_format_all(archive); + if (archive_read_open(archive, f, fetch_archive_open, fetch_archive_read, + fetch_archive_close)) + errx(2, "cannot open archive: %s", archive_error_string(archive)); + + *cookie = f; + + return archive; +} + +void +close_remote_archive(void *cookie) +{ + free(cookie); +} + +struct archive * +open_local_archive(const char *path, void **cookie) +{ + struct archive *archive; + + archive = archive_read_new(); + archive_read_support_compression_all(archive); + archive_read_support_format_all(archive); + if (archive_read_open_filename(archive, path, 1024)) + errx(2, "cannot open archive: %s", + archive_error_string(archive)); + *cookie = NULL; + + return archive; +} + +void +close_local_archive(void *cookie) +{ +} diff --git a/pkgtools/pkg_install/files/lib/version.h b/pkgtools/pkg_install/files/lib/version.h index 0a6307c47cb..f6ceb3da2fa 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.97 2008/03/13 16:35:31 joerg Exp $ */ +/* $NetBSD: version.h,v 1.98 2008/04/04 15:21:32 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 "20080313" +#define PKGTOOLS_VERSION "20080402" #endif /* _INST_LIB_VERSION_H_ */ |