Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 17 Apr 2009 00:55:52 +0000 (UTC)
From:      Tim Kientzle <kientzle@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r191173 - head/lib/libarchive
Message-ID:  <200904170055.n3H0tqmA099278@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: kientzle
Date: Fri Apr 17 00:55:52 2009
New Revision: 191173
URL: http://svn.freebsd.org/changeset/base/191173

Log:
  Implement command-line fallbacks for gzip and bzip2 decompression as well.
  Not an issue for FreeBSD, since the base system has the necessary libraries.
  Since all decompressors are always available now, we can unconditionally
  enable them in archive_read_support_compression_all().

Modified:
  head/lib/libarchive/archive_read_support_compression_all.c
  head/lib/libarchive/archive_read_support_compression_bzip2.c
  head/lib/libarchive/archive_read_support_compression_gzip.c

Modified: head/lib/libarchive/archive_read_support_compression_all.c
==============================================================================
--- head/lib/libarchive/archive_read_support_compression_all.c	Fri Apr 17 00:54:35 2009	(r191172)
+++ head/lib/libarchive/archive_read_support_compression_all.c	Fri Apr 17 00:55:52 2009	(r191173)
@@ -31,18 +31,24 @@ __FBSDID("$FreeBSD$");
 int
 archive_read_support_compression_all(struct archive *a)
 {
-#if HAVE_BZLIB_H
+	/* Bzip falls back to "bunzip2" command-line */
 	archive_read_support_compression_bzip2(a);
-#endif
 	/* The decompress code doesn't use an outside library. */
 	archive_read_support_compression_compress(a);
 	/* Gzip decompress falls back to "gunzip" command-line. */
 	archive_read_support_compression_gzip(a);
-#if HAVE_LZMADEC_H
-	/* LZMA bidding is subject to false positives because
-	 * the LZMA file format has a very weak signature.  It
-	 * may not be feasible to include LZMA detection here. */
-	/* archive_read_support_compression_lzma(a); */
-#endif
+	/* The LZMA file format has a very weak signature, so it
+	 * may not be feasible to keep this here, but we'll try.
+	 * This will come back out if there are problems. */
+	/* Lzma falls back to "unlzma" command-line program. */
+	archive_read_support_compression_lzma(a);
+	/* Xz falls back to "unxz" command-line program. */
+	archive_read_support_compression_xz(a);
+
+	/* Note: We always return ARCHIVE_OK here, even if some of the
+	 * above return ARCHIVE_WARN.  The intent here is to enable
+	 * "as much as possible."  Clients who need specific
+	 * compression should enable those individually so they can
+	 * verify the level of support. */
 	return (ARCHIVE_OK);
 }

Modified: head/lib/libarchive/archive_read_support_compression_bzip2.c
==============================================================================
--- head/lib/libarchive/archive_read_support_compression_bzip2.c	Fri Apr 17 00:54:35 2009	(r191172)
+++ head/lib/libarchive/archive_read_support_compression_bzip2.c	Fri Apr 17 00:55:52 2009	(r191173)
@@ -86,7 +86,13 @@ archive_read_support_compression_bzip2(s
 	reader->init = bzip2_reader_init;
 	reader->options = NULL;
 	reader->free = bzip2_reader_free;
+#if HAVE_BZLIB_H
 	return (ARCHIVE_OK);
+#else
+	archive_set_error(_a, ARCHIVE_ERRNO_MISC,
+	    "Using external bunzip2 program");
+	return (ARCHIVE_WARN);
+#endif
 }
 
 static int
@@ -150,10 +156,15 @@ bzip2_reader_bid(struct archive_read_fil
 static int
 bzip2_reader_init(struct archive_read_filter *self)
 {
+	int r;
 
-	archive_set_error(&self->archive->archive, -1,
-	    "This version of libarchive was compiled without bzip2 support");
-	return (ARCHIVE_FATAL);
+	r = __archive_read_program(self, "bunzip2");
+	/* Note: We set the format here even if __archive_read_program()
+	 * above fails.  We do, after all, know what the format is
+	 * even if we weren't able to read it. */
+	self->code = ARCHIVE_COMPRESSION_BZIP2;
+	self->name = "bzip2";
+	return (r);
 }
 
 

Modified: head/lib/libarchive/archive_read_support_compression_gzip.c
==============================================================================
--- head/lib/libarchive/archive_read_support_compression_gzip.c	Fri Apr 17 00:54:35 2009	(r191172)
+++ head/lib/libarchive/archive_read_support_compression_gzip.c	Fri Apr 17 00:55:52 2009	(r191173)
@@ -92,7 +92,14 @@ archive_read_support_compression_gzip(st
 	bidder->init = gzip_bidder_init;
 	bidder->options = NULL;
 	bidder->free = NULL; /* No data, so no cleanup necessary. */
+	/* Signal the extent of gzip support with the return value here. */
+#if HAVE_ZLIB_H
 	return (ARCHIVE_OK);
+#else
+	archive_set_error(_a, ARCHIVE_ERRNO_MISC,
+	    "Using external gunzip program");
+	return (ARCHIVE_WARN);
+#endif
 }
 
 /*
@@ -207,9 +214,9 @@ gzip_bidder_bid(struct archive_read_filt
 #ifndef HAVE_ZLIB_H
 
 /*
- * If we don't have the library on this system, we can't actually do the
- * decompression.  We can, however, still detect compressed archives
- * and emit a useful message.
+ * If we don't have the library on this system, we can't do the
+ * decompression directly.  We can, however, try to run gunzip
+ * in case that's available.
  */
 static int
 gzip_bidder_init(struct archive_read_filter *self)
@@ -217,6 +224,9 @@ gzip_bidder_init(struct archive_read_fil
 	int r;
 
 	r = __archive_read_program(self, "gunzip");
+	/* Note: We set the format here even if __archive_read_program()
+	 * above fails.  We do, after all, know what the format is
+	 * even if we weren't able to read it. */
 	self->code = ARCHIVE_COMPRESSION_GZIP;
 	self->name = "gzip";
 	return (r);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200904170055.n3H0tqmA099278>