PERFORCE change 176778 for review

Garrett Cooper gcooper at FreeBSD.org
Sun Apr 11 09:44:44 UTC 2010


http://p4web.freebsd.org/@@176778?ac=10

Change 176778 by gcooper at gcooper-bayonetta on 2010/04/11 09:43:48

	Commit modified copy of bapt's patch to enable archive(3) support with pkg_install in unpack. Need to test.

Affected files ...

.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/add/Makefile#2 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/create/Makefile#2 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/delete/Makefile#2 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/info/Makefile#2 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/lib/Makefile#2 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/lib/file.c#6 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/updating/Makefile#2 edit
.. //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/version/Makefile#2 edit

Differences ...

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/add/Makefile#2 (text+ko) ====

@@ -8,7 +8,7 @@
 WARNS?=	3
 WFORMAT?=	1
 
-DPADD=	${LIBINSTALL} ${LIBFETCH} ${LIBMD}
-LDADD=	${LIBINSTALL} -lfetch -lmd
+DPADD=	${LIBINSTALL} ${LIBARCHIVE} ${LIBFETCH} ${LIBMD}
+LDADD=	${LIBINSTALL} -larchive -lfetch -lmd
 
 .include <bsd.prog.mk>

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/create/Makefile#2 (text+ko) ====

@@ -8,7 +8,7 @@
 WARNS?=	3
 WFORMAT?=	1
 
-DPADD=	${LIBINSTALL} ${LIBMD}
-LDADD=	${LIBINSTALL} -lmd
+DPADD=	${LIBINSTALL} ${LIBARCHIVE} ${LIBMD}
+LDADD=	${LIBINSTALL} -larchive -lmd
 
 .include <bsd.prog.mk>

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/delete/Makefile#2 (text+ko) ====

@@ -7,7 +7,7 @@
 
 WFORMAT?=	1
 
-DPADD=	${LIBINSTALL} ${LIBMD}
-LDADD=	${LIBINSTALL} -lmd
+DPADD=	${LIBINSTALL} ${LIBARCHIVE} ${LIBMD}
+LDADD=	${LIBINSTALL} -larchive -lmd
 
 .include <bsd.prog.mk>

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/info/Makefile#2 (text+ko) ====

@@ -7,7 +7,7 @@
 
 WFORMAT?=	1
 
-DPADD=	${LIBINSTALL} ${LIBFETCH} ${LIBMD}
-LDADD=	${LIBINSTALL} -lfetch -lmd
+DPADD=	${LIBINSTALL} ${LIBARCHIVE} ${LIBFETCH} ${LIBMD}
+LDADD=	${LIBINSTALL} -larchive -lfetch -lmd
 
 .include <bsd.prog.mk>

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/lib/Makefile#2 (text+ko) ====


==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/lib/file.c#6 (text+ko) ====

@@ -22,7 +22,10 @@
 __FBSDID("$FreeBSD: src/usr.sbin/pkg_install/lib/file.c,v 1.70 2010/04/01 14:27:29 flz Exp $");
 
 #include "lib.h"
+#include <archive.h>
+#include <archive_entry.h>
 #include <err.h>
+#include <fnmatch.h>
 #include <pwd.h>
 #include <time.h>
 #include <sys/wait.h>
@@ -334,37 +337,71 @@
     }
 }
 
+#define EXTRACT_ARCHIVE_FLAGS	(ARCHIVE_EXTRACT_OWNER | ARCHIVE_EXTRACT_PERM | ARCHIVE_EXTRACT_TIME)
+
 /* Unpack a tar file */
 int
-unpack(const char *pkg, const char *flist)
+unpack(const char *pkg, const char *file_expr)
 {
-    const char *comp, *cp;
-    char suff[80];
+	struct archive *archive;
+	struct archive_entry *archive_entry;
+	Boolean extract_whole_archive = FALSE;
+	const char *error = NULL;
+	const char *pkg_name_humanized;
+	int fn_ret = 0, r;
+
+	if (file_expr == NULL || strcmp("*", file_expr) == 0)
+		extract_whole_archive = TRUE;
+
+	pkg_name_humanized = strcmp(pkg, "-") == 0 ? "(stdin)" : pkg;
+
+	archive_read_support_compression_all(archive);
+	archive_read_support_format_tar(archive);
+
+	/* The initial open failed */
+	if (archive_read_open_filename(archive, pkg,
+	    ARCHIVE_DEFAULT_BYTES_PER_BLOCK) != ARCHIVE_OK) {
+
+		error = archive_error_string(archive);
+		warnx("%s: unable to open the package from %s: %s",
+		    __func__, pkg_name_humanized, error);
 
-    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";
-	    }
 	}
-    }
-    else
-	comp = "-j";
-    if (vsystem("/usr/bin/tar -xp %s -f '%s' %s", comp, pkg, flist ? flist : "")) {
-	warnx("tar extract of %s failed!", pkg);
-	return 1;
-    }
-    return 0;
+	else
+		while (error == NULL &&
+		    (r = archive_read_next_header(archive, &archive_entry)) ==
+		     ARCHIVE_OK) {
+
+			/* Let's extract the whole archive, or just a file. */
+			if (extract_whole_archive == TRUE ||
+			    (fn_ret = fnmatch(file_expr,
+			     archive_entry_pathname(archive_entry),
+			         FNM_PATHNAME) == 0)) {
+
+				r = archive_read_extract(archive, archive_entry,
+				    EXTRACT_ARCHIVE_FLAGS);
+				if (r != ARCHIVE_OK) {
+					error = archive_error_string(archive);
+					warnx("%s: extraction for %s failed: "
+					    "%s", __func__, pkg_name_humanized,
+					    error);
+				}
+
+			}
+
+			/*
+			 * Else let's skip the entry because we still haven't
+			 * found what we're looking for.
+			 */
+			else if (fn_ret == FNM_NOMATCH)
+				archive_read_data_skip(archive);
+
+		}
+
+	archive_read_finish(archive);
+
+	return (error == NULL ? 0 : 1);
+
 }
 
 /*

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/updating/Makefile#2 (text+ko) ====

@@ -7,7 +7,7 @@
 
 WFORMAT?= 1
 
-DPADD=	${LIBINSTALL} ${LIBFETCH} ${LIBMD}
-LDADD=	${LIBINSTALL} -lfetch -lmd
+DPADD=	${LIBINSTALL} ${LIBARCHIVE} ${LIBFETCH} ${LIBMD}
+LDADD=	${LIBINSTALL} -larchive -lfetch -lmd
 
 .include <bsd.prog.mk>

==== //depot/projects/soc2007/gcooper-pkg_install-enhancements-simplified/usr.sbin/pkg_install/version/Makefile#2 (text+ko) ====

@@ -7,8 +7,8 @@
 
 WFORMAT?=	1
 
-DPADD=	${LIBINSTALL} ${LIBFETCH} ${LIBMD}
-LDADD=	${LIBINSTALL} -lfetch -lmd
+DPADD=	${LIBINSTALL} ${LIBARCHIVE} ${LIBFETCH} ${LIBMD}
+LDADD=	${LIBINSTALL} -larchive -lfetch -lmd
 
 test:
 	sh ${.CURDIR}/test-pkg_version.sh


More information about the p4-projects mailing list