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