RPM Package Manager, CVS Repository
http://rpm5.org/cvs/
____________________________________________________________________________
Server: rpm5.org Name: Anders F. Björklund
Root: /v/rpm/cvs Email: afb@rpm5.org
Module: xar Date: 02-Oct-2007 23:51:57
Branch: HEAD Handle: 2007100222515502
Modified files:
xar ChangeLog INSTALL configure.ac
xar/include config.h.in xar.h.in
xar/lib Makefile.inc.in bzxar.c io.c zxar.c
xar/src xar.1 xar.c
xar/test compression data
Log:
new liblzma compression support (rpm5.org)
Summary:
Revision Changes Path
1.5 +2 -0 xar/ChangeLog
1.2 +5 -0 xar/INSTALL
1.12 +10 -0 xar/configure.ac
1.3 +1 -0 xar/include/config.h.in
1.6 +1 -0 xar/include/xar.h.in
1.5 +2 -2 xar/lib/Makefile.inc.in
1.5 +31 -11 xar/lib/bzxar.c
1.6 +8 -0 xar/lib/io.c
1.5 +32 -12 xar/lib/zxar.c
1.6 +1 -1 xar/src/xar.1
1.10 +3 -2 xar/src/xar.c
1.2 +28 -0 xar/test/compression
1.2 +57 -1 xar/test/data
____________________________________________________________________________
patch -p0 <<'@@ .'
Index: xar/ChangeLog
============================================================================
$ cvs diff -u -r1.4 -r1.5 ChangeLog
--- xar/ChangeLog 2 Oct 2007 21:46:41 -0000 1.4
+++ xar/ChangeLog 2 Oct 2007 21:51:55 -0000 1.5
@@ -1,5 +1,7 @@
devel
2007-10-02 Rob Braun bbraun@synack.net
+ * test/compression test/data include/config.h.in include/xar.h.in src/xar.1 src/xar.c configure.ac lib/lzmaxar.c lib/lzmaxar.h lib/io.c lib/bzxar.c lib/Makefile.inc.in lib/zxar.c INSTALL: Incorporate a patch from anders.f.bjorklund for adding lzma compression support.
+ 2007-10-02 Rob Braun bbraun@synack.net
* include/xar.h.in lib/io.c lib/io.h lib/archive.c: Add a "streaming" API that allows for file data to be extracted incrementally, like the zlib decompression API, instead of requiring the entire file to fit in memory like xar_extract_tobuffer(). This is the inital commit of the API and may still change. This change is based on a patch from Charles Srstka.
2007-09-26 Rob Braun bbraun@synack.net
* lib/io.c: Consolidate the lseek handling code into one function.
@@ .
patch -p0 <<'@@ .'
Index: xar/INSTALL
============================================================================
$ cvs diff -u -r1.1 -r1.2 INSTALL
--- xar/INSTALL 30 May 2007 03:55:57 -0000 1.1
+++ xar/INSTALL 2 Oct 2007 21:51:55 -0000 1.2
@@ -26,6 +26,11 @@
http://www.bzip.org/
+Optional: Xar can optionally use liblzma for data compression. For more
+ information about liblzma, see:
+
+ http://tukaani.org/lzma/
+
Optional: Regenerating the configure script requires GNU autoconf. Doing so is
only necessary when making changes to the configuration system.
@@ .
patch -p0 <<'@@ .'
Index: xar/configure.ac
============================================================================
$ cvs diff -u -r1.11 -r1.12 configure.ac
--- xar/configure.ac 29 Sep 2007 12:41:50 -0000 1.11
+++ xar/configure.ac 2 Oct 2007 21:51:55 -0000 1.12
@@ -351,6 +351,16 @@
fi
dnl
+dnl Configure liblzma.
+dnl
+have_liblzma="1"
+AC_CHECK_HEADERS([lzma.h], , [have_liblzma="0"])
+AC_CHECK_LIB([lzma], [lzma_code], , [have_liblzma="0"])
+if test "x${have_liblzma}" = "x1" ; then
+ AC_DEFINE([HAVE_LIBLZMA])
+fi
+
+dnl
dnl Process .in files.
dnl
AC_SUBST([cfghdrs])
@@ .
patch -p0 <<'@@ .'
Index: xar/include/config.h.in
============================================================================
$ cvs diff -u -r1.2 -r1.3 config.h.in
--- xar/include/config.h.in 21 Sep 2007 11:55:42 -0000 1.2
+++ xar/include/config.h.in 2 Oct 2007 21:51:55 -0000 1.3
@@ -19,6 +19,7 @@
#undef HAVE_LIBUTIL_H
#undef HAVE_ASPRINTF
#undef HAVE_LIBBZ2
+#undef HAVE_LIBLZMA
#undef HAVE_LCHOWN
#undef HAVE_LCHMOD
#undef HAVE_STRMODE
@@ .
patch -p0 <<'@@ .'
Index: xar/include/xar.h.in
============================================================================
$ cvs diff -u -r1.5 -r1.6 xar.h.in
--- xar/include/xar.h.in 2 Oct 2007 21:46:41 -0000 1.5
+++ xar/include/xar.h.in 2 Oct 2007 21:51:55 -0000 1.6
@@ -107,6 +107,7 @@
#define XAR_OPT_COMPRESSION "compression" /* set the file compression type */
#define XAR_OPT_VAL_GZIP "gzip"
#define XAR_OPT_VAL_BZIP "bzip2"
+#define XAR_OPT_VAL_LZMA "lzma"
#define XAR_OPT_RSIZE "rsize" /* Read io buffer size */
@@ .
patch -p0 <<'@@ .'
Index: xar/lib/Makefile.inc.in
============================================================================
$ cvs diff -u -r1.4 -r1.5 Makefile.inc.in
--- xar/lib/Makefile.inc.in 12 Sep 2007 15:47:42 -0000 1.4
+++ xar/lib/Makefile.inc.in 2 Oct 2007 21:51:56 -0000 1.5
@@ -16,8 +16,8 @@
# Sources.
LIBXAR_SRCS := archive.c arcmod.c b64.c bzxar.c darwinattr.c data.c ea.c err.c
-LIBXAR_SRCS += ext2.c fbsdattr.c filetree.c io.c linuxattr.c hash.c signature.c stat.c
-LIBXAR_SRCS += subdoc.c util.c zxar.c script.c macho.c
+LIBXAR_SRCS += ext2.c fbsdattr.c filetree.c io.c lzmaxar.c linuxattr.c hash.c
+LIBXAR_SRCS += signature.c stat.c subdoc.c util.c zxar.c script.c macho.c
LIBXAR_SRCS := $(patsubst %, @srcroot@lib/%, $(LIBXAR_SRCS))
@@ .
patch -p0 <<'@@ .'
Index: xar/lib/bzxar.c
============================================================================
$ cvs diff -u -r1.4 -r1.5 bzxar.c
--- xar/lib/bzxar.c 20 Sep 2007 10:29:13 -0000 1.4
+++ xar/lib/bzxar.c 2 Oct 2007 21:51:56 -0000 1.5
@@ -199,21 +199,41 @@
BZIP2_CONTEXT(context)->bz.next_out = out;
BZIP2_CONTEXT(context)->bz.avail_out = 0;
- do {
- outlen *= 2;
- out = realloc(out, outlen);
- if( out == NULL ) abort();
+ if( *inlen != 0 ) {
+ do {
+ outlen *= 2;
+ out = realloc(out, outlen);
+ if( out == NULL ) abort();
- BZIP2_CONTEXT(context)->bz.next_out = ((char *)out) + offset;
- BZIP2_CONTEXT(context)->bz.avail_out = outlen - offset;
+ BZIP2_CONTEXT(context)->bz.next_out = ((char *)out) + offset;
+ BZIP2_CONTEXT(context)->bz.avail_out = outlen - offset;
- if( *inlen == 0 )
- r = BZ2_bzCompress(&BZIP2_CONTEXT(context)->bz, BZ_FINISH);
- else
r = BZ2_bzCompress(&BZIP2_CONTEXT(context)->bz, BZ_RUN);
- offset = outlen - BZIP2_CONTEXT(context)->bz.avail_out;
- } while( BZIP2_CONTEXT(context)->bz.avail_in != 0 );
+ offset = outlen - BZIP2_CONTEXT(context)->bz.avail_out;
+ } while( r == BZ_RUN_OK && BZIP2_CONTEXT(context)->bz.avail_in != 0 );
+ } else {
+ do {
+ outlen *= 2;
+ out = realloc(out, outlen);
+ if( out == NULL ) abort();
+
+ BZIP2_CONTEXT(context)->bz.next_out = ((char *)out) + offset;
+ BZIP2_CONTEXT(context)->bz.avail_out = outlen - offset;
+
+ r = BZ2_bzCompress(&BZIP2_CONTEXT(context)->bz, BZ_FINISH);
+ offset = outlen - BZIP2_CONTEXT(context)->bz.avail_out;
+ } while( (r == BZ_FINISH_OK) && (r != BZ_STREAM_END /* no-op */) );
+ }
+ if( (r != BZ_RUN_OK && r != BZ_STREAM_END && r != BZ_SEQUENCE_ERROR) ) {
+ xar_err_new(x);
+ xar_err_set_file(x, f);
+ xar_err_set_string(x, "Error compressing file");
+ xar_err_set_errno(x, r);
+ xar_err_callback(x, XAR_SEVERITY_FATAL, XAR_ERR_ARCHIVE_CREATION);
+ return -1;
+ }
+
free(*in);
*in = out;
*inlen = offset;
@@ .
patch -p0 <<'@@ .'
Index: xar/lib/io.c
============================================================================
$ cvs diff -u -r1.5 -r1.6 io.c
--- xar/lib/io.c 2 Oct 2007 21:46:42 -0000 1.5
+++ xar/lib/io.c 2 Oct 2007 21:51:56 -0000 1.6
@@ -58,6 +58,7 @@
#include "io.h"
#include "zxar.h"
#include "bzxar.h"
+#include "lzmaxar.h"
#include "hash.h"
#include "script.h"
#include "macho.h"
@@ -105,6 +106,13 @@
xar_bzip_toheap_in,
(toheap_out)NULL,
xar_bzip_toheap_done
+ },
+ { xar_lzma_fromheap_in,
+ (fromheap_out)NULL,
+ xar_lzma_fromheap_done,
+ xar_lzma_toheap_in,
+ (toheap_out)NULL,
+ xar_lzma_toheap_done
}
};
@@ .
patch -p0 <<'@@ .'
Index: xar/lib/zxar.c
============================================================================
$ cvs diff -u -r1.4 -r1.5 zxar.c
--- xar/lib/zxar.c 20 Sep 2007 10:29:13 -0000 1.4
+++ xar/lib/zxar.c 2 Oct 2007 21:51:56 -0000 1.5
@@ -115,7 +115,7 @@
GZIP_CONTEXT(context)->z.next_out = ((unsigned char *)out) + offset;
GZIP_CONTEXT(context)->z.avail_out = outlen - offset;
- r = inflate(&(GZIP_CONTEXT(context)->z), Z_SYNC_FLUSH);
+ r = inflate(&(GZIP_CONTEXT(context)->z), Z_NO_FLUSH);
if( (r != Z_OK) && (r != Z_STREAM_END) ) {
xar_err_new(x);
xar_err_set_file(x, f);
@@ -189,20 +189,40 @@
GZIP_CONTEXT(context)->z.next_out = out;
GZIP_CONTEXT(context)->z.avail_out = 0;
- do {
- outlen *= 2;
- out = realloc(out, outlen);
- if( out == NULL ) abort();
+ if( *inlen != 0 ) {
+ do {
+ outlen *= 2;
+ out = realloc(out, outlen);
+ if( out == NULL ) abort();
+
+ GZIP_CONTEXT(context)->z.next_out = ((unsigned char *)out) + offset;
+ GZIP_CONTEXT(context)->z.avail_out = outlen - offset;
+
+ r = deflate(&GZIP_CONTEXT(context)->z, Z_NO_FLUSH);
+ offset = outlen - GZIP_CONTEXT(context)->z.avail_out;
+ } while( r == Z_OK && GZIP_CONTEXT(context)->z.avail_in != 0 );
+ } else {
+ do {
+ outlen *= 2;
+ out = realloc(out, outlen);
+ if( out == NULL ) abort();
- GZIP_CONTEXT(context)->z.next_out = ((unsigned char *)out) + offset;
- GZIP_CONTEXT(context)->z.avail_out = outlen - offset;
+ GZIP_CONTEXT(context)->z.next_out = ((unsigned char *)out) + offset;
+ GZIP_CONTEXT(context)->z.avail_out = outlen - offset;
- if( *inlen == 0 )
r = deflate(&GZIP_CONTEXT(context)->z, Z_FINISH);
- else
- r = deflate(&GZIP_CONTEXT(context)->z, Z_SYNC_FLUSH);
- offset = outlen - GZIP_CONTEXT(context)->z.avail_out;
- } while( GZIP_CONTEXT(context)->z.avail_in != 0 );
+ offset = outlen - GZIP_CONTEXT(context)->z.avail_out;
+ } while( r == Z_OK && r != Z_STREAM_END /* no-op */);
+ }
+
+ if( (r != Z_OK && r != Z_STREAM_END) ) {
+ xar_err_new(x);
+ xar_err_set_file(x, f);
+ xar_err_set_string(x, "Error compressing file");
+ xar_err_set_errno(x, r);
+ xar_err_callback(x, XAR_SEVERITY_FATAL, XAR_ERR_ARCHIVE_CREATION);
+ return -1;
+ }
free(*in);
*in = out;
@@ .
patch -p0 <<'@@ .'
Index: xar/src/xar.1
============================================================================
$ cvs diff -u -r1.5 -r1.6 xar.1
--- xar/src/xar.1 29 Sep 2007 12:29:44 -0000 1.5
+++ xar/src/xar.1 2 Oct 2007 21:51:56 -0000 1.6
@@ -34,7 +34,7 @@
.TP
\-\-compression
Specifies the compression type to use.
-Valid values: none, gzip, bzip2. Default value: gzip
+Valid values: none, gzip, bzip2, lzma. Default value: gzip
.TP
\-j
Synonym for \-\-compression=bzip2
@@ .
patch -p0 <<'@@ .'
Index: xar/src/xar.c
============================================================================
$ cvs diff -u -r1.9 -r1.10 xar.c
--- xar/src/xar.c 29 Sep 2007 12:29:44 -0000 1.9
+++ xar/src/xar.c 2 Oct 2007 21:51:56 -0000 1.10
@@ -665,7 +665,7 @@
fprintf(stderr, "\t specified file.\n");
fprintf(stderr, "\t--dump-header Prints out the xar binary header information\n");
fprintf(stderr, "\t--compression Specifies the compression type to use.\n");
- fprintf(stderr, "\t Valid values: none, gzip, bzip2\n");
+ fprintf(stderr, "\t Valid values: none, gzip, bzip2, lzma\n");
fprintf(stderr, "\t Default: gzip\n");
fprintf(stderr, "\t-j Synonym for \"--compression=bzip2\"\n");
fprintf(stderr, "\t-z Synonym for \"--compression=gzip\"\n");
@@ -758,7 +758,8 @@
}
if( (strcmp(optarg, XAR_OPT_VAL_NONE) != 0) &&
(strcmp(optarg, XAR_OPT_VAL_GZIP) != 0) &&
- (strcmp(optarg, XAR_OPT_VAL_BZIP) != 0) ) {
+ (strcmp(optarg, XAR_OPT_VAL_BZIP) != 0) &&
+ (strcmp(optarg, XAR_OPT_VAL_LZMA) != 0) ) {
usage(argv[0]);
exit(1);
}
@@ .
patch -p0 <<'@@ .'
Index: xar/test/compression
============================================================================
$ cvs diff -u -r1.1 -r1.2 compression
--- xar/test/compression 30 May 2007 03:56:00 -0000 1.1
+++ xar/test/compression 2 Oct 2007 21:51:57 -0000 1.2
@@ -8,6 +8,8 @@
if [ $? -ne 0 ]; then
echo "Error creating archive"
exit 1
+else
+ du -k bin.xar
fi
${XAR} -xf bin.xar
@@ -26,6 +28,8 @@
if [ $? -ne 0 ]; then
echo "Error creating archive"
exit 1
+else
+ du -k bin.xar
fi
${XAR} -xf bin.xar
@@ -50,6 +54,28 @@
if [ $? -ne 0 ]; then
echo "Error extracting archive"
exit 1
+else
+ du -k bin.xar
+fi
+
+if [ ! -e bin/sh ]; then
+ echo "Error with extracted contents"
+fi
+
+echo "Testing normal archival creation/extraction with lzma compression"
+rm -rf bin.xar bin
+${XAR} --compression=lzma -cf bin.xar /bin
+if [ $? -ne 0 ]; then
+ echo "Error creating archive"
+ exit 1
+else
+ du -k bin.xar
+fi
+
+${XAR} -xf bin.xar
+if [ $? -ne 0 ]; then
+ echo "Error extracting archive"
+ exit 1
fi
if [ ! -e bin/sh ]; then
@@ -62,6 +88,8 @@
if [ $? -ne 0 ]; then
echo "Error creating archive"
exit 1
+else
+ du -k bin.xar
fi
${XAR} -xf bin.xar
@@ .
patch -p0 <<'@@ .'
Index: xar/test/data
============================================================================
$ cvs diff -u -r1.1 -r1.2 data
--- xar/test/data 30 May 2007 03:56:00 -0000 1.1
+++ xar/test/data 2 Oct 2007 21:51:57 -0000 1.2
@@ -90,7 +90,36 @@
extract_archive h.xar
cleanup
-echo "Testing zero length files with bzip2 compression"
+echo "Testing zero length files with lzma compression"
+cleanup
+mkdir h
+touch h/a
+
+cd h
+${XAR} --compression=lzma -cf ../h.xar .
+if [ $? -ne 0 ]; then
+ echo "Error creating archive"
+ exit 1
+fi
+cd ..
+${XAR} --dump-toc=h.toc -f h.xar
+if [ $? -ne 0 ]; then
+ echo "Error dumping toc"
+ cleanup
+ exit 1
+fi
+
+offset=`xsltproc data.xsl h.toc | grep -v xml`
+if [ "$offset" != "" ]; then
+ echo "Zero length file has data section"
+ cleanup
+ exit 1
+fi
+
+extract_archive h.xar
+cleanup
+
+echo "Testing zero length files with no compression"
cleanup
mkdir h
touch h/a
@@ -172,6 +201,33 @@
fi
cleanup
+echo "Testing mixed zero length/populated files with lzma compression"
+cleanup
+mkdir h
+touch h/a
+echo "foo" > h/b
+
+cd h
+${XAR} --compression=lzma -cf ../h.xar .
+if [ $? -ne 0 ]; then
+ echo "Error creating archive"
+ exit 1
+fi
+cd ..
+
+extract_archive h.xar
+contents=`cat a`
+if [ ! -z "$contents" ]; then
+ echo "File isn't zero length after extraction"
+ exit 1
+fi
+contents=`cat b`
+if [ "$contents" != "foo" ]; then
+ echo "Contents of populated file not the same after extraction"
+ exit 1
+fi
+cleanup
+
echo "Testing mixed zero length/populated files with no compression"
cleanup
mkdir h
@@ .
Received on Tue Oct 2 23:51:57 2007