From owner-freebsd-current@FreeBSD.ORG Tue Dec 15 15:25:38 2009 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id A7A24106568F for ; Tue, 15 Dec 2009 15:25:38 +0000 (UTC) (envelope-from baptiste.daroussin@gmail.com) Received: from mail-ew0-f226.google.com (mail-ew0-f226.google.com [209.85.219.226]) by mx1.freebsd.org (Postfix) with ESMTP id 325B38FC23 for ; Tue, 15 Dec 2009 15:25:37 +0000 (UTC) Received: by ewy26 with SMTP id 26so4984280ewy.3 for ; Tue, 15 Dec 2009 07:25:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:received:date:from:to:subject :message-id:mime-version:content-type:content-disposition :content-transfer-encoding:user-agent; bh=u3qiBmUzz6c/ecwomrjafn9phAgC7PMrdlWCfuSs80s=; b=vjW6YTc1tXMJrCdYYBnjFqdQnPog5O4elom/gxmo1Uj8+fyQUpAWPUjgqTkqQjJXWt yFxzn96bkC2NparXfDZVk0ZRG5mTTcsSnoNaPsPcDsaWEp9hU1mBIKfcLwTNd0spUlav 7ILgX6IaQKXpbdtBWR1EvbJeVLIZaxJLofvBQ= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=date:from:to:subject:message-id:mime-version:content-type :content-disposition:content-transfer-encoding:user-agent; b=u7I3jxwwPxNSujFQFSXDfw7A6Inrn7ds2SJio2xyhc19VbHFC23KPY9MANMHNYLYwC ueK/FOzW/41A75DQEL9arItE0X22+mGnnQvmLse6EJvoQZs7BXp1UWRZgvRtnfFYgE4g XFYkNYLqGyAWR5h6d1/gqndhnAeS1eIimd+no= Received: by 10.213.96.223 with SMTP id i31mr2709980ebn.57.1260888869267; Tue, 15 Dec 2009 06:54:29 -0800 (PST) Received: from wicklow.lan (stc92-3-82-245-249-89.fbx.proxad.net [82.245.249.89]) by mx.google.com with ESMTPS id 15sm3773158ewy.4.2009.12.15.06.54.27 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 15 Dec 2009 06:54:28 -0800 (PST) Received: from bapt (uid 1001) (envelope-from baptiste.daroussin@gmail.com) id 2a309 by wicklow.lan (DragonFly Mail Agent) Tue, 15 Dec 2009 15:52:43 +0100 Date: Tue, 15 Dec 2009 15:52:43 +0100 From: Baptiste Daroussin To: freebsd-current@freebsd.org Message-ID: <20091215145243.GF1016@wicklow.lan> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="ADZbWkCsHQ7r3kzd" Content-Disposition: inline Content-Transfer-Encoding: 8bit User-Agent: Mutt/1.5.20 (2009-06-14) Subject: Small patches for pkg_add X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 15 Dec 2009 15:25:38 -0000 --ADZbWkCsHQ7r3kzd Content-Type: text/plain; charset=us-ascii Content-Disposition: inline I've written a small patch for pkg_install that removes the system call to tar in pkg_add command replacing it by some libarchive code. I'm planning to do some cleanup by time to time sending small patches on pkg_install. My very first goal is to remove most of the system call, and to understand the way the code works, not to rewrite everything. Here is the first patch : - modification of the unpack function to use libarchive to extract data - it does not modify the way things works: it does exactly the same thing without the system call - I also removed two unused function from lib/file.c It is my first patch for src, I don't know the good process for that. Hope to send more patches soon. This is not another attempt to rewrite pkgtools, I just want to improve them the time that people working on the different rewrites finish their work. the patch is join to this mail, or can be found at the following link: http://etoilebsd.net/~bapt/pkgtools-libarchive-patch1.patch regards Bapt --ADZbWkCsHQ7r3kzd Content-Type: text/x-diff; charset=iso-8859-1 Content-Disposition: attachment; filename="pkgtools-libarchive-patch1.patch" Content-Transfer-Encoding: 8bit Index: delete/Makefile =================================================================== --- delete/Makefile (révision 199967) +++ delete/Makefile (copie de travail) @@ -9,6 +9,6 @@ WFORMAT?= 1 DPADD= ${LIBINSTALL} ${LIBMD} -LDADD= ${LIBINSTALL} -lmd +LDADD= ${LIBINSTALL} -lmd -larchive .include Index: create/Makefile =================================================================== --- create/Makefile (révision 199967) +++ create/Makefile (copie de travail) @@ -9,6 +9,6 @@ WFORMAT?= 1 DPADD= ${LIBINSTALL} ${LIBMD} -LDADD= ${LIBINSTALL} -lmd +LDADD= ${LIBINSTALL} -lmd -larchive .include Index: version/Makefile =================================================================== --- version/Makefile (révision 199967) +++ version/Makefile (copie de travail) @@ -9,7 +9,7 @@ WFORMAT?= 1 DPADD= ${LIBINSTALL} ${LIBFETCH} ${LIBMD} -LDADD= ${LIBINSTALL} -lfetch -lmd +LDADD= ${LIBINSTALL} -lfetch -lmd -larchive test: sh ${.CURDIR}/test-pkg_version.sh Index: lib/file.c =================================================================== --- lib/file.c (révision 199967) +++ lib/file.c (copie de travail) @@ -22,10 +22,13 @@ __FBSDID("$FreeBSD$"); #include "lib.h" +#include +#include #include #include #include #include +#include /* Quick check to see if a file exists */ Boolean @@ -293,68 +296,49 @@ } } -/* - * Copy a hierarchy (possibly from dir) to the current directory, or - * if "to" is TRUE, from the current directory to a location someplace - * else. - * - * Though slower, using tar to copy preserves symlinks and everything - * without me having to write some big hairy routine to do it. - */ -void -copy_hierarchy(const char *dir, const char *fname, Boolean to) -{ - char cmd[FILENAME_MAX * 3]; - - if (!to) { - /* If absolute path, use it */ - if (*fname == '/') - dir = "/"; - snprintf(cmd, FILENAME_MAX * 3, "/usr/bin/tar cf - -C %s %s | /usr/bin/tar xpf -", - dir, fname); - } - else - snprintf(cmd, FILENAME_MAX * 3, "/usr/bin/tar cf - %s | /usr/bin/tar xpf - -C %s", - fname, dir); -#ifdef DEBUG - printf("Using '%s' to copy trees.\n", cmd); -#endif - if (system(cmd)) { - cleanup(0); - errx(2, "%s: could not perform '%s'", __func__, cmd); - } -} - /* Unpack a tar file */ int unpack(const char *pkg, const char *flist) { - const char *comp, *cp; - char suff[80]; - - comp = ""; - /* - * Figure out by a crude heuristic whether this or not this is probably - * compressed and whichever compression utility was used (gzip or bzip2). - */ - if (strcmp(pkg, "-")) { - cp = strrchr(pkg, '.'); - if (cp) { - strcpy(suff, cp + 1); - if (strchr(suff, 'z') || strchr(suff, 'Z')) { - if (strchr(suff, 'b')) - comp = "-j"; - else - comp = "-z"; - } - } - } + int r; + bool whole_archive=false; + struct archive *a = archive_read_new(); + struct archive_entry *entry; + const int archive_flags = ARCHIVE_EXTRACT_OWNER| ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_TIME; + if(flist == NULL) + whole_archive=true; else - comp = "-j"; - if (vsystem("/usr/bin/tar -xp %s -f '%s' %s", comp, pkg, flist ? flist : "")) { - warnx("tar extract of %s failed!", pkg); + if(strlen(flist) == 0) + whole_archive=true; + archive_read_support_compression_all(a); + archive_read_support_format_all(a); + r = archive_read_open_filename(a, pkg, 16384); + if (r != ARCHIVE_OK) { + archive_read_finish(a); return 1; - } + } + if(!whole_archive) { + while ( ( r = archive_read_next_header(a, &entry)) == ARCHIVE_OK) { + if (strcmp(archive_entry_pathname(entry), flist)==0) { + r = archive_read_extract(a, entry, archive_flags); + if (r != ARCHIVE_OK) { + warnx("tar extract of %s failed", pkg); + archive_read_finish(a); + return 1; + } + } else + archive_read_data_skip(a); + } + } else + while ((archive_read_next_header(a, &entry)) == ARCHIVE_OK) { + r = archive_read_extract(a, entry, archive_flags); + if (r != ARCHIVE_OK) { + warnx("tar extract of %s failed", pkg); + archive_read_finish(a); + return 1; + } + } + archive_read_finish(a); return 0; } Index: lib/lib.h =================================================================== --- lib/lib.h (révision 199967) +++ lib/lib.h (copie de travail) @@ -189,7 +189,6 @@ void write_file(const char *, const char *); void copy_file(const char *, const char *, const char *); void move_file(const char *, const char *, const char *); -void copy_hierarchy(const char *, const char *, Boolean); int delete_hierarchy(const char *, Boolean, Boolean); int unpack(const char *, const char *); void format_cmd(char *, int, const char *, const char *, const char *); Index: add/perform.c =================================================================== --- add/perform.c (révision 199967) +++ add/perform.c (copie de travail) @@ -128,7 +128,7 @@ warnx("can't stat package file '%s'", pkg_fullname); goto bomb; } - sprintf(extract_contents, "--fast-read %s", CONTENTS_FNAME); + sprintf(extract_contents, "%s", CONTENTS_FNAME); extract = extract_contents; } else { Index: add/Makefile =================================================================== --- add/Makefile (révision 199967) +++ add/Makefile (copie de travail) @@ -9,6 +9,6 @@ WFORMAT?= 1 DPADD= ${LIBINSTALL} ${LIBFETCH} ${LIBMD} -LDADD= ${LIBINSTALL} -lfetch -lmd +LDADD= ${LIBINSTALL} -lfetch -lmd -larchive .include Index: info/Makefile =================================================================== --- info/Makefile (révision 199967) +++ info/Makefile (copie de travail) @@ -9,6 +9,6 @@ WFORMAT?= 1 DPADD= ${LIBINSTALL} ${LIBFETCH} ${LIBMD} -LDADD= ${LIBINSTALL} -lfetch -lmd +LDADD= ${LIBINSTALL} -lfetch -lmd -larchive .include Index: updating/Makefile =================================================================== --- updating/Makefile (révision 199967) +++ updating/Makefile (copie de travail) @@ -9,6 +9,6 @@ WFORMAT?= 1 DPADD= ${LIBINSTALL} ${LIBFETCH} ${LIBMD} -LDADD= ${LIBINSTALL} -lfetch -lmd +LDADD= ${LIBINSTALL} -lfetch -lmd -larchive .include --ADZbWkCsHQ7r3kzd--